Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] permission checks for chdir need special treatment only on the last step

... so we ought to pass MAY_CHDIR to vfs_permission() instead of having
it triggered on every step of preceding pathname resolution. LOOKUP_CHDIR
is killed by that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 8bb79224 db2e747b

+2 -6
-2
fs/namei.c
··· 268 268 if (nd) { 269 269 if (nd->flags & LOOKUP_ACCESS) 270 270 extra |= MAY_ACCESS; 271 - if (nd->flags & LOOKUP_CHDIR) 272 - extra |= MAY_CHDIR; 273 271 if (nd->flags & LOOKUP_OPEN) 274 272 extra |= MAY_OPEN; 275 273 }
+2 -3
fs/open.c
··· 501 501 struct nameidata nd; 502 502 int error; 503 503 504 - error = __user_walk(filename, 505 - LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_CHDIR, &nd); 504 + error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); 506 505 if (error) 507 506 goto out; 508 507 509 - error = vfs_permission(&nd, MAY_EXEC); 508 + error = vfs_permission(&nd, MAY_EXEC | MAY_CHDIR); 510 509 if (error) 511 510 goto dput_and_out; 512 511
-1
include/linux/namei.h
··· 55 55 #define LOOKUP_OPEN (0x0100) 56 56 #define LOOKUP_CREATE (0x0200) 57 57 #define LOOKUP_ACCESS (0x0400) 58 - #define LOOKUP_CHDIR (0x0800) 59 58 60 59 extern int __user_walk(const char __user *, unsigned, struct nameidata *); 61 60 extern int __user_walk_fd(int dfd, const char __user *, unsigned, struct nameidata *);