Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jan 2025 13:53:08 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: 155987e20190 - stable/14 - tarfs: Fix the size of struct tarfs_fid and add a static assert
Message-ID:  <202501171353.50HDr8ae022440@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=155987e2019089a5bd2eef77ed7bcc5cc26c362e

commit 155987e2019089a5bd2eef77ed7bcc5cc26c362e
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2024-12-06 02:09:27 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-01-17 13:50:46 +0000

    tarfs: Fix the size of struct tarfs_fid 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 packs the structure and checks via a __Static_assert().
    
    Reviewed by:    markj
    MFC after:      2 weeks
    
    (cherry picked from commit 4db1b113b15158c7d134df83e7a7201cf46d459b)
---
 sys/fs/tarfs/tarfs.h       | 2 +-
 sys/fs/tarfs/tarfs_vnops.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/fs/tarfs/tarfs.h b/sys/fs/tarfs/tarfs.h
index ff1985e488cd..ffb95d2c0ac5 100644
--- a/sys/fs/tarfs/tarfs.h
+++ b/sys/fs/tarfs/tarfs.h
@@ -165,7 +165,7 @@ struct tarfs_fid {
 	u_short			 data0;	/* force alignment */
 	ino_t			 ino;
 	unsigned long		 gen;
-};
+} __packed;
 
 #define	TARFS_NODE_LOCK(tnp) \
 	mtx_lock(&(tnp)->lock)
diff --git a/sys/fs/tarfs/tarfs_vnops.c b/sys/fs/tarfs/tarfs_vnops.c
index 8c97fab185fc..afb8e05f5929 100644
--- a/sys/fs/tarfs/tarfs_vnops.c
+++ b/sys/fs/tarfs/tarfs_vnops.c
@@ -668,6 +668,8 @@ tarfs_vptofh(struct vop_vptofh_args *ap)
 {
 	struct tarfs_fid *tfp;
 	struct tarfs_node *tnp;
+	_Static_assert(sizeof(struct tarfs_fid) <= sizeof(struct fid),
+	    "struct tarfs_fid cannot be larger than struct fid");
 
 	tfp = (struct tarfs_fid *)ap->a_fhp;
 	tnp = VP_TO_TARFS_NODE(ap->a_vp);



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