git: 7c419d3c7f65 - releng/14.4 - tmpfs: Clear setgid on creation by nonmembers

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 17:04:32 UTC
The branch releng/14.4 has been updated by markj:

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

commit 7c419d3c7f652f3ced6b9b41a33bab27f45c9e72
Author:     Kevin Day <kevin@your.org>
AuthorDate: 2026-11-14 01:40:14 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-16 21:16:23 +0000

    tmpfs: Clear setgid on creation by nonmembers
    
    New tmpfs nodes inherit their parent directory group. Clear S_ISGID when
    the creator is not a member of that group and lacks PRIV_VFS_SETGID,
    matching UFS and tmpfs chmod behavior.
    
    Approved by:    so
    Security:       FreeBSD-SA-26:94.tmpfs
    Security:       CVE-2026-127749
    Reviewed by:    kib
---
 sys/fs/tmpfs/tmpfs_subr.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index bca6bf911eb1..40e242a07dd0 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -1164,6 +1164,7 @@ tmpfs_alloc_file(struct vnode *dvp, struct vnode **vpp, struct vattr *vap,
     struct componentname *cnp, const char *target)
 {
 	int error;
+	mode_t mode;
 	struct tmpfs_dirent *de;
 	struct tmpfs_mount *tmp;
 	struct tmpfs_node *dnode;
@@ -1192,9 +1193,15 @@ tmpfs_alloc_file(struct vnode *dvp, struct vnode **vpp, struct vattr *vap,
 	} else
 		parent = NULL;
 
+	mode = vap->va_mode;
+	if ((mode & S_ISGID) != 0 &&
+	    !groupmember(dnode->tn_gid, cnp->cn_cred) &&
+	    priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID) != 0)
+		mode &= ~S_ISGID;
+
 	/* Allocate a node that represents the new file. */
 	error = tmpfs_alloc_node(dvp->v_mount, tmp, vap->va_type,
-	    cnp->cn_cred->cr_uid, dnode->tn_gid, vap->va_mode, parent,
+	    cnp->cn_cred->cr_uid, dnode->tn_gid, mode, parent,
 	    target, vap->va_rdev, &node);
 	if (error != 0)
 		return (error);