All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfs: bypass may_create_in_sticky check if task has CAP_FOWNER
@ 2022-07-27 12:30 Jeff Layton
  2022-07-27 12:37 ` Christian Brauner
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Layton @ 2022-07-27 12:30 UTC (permalink / raw)
  To: viro
  Cc: linux-fsdevel, linux-nfs, linux-kernel, Yongchen Yang, Christian Brauner

NFS server is exporting a sticky directory (mode 01777) with root
squashing enabled. Client has protect_regular enabled and then tries to
open a file as root in that directory. File is created (with ownership
set to nobody:nobody) but the open syscall returns an error.

The problem is may_create_in_sticky, which rejects the open even though
the file has already been created/opened. Bypass the checks in
may_create_in_sticky if the task has CAP_FOWNER in the given namespace.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=1976829
Reported-by: Yongchen Yang <yoyang@redhat.com>
Suggested-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/namei.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/namei.c b/fs/namei.c
index 1f28d3f463c3..170c2396ba29 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1230,7 +1230,8 @@ static int may_create_in_sticky(struct user_namespace *mnt_userns,
 	    (!sysctl_protected_regular && S_ISREG(inode->i_mode)) ||
 	    likely(!(dir_mode & S_ISVTX)) ||
 	    uid_eq(i_uid_into_mnt(mnt_userns, inode), dir_uid) ||
-	    uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode)))
+	    uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode)) ||
+	    ns_capable(mnt_userns, CAP_FOWNER))
 		return 0;
 
 	if (likely(dir_mode & 0002) ||
-- 
2.37.1


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

end of thread, other threads:[~2022-07-27 13:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 12:30 [PATCH] vfs: bypass may_create_in_sticky check if task has CAP_FOWNER Jeff Layton
2022-07-27 12:37 ` Christian Brauner
2022-07-27 12:55   ` Jeff Layton
2022-07-27 13:16     ` Christian Brauner
2022-07-27 13:29       ` Jeff Layton
2022-07-27 13:36         ` Christian Brauner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.