linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfs: reorder checks in may_create_in_sticky
@ 2024-06-20 12:03 Mateusz Guzik
  2024-06-20 12:46 ` Jan Kara
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mateusz Guzik @ 2024-06-20 12:03 UTC (permalink / raw)
  To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel, Mateusz Guzik

The routine is called for all directories on file creation and weirdly
postpones the check if the dir is sticky to begin with. Instead it first
checks fifos and regular files (in that order), while avoidably pulling
globals.

No functional changes.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
 fs/namei.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 63d1fb06da6b..b1600060ecfb 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1246,9 +1246,9 @@ static int may_create_in_sticky(struct mnt_idmap *idmap,
 	umode_t dir_mode = nd->dir_mode;
 	vfsuid_t dir_vfsuid = nd->dir_vfsuid;
 
-	if ((!sysctl_protected_fifos && S_ISFIFO(inode->i_mode)) ||
-	    (!sysctl_protected_regular && S_ISREG(inode->i_mode)) ||
-	    likely(!(dir_mode & S_ISVTX)) ||
+	if (likely(!(dir_mode & S_ISVTX)) ||
+	    (S_ISREG(inode->i_mode) && !sysctl_protected_regular) ||
+	    (S_ISFIFO(inode->i_mode) && !sysctl_protected_fifos) ||
 	    vfsuid_eq(i_uid_into_vfsuid(idmap, inode), dir_vfsuid) ||
 	    vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, inode), current_fsuid()))
 		return 0;
-- 
2.43.0


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

end of thread, other threads:[~2024-06-21 11:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 12:03 [PATCH] vfs: reorder checks in may_create_in_sticky Mateusz Guzik
2024-06-20 12:46 ` Jan Kara
2024-06-20 13:59 ` Christian Brauner
2024-06-21  7:45 ` Christian Brauner
2024-06-21 11:17   ` Mateusz Guzik
2024-06-21 11:25   ` Jan Kara

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