linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] vfs: don't check may_create_in_sticky if the file is already open/created
@ 2022-07-26 20:23 Jeff Layton
  2022-07-26 20:27 ` Jeff Layton
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff Layton @ 2022-07-26 20:23 UTC (permalink / raw)
  To: viro
  Cc: linux-fsdevel, linux-nfs, linux-kernel, Christian Brauner,
	Yongchen Yang

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. Only call may_create_in_sticky
if the file hasn't already been opened or created.

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

diff --git a/fs/namei.c b/fs/namei.c
index 1f28d3f463c3..7480b6dc8d27 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3495,10 +3495,15 @@ static int do_open(struct nameidata *nd,
 			return -EEXIST;
 		if (d_is_dir(nd->path.dentry))
 			return -EISDIR;
-		error = may_create_in_sticky(mnt_userns, nd,
-					     d_backing_inode(nd->path.dentry));
-		if (unlikely(error))
-			return error;
+		if (!(file->f_mode & (FMODE_OPENED | FMODE_CREATED))) {
+			error = may_create_in_sticky(mnt_userns, nd,
+						d_backing_inode(nd->path.dentry));
+			if (unlikely(error)) {
+				printk("%s: f_mode=0x%x oflag=0x%x\n",
+					__func__, file->f_mode, open_flag);
+				return error;
+			}
+		}
 	}
 	if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
 		return -ENOTDIR;
-- 
2.37.1


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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-26 20:23 [RFC PATCH] vfs: don't check may_create_in_sticky if the file is already open/created Jeff Layton
2022-07-26 20:27 ` Jeff Layton
2022-07-27 11:34   ` Christian Brauner
2022-07-27 11:48     ` Christian Brauner
2022-07-27 12:04     ` Jeff Layton
2022-07-27 12:32       ` Christian Brauner
2022-07-27 13:00         ` Jeff Layton
2022-07-27 13:17           ` Christian Brauner

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).