]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfs: reorder checks in may_create_in_sticky
authorMateusz Guzik <mjguzik@gmail.com>
Thu, 20 Jun 2024 12:03:59 +0000 (14:03 +0200)
committerChristian Brauner <brauner@kernel.org>
Tue, 25 Jun 2024 09:15:47 +0000 (11:15 +0200)
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>
Link: https://lore.kernel.org/r/20240620120359.151258-1-mjguzik@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/namei.c

index 3d3674c21d3c492a7ff801c097ea551eb773f5d7..8b40991cb59e0441676df0c662e4e315e3e6c1aa 100644 (file)
@@ -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;