freebsd-dev/sys/fs/tmpfs
Ryan Moeller 693d10a291 tmpfs: Preserve alignment of struct fid fields
On 64-bit platforms, the two short fields in `struct tmpfs_fid` are padded to
the 64-bit alignment of the long field.  This pushes the offsets of the
subsequent fields by 4 bytes and makes `struct tmpfs_fid` bigger than
`struct fid`.  `tmpfs_vptofh()` casts a `struct fid *` to `struct tmpfs_fid *`,
causing 4 bytes of adjacent memory to be overwritten when the struct fields are
set.  Through several layers of indirection and embedded structs, the adjacent
memory for one particular call to `tmpfs_vptofh()` happens to be the stack
canary for `nfsrvd_compound()`.  Half of the canary ends up being clobbered,
going unnoticed until eventually the stack check fails when `nfsrvd_compound()`
returns and a panic is triggered.

Instead of duplicating fields of `struct fid` in `struct tmpfs_fid`, narrow the
struct to cover only the unique fields for tmpfs and assert at compile time
that the struct fits in the allotted space.  This way we don't have to
replicate the offsets of `struct fid` fields, we just use them directly.

Reviewed by:	kib, mav, rmacklem
Approved by:	mav (mentor)
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D25077
2020-06-03 09:38:51 +00:00
..
tmpfs_fifoops.c vfs: flatten vop vectors 2019-12-16 00:06:22 +00:00
tmpfs_fifoops.h sys/fs: further adoption of SPDX licensing ID tags. 2017-11-27 15:15:37 +00:00
tmpfs_subr.c Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many) 2020-02-26 14:26:36 +00:00
tmpfs_vfsops.c tmpfs: Preserve alignment of struct fid fields 2020-06-03 09:38:51 +00:00
tmpfs_vnops.c tmpfs: Preserve alignment of struct fid fields 2020-06-03 09:38:51 +00:00
tmpfs_vnops.h Rework pathconf handling for FIFOs. 2017-12-19 22:39:05 +00:00
tmpfs.h tmpfs: Preserve alignment of struct fid fields 2020-06-03 09:38:51 +00:00