linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6.1.y 0/2] Address ltp nfs test failure.
@ 2023-08-25 16:16 Harshit Mogalapalli
  2023-08-25 16:16 ` [PATCH 6.1.y 1/2] nfs: use vfs setgid helper Harshit Mogalapalli
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Harshit Mogalapalli @ 2023-08-25 16:16 UTC (permalink / raw)
  To: brauner, chuck.lever, bfields, stable, linux-nfs
  Cc: gregkh, hch, jlayton, vegard.nossum, naresh.kamboju,
	Harshit Mogalapalli

These two are backports for 6.1.y. Conflict resolution in done in
both patches.

I have tested LTP-nfs fchown02 and chown02 on 6.1.y with below patches
applied. The tests passed.

I would like to have a review as I am not familiar with this code.

Thanks to Vegard for helping me with this.

Thanks,
Harshit

Christian Brauner (2):
  nfs: use vfs setgid helper
  nfsd: use vfs setgid helper

 fs/attr.c          | 1 +
 fs/internal.h      | 2 --
 fs/nfs/inode.c     | 4 +---
 fs/nfsd/vfs.c      | 4 +++-
 include/linux/fs.h | 2 ++
 5 files changed, 7 insertions(+), 6 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 6.1.y 1/2] nfs: use vfs setgid helper
  2023-08-25 16:16 [PATCH 6.1.y 0/2] Address ltp nfs test failure Harshit Mogalapalli
@ 2023-08-25 16:16 ` Harshit Mogalapalli
  2023-08-25 16:16 ` [PATCH 6.1.y 2/2] nfsd: " Harshit Mogalapalli
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Harshit Mogalapalli @ 2023-08-25 16:16 UTC (permalink / raw)
  To: brauner, chuck.lever, bfields, stable, linux-nfs
  Cc: gregkh, hch, jlayton, vegard.nossum, naresh.kamboju,
	Harshit Mogalapalli

From: Christian Brauner <brauner@kernel.org>

commit 4f704d9a8352f5c0a8fcdb6213b934630342bd44 upstream.

We've aligned setgid behavior over multiple kernel releases. The details
can be found in the following two merge messages:
cf619f891971 ("Merge tag 'fs.ovl.setgid.v6.2')
426b4ca2d6a5 ("Merge tag 'fs.setgid.v6.0')
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. Switch nfs to rely on this
helper as well. Without this patch the setgid stripping tests in
xfstests will fail.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Message-Id: <20230313-fs-nfs-setgid-v2-1-9a59f436cfc0@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
[Harshit: backport to 6.1.y]
Conflicts:
	fs/internal.h -- minor conflict due to code change differences.
	include/linux/fs.h -- Used struct user_namespace *mnt_userns
			instead of struct mnt_idmap *idmap
	fs/nfs/inode.c -- Used init_user_ns instead of nop_mnt_idmap

Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
 fs/attr.c          | 1 +
 fs/internal.h      | 2 --
 fs/nfs/inode.c     | 4 +---
 include/linux/fs.h | 2 ++
 4 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/attr.c b/fs/attr.c
index b45f30e516fa..9b9a70e0cc54 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -47,6 +47,7 @@ int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
 		return ATTR_KILL_SGID;
 	return 0;
 }
+EXPORT_SYMBOL(setattr_should_drop_sgid);
 
 /**
  * setattr_should_drop_suidgid - determine whether the set{g,u}id bit needs to
diff --git a/fs/internal.h b/fs/internal.h
index 46caa33373a4..42df013f7fe7 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -242,5 +242,3 @@ ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *po
 /*
  * fs/attr.c
  */
-int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
-			     const struct inode *inode);
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 6b2cfa59a1a2..e0c1fb98f907 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -717,9 +717,7 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
 		if ((attr->ia_valid & ATTR_KILL_SUID) != 0 &&
 		    inode->i_mode & S_ISUID)
 			inode->i_mode &= ~S_ISUID;
-		if ((attr->ia_valid & ATTR_KILL_SGID) != 0 &&
-		    (inode->i_mode & (S_ISGID | S_IXGRP)) ==
-		     (S_ISGID | S_IXGRP))
+		if (setattr_should_drop_sgid(&init_user_ns, inode))
 			inode->i_mode &= ~S_ISGID;
 		if ((attr->ia_valid & ATTR_MODE) != 0) {
 			int mode = attr->ia_mode & S_IALLUGO;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index a2b5592c6828..26ea1a0a59a1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3120,6 +3120,8 @@ extern struct inode *new_inode(struct super_block *sb);
 extern void free_inode_nonrcu(struct inode *inode);
 extern int setattr_should_drop_suidgid(struct user_namespace *, struct inode *);
 extern int file_remove_privs(struct file *);
+int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
+			     const struct inode *inode);
 
 /*
  * This must be used for allocating filesystems specific inodes to set
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 6.1.y 2/2] nfsd: use vfs setgid helper
  2023-08-25 16:16 [PATCH 6.1.y 0/2] Address ltp nfs test failure Harshit Mogalapalli
  2023-08-25 16:16 ` [PATCH 6.1.y 1/2] nfs: use vfs setgid helper Harshit Mogalapalli
@ 2023-08-25 16:16 ` Harshit Mogalapalli
  2023-08-25 23:11 ` [PATCH 6.1.y 0/2] Address ltp nfs test failure Daniel Díaz
  2023-08-27  7:57 ` Greg KH
  3 siblings, 0 replies; 6+ messages in thread
From: Harshit Mogalapalli @ 2023-08-25 16:16 UTC (permalink / raw)
  To: brauner, chuck.lever, bfields, stable, linux-nfs
  Cc: gregkh, hch, jlayton, vegard.nossum, naresh.kamboju, Sherry Yang,
	Harshit Mogalapalli

From: Christian Brauner <brauner@kernel.org>

commit 2d8ae8c417db284f598dffb178cc01e7db0f1821 upstream.

We've aligned setgid behavior over multiple kernel releases. The details
can be found in commit cf619f891971 ("Merge tag 'fs.ovl.setgid.v6.2' of
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and
commit 426b4ca2d6a5 ("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 <sherry.yang@oracle.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
[Harshit: backport to 6.1.y:
Use init_user_ns instead of nop_mnt_idmap as we don't have
commit abf08576afe3 ("fs: port vfs_*() helpers to struct mnt_idmap")]
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
 fs/nfsd/vfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 155b34c4683c..4c11046800ab 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -321,7 +321,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(&init_user_ns, inode);
 		}
 	}
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 6.1.y 0/2] Address ltp nfs test failure.
  2023-08-25 16:16 [PATCH 6.1.y 0/2] Address ltp nfs test failure Harshit Mogalapalli
  2023-08-25 16:16 ` [PATCH 6.1.y 1/2] nfs: use vfs setgid helper Harshit Mogalapalli
  2023-08-25 16:16 ` [PATCH 6.1.y 2/2] nfsd: " Harshit Mogalapalli
@ 2023-08-25 23:11 ` Daniel Díaz
  2023-08-26 10:00   ` Harshit Mogalapalli
  2023-08-27  7:57 ` Greg KH
  3 siblings, 1 reply; 6+ messages in thread
From: Daniel Díaz @ 2023-08-25 23:11 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: brauner, chuck.lever, bfields, stable, linux-nfs, gregkh, hch,
	jlayton, vegard.nossum, naresh.kamboju

Hello!

On Fri, 25 Aug 2023 at 10:17, Harshit Mogalapalli
<harshit.m.mogalapalli@oracle.com> wrote:
> These two are backports for 6.1.y. Conflict resolution in done in
> both patches.
> I have tested LTP-nfs fchown02 and chown02 on 6.1.y with below patches
> applied. The tests passed.

I have given this a go but did not see better results.

On 6.1.48-rc1, without any extra patches:
  https://lkft.validation.linaro.org/scheduler/job/6685964#L3814
  https://storage.tuxsuite.com/public/linaro/lkft/builds/2UR2OCpseRQ0lu76phKZBw6l2xf/

On 6.1.48-rc1 plus this series of patches:
  https://lkft.validation.linaro.org/scheduler/job/6692637#L3832
  https://lkft.validation.linaro.org/scheduler/job/6692642#L3818
  https://storage.tuxsuite.com/public/linaro/daniel/builds/2UUHtMsTAQeuei3gGM32NWZx82w/

In both cases:
  chown02.c:46: TPASS: chown(testfile1, 0, 0) passed
  chown02.c:46: TPASS: chown(testfile2, 0, 0) passed
  chown02.c:58: TFAIL: testfile2: wrong mode permissions 0100700,
expected 0102700
[...]
  fchown02.c:57: TPASS: fchown(3, 0, 0) passed
  fchown02.c:57: TPASS: fchown(4, 0, 0) passed
  fchown02.c:67: TFAIL: testfile2: wrong mode permissions 0100700,
expected 0102700

The exact same thing happened with the 5.15 patch series.

I'll be glad to test more patches.

Greetings!

Daniel Díaz
daniel.diaz@linaro.org


> I would like to have a review as I am not familiar with this code.
>
> Thanks to Vegard for helping me with this.
>
> Thanks,
> Harshit
>
> Christian Brauner (2):
>   nfs: use vfs setgid helper
>   nfsd: use vfs setgid helper
>
>  fs/attr.c          | 1 +
>  fs/internal.h      | 2 --
>  fs/nfs/inode.c     | 4 +---
>  fs/nfsd/vfs.c      | 4 +++-
>  include/linux/fs.h | 2 ++
>  5 files changed, 7 insertions(+), 6 deletions(-)
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 6.1.y 0/2] Address ltp nfs test failure.
  2023-08-25 23:11 ` [PATCH 6.1.y 0/2] Address ltp nfs test failure Daniel Díaz
@ 2023-08-26 10:00   ` Harshit Mogalapalli
  0 siblings, 0 replies; 6+ messages in thread
From: Harshit Mogalapalli @ 2023-08-26 10:00 UTC (permalink / raw)
  To: Daniel Díaz
  Cc: brauner, chuck.lever, bfields, stable, linux-nfs, gregkh, hch,
	jlayton, vegard.nossum, naresh.kamboju

Hi Daniel,

On 26/08/23 4:41 am, Daniel Díaz wrote:
> Hello!
> 
> On Fri, 25 Aug 2023 at 10:17, Harshit Mogalapalli
> <harshit.m.mogalapalli@oracle.com> wrote:
>> These two are backports for 6.1.y. Conflict resolution in done in
>> both patches.
>> I have tested LTP-nfs fchown02 and chown02 on 6.1.y with below patches
>> applied. The tests passed.
> 
> I have given this a go but did not see better results.
> 
> On 6.1.48-rc1, without any extra patches:
>    https://lkft.validation.linaro.org/scheduler/job/6685964#L3814
>    https://storage.tuxsuite.com/public/linaro/lkft/builds/2UR2OCpseRQ0lu76phKZBw6l2xf/
> 
> On 6.1.48-rc1 plus this series of patches:
>    https://lkft.validation.linaro.org/scheduler/job/6692637#L3832
>    https://lkft.validation.linaro.org/scheduler/job/6692642#L3818
>    https://storage.tuxsuite.com/public/linaro/daniel/builds/2UUHtMsTAQeuei3gGM32NWZx82w/
> 
> In both cases:
>    chown02.c:46: TPASS: chown(testfile1, 0, 0) passed
>    chown02.c:46: TPASS: chown(testfile2, 0, 0) passed
>    chown02.c:58: TFAIL: testfile2: wrong mode permissions 0100700,
> expected 0102700
> [...]
>    fchown02.c:57: TPASS: fchown(3, 0, 0) passed
>    fchown02.c:57: TPASS: fchown(4, 0, 0) passed
>    fchown02.c:67: TFAIL: testfile2: wrong mode permissions 0100700,
> expected 0102700
> 
> The exact same thing happened with the 5.15 patch series.
> 

Odd, I just tested 5.15 based kernel again.

Unpatched kernel:

<<<test_start>>>
tag=fchown02 stime=1693034274
cmdline="fchown02"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1561: TINFO: Timeout per run is 0h 00m 30s
fchown02.c:58: TPASS: fchown(3, 0, 0) passed
fchown02.c:58: TPASS: fchown(4, 0, 0) passed
fchown02.c:68: TFAIL: testfile2: wrong mode permissions 0100700, 
expected 0102700

Summary:
passed   2
failed   1
broken   0
skipped  0
warnings 0

-----------

patched kernel:

<<<test_start>>>
tag=fchown02 stime=1693034615
cmdline="fchown02"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1561: TINFO: Timeout per run is 0h 00m 30s
fchown02.c:58: TPASS: fchown(3, 0, 0) passed
fchown02.c:58: TPASS: fchown(4, 0, 0) passed

Summary:
passed   2
failed   0
broken   0
skipped  0
warnings 0


Test steps:

mkdir /tmpdir

yum install nfs-utils  -y
echo "/media *(rw,no_root_squash,sync)" >/etc/exports
systemctl start nfs-server.service
mount -o rw,nfsvers=4 127.0.0.1:/media /tmpdir
cd /opt/ltp/
./runltp -d /tmpdir  -s fchown02


Thanks for testing.

Regards,
Harshit
> I'll be glad to test more patches.
> 
> Greetings!
> 
> Daniel Díaz
> daniel.diaz@linaro.org
> 
> 
>> I would like to have a review as I am not familiar with this code.
>>
>> Thanks to Vegard for helping me with this.
>>
>> Thanks,
>> Harshit
>>
>> Christian Brauner (2):
>>    nfs: use vfs setgid helper
>>    nfsd: use vfs setgid helper
>>
>>   fs/attr.c          | 1 +
>>   fs/internal.h      | 2 --
>>   fs/nfs/inode.c     | 4 +---
>>   fs/nfsd/vfs.c      | 4 +++-
>>   include/linux/fs.h | 2 ++
>>   5 files changed, 7 insertions(+), 6 deletions(-)
>>
>> --
>> 2.34.1
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 6.1.y 0/2] Address ltp nfs test failure.
  2023-08-25 16:16 [PATCH 6.1.y 0/2] Address ltp nfs test failure Harshit Mogalapalli
                   ` (2 preceding siblings ...)
  2023-08-25 23:11 ` [PATCH 6.1.y 0/2] Address ltp nfs test failure Daniel Díaz
@ 2023-08-27  7:57 ` Greg KH
  3 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2023-08-27  7:57 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: brauner, chuck.lever, bfields, stable, linux-nfs, hch, jlayton,
	vegard.nossum, naresh.kamboju

On Fri, Aug 25, 2023 at 09:16:01AM -0700, Harshit Mogalapalli wrote:
> These two are backports for 6.1.y. Conflict resolution in done in
> both patches.
> 
> I have tested LTP-nfs fchown02 and chown02 on 6.1.y with below patches
> applied. The tests passed.
> 
> I would like to have a review as I am not familiar with this code.
> 
> Thanks to Vegard for helping me with this.
> 
> Thanks,
> Harshit
> 
> Christian Brauner (2):
>   nfs: use vfs setgid helper
>   nfsd: use vfs setgid helper
> 
>  fs/attr.c          | 1 +
>  fs/internal.h      | 2 --
>  fs/nfs/inode.c     | 4 +---
>  fs/nfsd/vfs.c      | 4 +++-
>  include/linux/fs.h | 2 ++
>  5 files changed, 7 insertions(+), 6 deletions(-)
> 
> -- 
> 2.34.1
> 

All now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-27  7:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25 16:16 [PATCH 6.1.y 0/2] Address ltp nfs test failure Harshit Mogalapalli
2023-08-25 16:16 ` [PATCH 6.1.y 1/2] nfs: use vfs setgid helper Harshit Mogalapalli
2023-08-25 16:16 ` [PATCH 6.1.y 2/2] nfsd: " Harshit Mogalapalli
2023-08-25 23:11 ` [PATCH 6.1.y 0/2] Address ltp nfs test failure Daniel Díaz
2023-08-26 10:00   ` Harshit Mogalapalli
2023-08-27  7:57 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).