aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRick Macklem <rmacklem@FreeBSD.org>2024-12-06 02:05:06 +0000
committerMark Johnston <markj@FreeBSD.org>2025-01-29 17:02:12 +0000
commit0365b776f1b189855c67bdfa2be38955039f8ed6 (patch)
treea2f4ea427887d6810adb6d74f89c5441a351e26d
parentbb48aba6244c10236590b49e43fe90daab6a55fa (diff)
ext2fs: Fix the size of struct ufid and add a static assert
File system specific *fid structures are copied into the generic struct fid defined in sys/mount.h. As such, they cannot be larger than struct fid. This patch packed the structure and checks via a __Static_assert(). Approved by: so Security: FreeBSD-SA-25:02.fs Reviewed by: markj MFC after: 2 weeks (cherry picked from commit bfc8e3308bee23d0f7836d57f32ed8d47da02627) (cherry picked from commit ee931cf4a49c90487c938fa14b856401582a045c)
-rw-r--r--sys/fs/ext2fs/ext2_vnops.c2
-rw-r--r--sys/fs/ext2fs/inode.h2
2 files changed, 3 insertions, 1 deletions
diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c
index 01b94abf6cd5..63c4830b95be 100644
--- a/sys/fs/ext2fs/ext2_vnops.c
+++ b/sys/fs/ext2fs/ext2_vnops.c
@@ -1884,6 +1884,8 @@ ext2_vptofh(struct vop_vptofh_args *ap)
{
struct inode *ip;
struct ufid *ufhp;
+ _Static_assert(sizeof(struct ufid) <= sizeof(struct fid),
+ "struct ufid cannot be larger than struct fid");
ip = VTOI(ap->a_vp);
ufhp = (struct ufid *)ap->a_fhp;
diff --git a/sys/fs/ext2fs/inode.h b/sys/fs/ext2fs/inode.h
index 6b8b23ccab14..c29a64be12e0 100644
--- a/sys/fs/ext2fs/inode.h
+++ b/sys/fs/ext2fs/inode.h
@@ -189,7 +189,7 @@ struct ufid {
uint16_t ufid_pad; /* Force 32-bit alignment. */
ino_t ufid_ino; /* File number (ino). */
uint32_t ufid_gen; /* Generation number. */
-};
+} __packed;
#endif /* _KERNEL */
#endif /* !_FS_EXT2FS_INODE_H_ */