git: faa47d299a0e - releng/14.2 - tarfs: Fix the size of struct tarfs_fid and add a static assert

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 29 Jan 2025 18:54:56 UTC
The branch releng/14.2 has been updated by markj:

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

commit faa47d299a0ed3af49989495bd1debd469dc54e2
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2024-12-06 02:09:27 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-01-29 17:27:27 +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().
    
    Approved by:    so
    Security:       FreeBSD-SA-25:02.fs
    Reviewed by:    markj
    MFC after:      2 weeks
    
    (cherry picked from commit 4db1b113b15158c7d134df83e7a7201cf46d459b)
    (cherry picked from commit 155987e2019089a5bd2eef77ed7bcc5cc26c362e)
---
 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 f2828c60f8a7..4bc923ed8f9c 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);