git: 91b5592a1e1a - main - fs: Add static asserts for the size of fid structures

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Fri, 06 Dec 2024 01:57:38 UTC
The branch main has been updated by rmacklem:

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

commit 91b5592a1e1af97480d615cf508be05b5674d2f3
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2024-12-06 01:56:23 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-12-06 01:56:23 +0000

    fs: Add static asserts for the size of fid structures
    
    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 adds _Static_assert()s to check for this.
    
    ZFS and fuse already have _Static_assert()s.
    
    Reviewed by:    imp
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D47936
---
 sys/fs/msdosfs/msdosfs_vnops.c | 2 ++
 sys/fs/tmpfs/tmpfs_vnops.c     | 2 ++
 sys/fs/udf/udf_vnops.c         | 2 ++
 sys/ufs/ffs/ffs_vnops.c        | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c
index 078ea5e52312..6417b7dac16b 100644
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -1962,6 +1962,8 @@ msdosfs_vptofh(struct vop_vptofh_args *ap)
 {
 	struct denode *dep;
 	struct defid *defhp;
+	_Static_assert(sizeof(struct defid) <= sizeof(struct fid),
+	    "struct defid cannot be larger than struct fid");
 
 	dep = VTODE(ap->a_vp);
 	defhp = (struct defid *)ap->a_fhp;
diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c
index 428c31f3c59a..162977b8abf7 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -1709,6 +1709,8 @@ vop_vptofh {
 	struct tmpfs_fid_data tfd;
 	struct tmpfs_node *node;
 	struct fid *fhp;
+	_Static_assert(sizeof(struct tmpfs_fid_data) <= sizeof(struct fid),
+	    "struct tmpfs_fid_data cannot be larger than struct fid");
 
 	node = VP_TO_TMPFS_NODE(ap->a_vp);
 	fhp = ap->a_fhp;
diff --git a/sys/fs/udf/udf_vnops.c b/sys/fs/udf/udf_vnops.c
index 98a779280690..88bf4917a851 100644
--- a/sys/fs/udf/udf_vnops.c
+++ b/sys/fs/udf/udf_vnops.c
@@ -1274,6 +1274,8 @@ udf_vptofh(struct vop_vptofh_args *a)
 {
 	struct udf_node *node;
 	struct ifid *ifhp;
+	_Static_assert(sizeof(struct ifid) <= sizeof(struct fid),
+	    "struct ifid cannot be larger than struct fid");
 
 	node = VTON(a->a_vp);
 	ifhp = (struct ifid *)a->a_fhp;
diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index e9849008cde2..6e83741975fd 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -1919,6 +1919,8 @@ ffs_vptofh(
 {
 	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;