nfsd: use vfs setgid helper
Subsystems (2)
PATCH 1/1 nfsd: use vfs setgid helper
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit cf619f891971 ("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit 426b4ca2d6a5 ("Merge tag 'fs.setgid.v6.0' ofgit://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:
Quoted 2 lines
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
[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 1 line
chown02.c:57: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
With this patch all tests pass.
---
ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s chown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2fa
ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s fchown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2fa
ubuntu@imp1-vm:~/src/git/xfstests$ sudo ./check -g perms FSTYP -- nfs PLATFORM -- Linux/x86_64 imp1-vm 6.3.0-nfs-setgid-3a3cfe624076 #20 SMP PREEMPT_DYNAMIC Tue May 2 12:35:51 UTC 2023 MKFS_OPTIONS -- 127.0.0.1:/nfsscratch MOUNT_OPTIONS -- -o vers=3,noacl 127.0.0.1:/nfsscratch /mnt/scratch Passed all 41 tests --- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfsd/vfs.c +3 -1
@@ -388,7 +388,9 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) iap->ia_mode &= ~S_ISGID ; }else {/* set ATTR_KILL_* bits and let VFS handle it */ - iap->ia_valid |= (ATTR_KILL_SUID |ATTR_KILL_SGID ); + iap->ia_valid |=ATTR_KILL_SUID ; + iap->ia_valid |= +setattr_should_drop_sgid (&nop_mnt_idmap, inode); } } }
Signature · 1 line
2.34.1
Quoted 28 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
Quoted 8 lines
[...]
Quoted 1 line
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]>
There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing. Thanks, Christian and Sherry!
Quoted 37 lines
---
ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s chown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s fchown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/src/git/xfstests$ sudo ./check -g perms FSTYP -- nfs PLATFORM -- Linux/x86_64 imp1-vm 6.3.0-nfs-setgid-3a3cfe624076 #20 SMP PREEMPT_DYNAMIC Tue May 2 12:35:51 UTC 2023 MKFS_OPTIONS -- 127.0.0.1:/nfsscratch MOUNT_OPTIONS -- -o vers=3,noacl 127.0.0.1:/nfsscratch /mnt/scratch Passed all 41 tests --- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +3
-1@@ -388,7 +388,9 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) iap->ia_mode &= ~S_ISGID ; }else {/* set ATTR_KILL_* bits and let VFS handle it */ - iap->ia_valid |= (ATTR_KILL_SUID |ATTR_KILL_SGID ); + iap->ia_valid |=ATTR_KILL_SUID ; + iap->ia_valid |= +setattr_should_drop_sgid (&nop_mnt_idmap, inode); } } }Signature · 1 line
2.34.1
--
Chuck Lever
Quoted 38 lines · Chuck Lever III
Quoted 35 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 1 line
chown02.c:57: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
With this patch all tests pass.
Quoted 7 lines
Quoted 2 lines
Reported-by Sherry Yang <[email protected]>Signed-off-by Christian Brauner <[email protected]>There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
ERROR: modpost: "setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!
Did I apply this patch to the wrong kernel?
Quoted 35 lines
Thanks, Christian and Sherry!
Quoted 32 lines
---
ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s chown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s fchown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/src/git/xfstests$ sudo ./check -g perms FSTYP -- nfs PLATFORM -- Linux/x86_64 imp1-vm 6.3.0-nfs-setgid-3a3cfe624076 #20 SMP PREEMPT_DYNAMIC Tue May 2 12:35:51 UTC 2023 MKFS_OPTIONS -- 127.0.0.1:/nfsscratch MOUNT_OPTIONS -- -o vers=3,noacl 127.0.0.1:/nfsscratch /mnt/scratch Passed all 41 tests --- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +3
-1@@ -388,7 +388,9 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) iap->ia_mode &= ~S_ISGID ; }else {/* set ATTR_KILL_* bits and let VFS handle it */ - iap->ia_valid |= (ATTR_KILL_SUID |ATTR_KILL_SGID ); + iap->ia_valid |=ATTR_KILL_SUID ; + iap->ia_valid |= +setattr_should_drop_sgid (&nop_mnt_idmap, inode); }
Quoted 8 lines
Quoted 5 lines
fs/nfsd/vfs.c +0
-0} }Signature · 1 line
2.34.1--
Chuck Lever
--
Chuck Lever
Quoted 45 lines · Chuck Lever III
Quoted 42 lines · Chuck Lever III
Quoted 37 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 1 line
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]>
Quoted 8 lines
Quoted 4 lines
There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
ERROR: modpost: "
setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!Did I apply this patch to the wrong kernel?
setattr_should_drop_sgid() is not available to callers built as modules. It needs an EXPORT_SYMBOL or _GPL.
Quoted 45 lines
Quoted 35 lines
Thanks, Christian and Sherry!
Quoted 32 lines
---
ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s chown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s fchown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/src/git/xfstests$ sudo ./check -g perms FSTYP -- nfs PLATFORM -- Linux/x86_64 imp1-vm 6.3.0-nfs-setgid-3a3cfe624076 #20 SMP PREEMPT_DYNAMIC Tue May 2 12:35:51 UTC 2023 MKFS_OPTIONS -- 127.0.0.1:/nfsscratch MOUNT_OPTIONS -- -o vers=3,noacl 127.0.0.1:/nfsscratch /mnt/scratch Passed all 41 tests --- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +3
-1@@ -388,7 +388,9 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) iap->ia_mode &= ~S_ISGID ; }else {/* set ATTR_KILL_* bits and let VFS handle it */ - iap->ia_valid |= (ATTR_KILL_SUID |ATTR_KILL_SGID ); + iap->ia_valid |=ATTR_KILL_SUID ; + iap->ia_valid |= +setattr_should_drop_sgid (&nop_mnt_idmap, inode); }Quoted 8 lines
Quoted 5 lines
fs/nfsd/vfs.c +0
-0} }Signature · 1 line
2.34.1--
Chuck Lever
Quoted 2 lines
--
Chuck Lever
--
Chuck Lever
Quoted 50 lines · Chuck Lever III
Quoted 50 lines · Chuck Lever III
Quoted 46 lines · Chuck Lever III
Quoted 29 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
Quoted 8 lines
[...]
Quoted 1 line
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]>There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
Quoted 6 lines
Quoted 3 lines
ERROR: modpost: "
setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!Did I apply this patch to the wrong kernel?
setattr_should_drop_sgid()is not available to callers built as modules. It needs anEXPORT_SYMBOLor_GPL.
Hey Chuck,
Thanks for taking a look!
The required export is part of
commit 4f704d9a835 ("nfs: use vfs setgid helper")
which is in current mainline as of Monday this week which was part of my v6.4/vfs.misc PR that was merged.
So this should all work fine on mainline. Seems I didn't use --base which is why that info was missing.
Thanks!
Christian
Hi Christian,
Quoted 39 lines · Christian Brauner
Quoted 38 lines · Chuck Lever III
Quoted 38 lines · Chuck Lever III
Quoted 35 lines · Chuck Lever III
Quoted 31 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
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]>
We had a very similar report from kernel-test-robot.
https://lore.kernel.org/all/[email protected]/
Which points to commit: ed5a7047d201 ("attr: use consistent sgid stripping checks")
And the above commit is backported to LTS kernels -- 5.10.y,5.15.y and 6.1.y
So would it be better to tag it to stable by adding "Cc: <[email protected]>" ?
Thanks,
Harshit
Quoted 27 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
ERROR: modpost: "
setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!Did I apply this patch to the wrong kernel?
setattr_should_drop_sgid()is not available to callers built as modules. It needs anEXPORT_SYMBOLor_GPL.Hey Chuck,
Thanks for taking a look!
The required export is part of
commit4f704d9a835("nfs: use vfs setgid helper")
which is in current mainline as of Monday this week which was part of my v6.4/vfs.misc PR that was merged.So this should all work fine on mainline. Seems I didn't use --base which is why that info was missing.
Thanks!
Christian
Quoted 58 lines · Harshit Mogalapalli
Hi Christian,
Quoted 39 lines · Christian Brauner
Quoted 38 lines · Chuck Lever III
Quoted 38 lines · Chuck Lever III
Quoted 35 lines · Chuck Lever III
Quoted 31 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
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]>We had a very similar report from kernel-test-robot.
Quoted 30 lines
Which points to commit:
ed5a7047d201("attr: use consistent sgid stripping checks")And the above commit is backported to LTS kernels -- 5.10.y,5.15.y and 6.1.y
So would it be better to tag it to stable by adding "Cc: <[email protected]>" ?
Thanks,
HarshitQuoted 21 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
ERROR: modpost: "
setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!Did I apply this patch to the wrong kernel?
setattr_should_drop_sgid()is not available to callers built as modules. It needs anEXPORT_SYMBOLor_GPL.Hey Chuck,
Thanks for taking a look!
The required export is part of
commit4f704d9a835("nfs: use vfs setgid helper")
which is in current mainline as of Monday this week which was part of my v6.4/vfs.misc PR that was merged.
So this should all work fine on mainline. Seems I didn't use --base which is why that info was missing.
Thanks!
Christian
I'll apply this to nfsd-next (6.5) and add Jeff's Reviewed-by and a Cc: stable.
--
Chuck Lever
Quoted 89 lines · Chuck Lever III
Quoted 58 lines · Harshit Mogalapalli
Hi Christian,
Quoted 39 lines · Christian Brauner
Quoted 38 lines · Chuck Lever III
Quoted 38 lines · Chuck Lever III
Quoted 35 lines · Chuck Lever III
Quoted 31 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
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]>We had a very similar report from kernel-test-robot.
Quoted 30 lines
Which points to commit:
ed5a7047d201("attr: use consistent sgid stripping checks")And the above commit is backported to LTS kernels -- 5.10.y,5.15.y and 6.1.y
So would it be better to tag it to stable by adding "Cc: <[email protected]>" ?
Thanks,
HarshitQuoted 21 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
ERROR: modpost: "
setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!Did I apply this patch to the wrong kernel?
setattr_should_drop_sgid()is not available to callers built as modules. It needs anEXPORT_SYMBOLor_GPL.Hey Chuck,
Thanks for taking a look!
The required export is part of
commit4f704d9a835("nfs: use vfs setgid helper")
which is in current mainline as of Monday this week which was part of my v6.4/vfs.misc PR that was merged.
So this should all work fine on mainline. Seems I didn't use --base which is why that info was missing.
Thanks!
Christian
Quoted 2 lines
I'll apply this to nfsd-next (6.5) and add Jeff's Reviewed-by and a Cc: stable.
Thanks all! Appreciate the Cc: stable fixup.
Quoted 93 lines · Chuck Lever III
Quoted 59 lines · Harshit Mogalapalli
Hi Christian,
Quoted 39 lines · Christian Brauner
Quoted 38 lines · Chuck Lever III
Quoted 38 lines · Chuck Lever III
Quoted 35 lines · Chuck Lever III
Quoted 31 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
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]>We had a very similar report from kernel-test-robot.
Quoted 30 lines
Which points to commit:
ed5a7047d201("attr: use consistent sgid stripping checks")And the above commit is backported to LTS kernels -- 5.10.y,5.15.y and 6.1.y
So would it be better to tag it to stable by adding "Cc: <[email protected]>" ?
Thanks,
HarshitQuoted 21 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
ERROR: modpost: "
setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!Did I apply this patch to the wrong kernel?
setattr_should_drop_sgid()is not available to callers built as modules. It needs anEXPORT_SYMBOLor_GPL.Hey Chuck,
Thanks for taking a look!
The required export is part of
commit4f704d9a835("nfs: use vfs setgid helper")
which is in current mainline as of Monday this week which was part of my v6.4/vfs.misc PR that was merged.
So this should all work fine on mainline. Seems I didn't use --base which is why that info was missing.
Thanks!
Christian
Quoted 2 lines
I'll apply this to nfsd-next (6.5) and add Jeff's Reviewed-by and a Cc: stable.
Hi Chuck,
Just following up to see if you know when this patch will go to linux mainline and linux-stable?
Thanks,
Sherry
Quoted 6 lines
--
Chuck Lever
Quoted 97 lines · Sherry Yang
Quoted 94 lines · Chuck Lever III
Quoted 89 lines · Harshit Mogalapalli
Hi Christian,
Quoted 39 lines · Christian Brauner
Quoted 38 lines · Chuck Lever III
Quoted 38 lines · Chuck Lever III
Quoted 35 lines · Chuck Lever III
Quoted 31 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
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]>We had a very similar report from kernel-test-robot.
https://lore.kernel.org/all/[email protected]/
Which points to commit:
ed5a7047d201("attr: use consistent sgid stripping checks")And the above commit is backported to LTS kernels -- 5.10.y,5.15.y and 6.1.y
So would it be better to tag it to stable by adding "Cc: <[email protected]>" ?
Thanks,
HarshitQuoted 21 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
There are some similar fstests failures this fix might address.
I've applied this patch to the nfsd-fixes tree for broader testing.
ERROR: modpost: "
setattr_should_drop_sgid" [fs/nfsd/nfsd.ko] undefined!Did I apply this patch to the wrong kernel?
setattr_should_drop_sgid()is not available to callers built as modules. It needs anEXPORT_SYMBOLor_GPL.Hey Chuck,
Thanks for taking a look!
The required export is part of
commit4f704d9a835("nfs: use vfs setgid helper")
which is in current mainline as of Monday this week which was part of my v6.4/vfs.misc PR that was merged.
So this should all work fine on mainline. Seems I didn't use --base which is why that info was missing.
Thanks!
Christian
Quoted 6 lines
Quoted 2 lines
I'll apply this to nfsd-next (6.5) and add Jeff's Reviewed-by and a Cc: stable.
Hi Chuck,
Just following up to see if you know when this patch will go to linux mainline and linux-stable?
Howdy- mentioned above: applied to nfsd-next for the v6.5 merge window, which will open in several weeks.
I added a Cc: stable, so once it is in 6.5-rc it will be automatically backported into the stable kernels.
--
Chuck Lever
Quoted 57 lines · Christian Brauner
We've aligned setgid behavior over multiple kernel releases. The details can be found in commit
cf619f891971("Merge tag 'fs.ovl.setgid.v6.2' ofgit://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit426b4ca2d6a5("Merge tag 'fs.setgid.v6.0' ofgit://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux").
Consistent setgid stripping behavior is now encapsulated in thesetattr_should_drop_sgid()helper which is used by all filesystems that strip setgid bits outside of vfs proper. UsuallyATTR_KILL_SGIDis raised in e.g.,chown_common()and is subject to thesetattr_should_drop_sgid()check to determine whether the setgid bit can be retained. Since nfsd is raisingATTR_KILL_SGIDunconditionally it will causenotify_change()to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raisesATR_KILL_SGIDif the caller lacks the necessary privileges to retain the setgid bit.Without this patch the setgid stripping tests in LTP will fail:
Quoted 2 lines
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[...]
Quoted 1 line
fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700
[...]
Quoted 1 line
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]>---
ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s chown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s fchown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2faubuntu@imp1-vm:~/src/git/xfstests$ sudo ./check -g perms FSTYP -- nfs PLATFORM -- Linux/x86_64 imp1-vm 6.3.0-nfs-setgid-3a3cfe624076 #20 SMP PREEMPT_DYNAMIC Tue May 2 12:35:51 UTC 2023 MKFS_OPTIONS -- 127.0.0.1:/nfsscratch MOUNT_OPTIONS -- -o vers=3,noacl 127.0.0.1:/nfsscratch /mnt/scratch Passed all 41 tests --- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0
fs/nfsd/vfs.c nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) · line 396
Quoted 10 lines
fs/nfsd/vfs.c +3
-1@@ -388,7 +388,9 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) iap->ia_mode &= ~S_ISGID ; }else {/* set ATTR_KILL_* bits and let VFS handle it */ - iap->ia_valid |= (ATTR_KILL_SUID |ATTR_KILL_SGID ); + iap->ia_valid |=ATTR_KILL_SUID ; + iap->ia_valid |= +setattr_should_drop_sgid (&nop_mnt_idmap, inode); } } }
Looks good to me. The thread should have assumed the user's creds by this point.