Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jan 2025 13:53:10 GMT
From:      Olivier Certner <olce@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 7a3a0402aeb6 - stable/14 - ext2fs: Fix the size of struct ufid and add a static assert
Message-ID:  <202501171353.50HDrABM022564@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=7a3a0402aeb626a7379addd344cbfd8900e83baa

commit 7a3a0402aeb626a7379addd344cbfd8900e83baa
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2024-12-06 02:05:06 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-01-17 13:51:53 +0000

    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().
    
    Reviewed by:    markj
    MFC after:      2 weeks
    
    (cherry picked from commit bfc8e3308bee23d0f7836d57f32ed8d47da02627)
---
 sys/fs/ext2fs/ext2_vnops.c | 2 ++
 sys/fs/ext2fs/inode.h      | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c
index 1c4b62bb4086..79d50a6a64cb 100644
--- a/sys/fs/ext2fs/ext2_vnops.c
+++ b/sys/fs/ext2fs/ext2_vnops.c
@@ -1892,6 +1892,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 46e6215aff6f..14d2d6454737 100644
--- a/sys/fs/ext2fs/inode.h
+++ b/sys/fs/ext2fs/inode.h
@@ -193,7 +193,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_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202501171353.50HDrABM022564>