Skip to content

Commit 2d8ae8c

Browse files
braunerchucklever
authored andcommitted
nfsd: use vfs setgid helper
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit cf619f8 ("Merge tag 'fs.ovl.setgid.v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit 426b4ca ("Merge tag 'fs.setgid.v6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux"). Consistent setgid stripping behavior is now encapsulated in the setattr_should_drop_sgid() helper which is used by all filesystems that strip setgid bits outside of vfs proper. Usually ATTR_KILL_SGID is raised in e.g., chown_common() and is subject to the setattr_should_drop_sgid() check to determine whether the setgid bit can be retained. Since nfsd is raising ATTR_KILL_SGID unconditionally it will cause notify_change() to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raises ATR_KILL_SGID if the caller lacks the necessary privileges to retain the setgid bit. Without this patch the setgid stripping tests in LTP will fail: > As you can see, the problem is S_ISGID (0002000) was dropped on a > non-group-executable file while chown was invoked by super-user, while [...] > fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700 [...] > chown02.c:57: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700 With this patch all tests pass. Reported-by: Sherry Yang <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Cc: <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 9561de3 commit 2d8ae8c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/nfsd/vfs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap)
388388
iap->ia_mode &= ~S_ISGID;
389389
} else {
390390
/* set ATTR_KILL_* bits and let VFS handle it */
391-
iap->ia_valid |= (ATTR_KILL_SUID | ATTR_KILL_SGID);
391+
iap->ia_valid |= ATTR_KILL_SUID;
392+
iap->ia_valid |=
393+
setattr_should_drop_sgid(&nop_mnt_idmap, inode);
392394
}
393395
}
394396
}

0 commit comments

Comments
 (0)