]> git.itanic.dy.fi Git - linux-stable/commitdiff
afs: Fix directory permissions check
authorDavid Howells <dhowells@redhat.com>
Wed, 16 May 2018 20:25:46 +0000 (21:25 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 21 Oct 2018 07:46:11 +0000 (08:46 +0100)
commit 378831e4daec75fbba6d3612bcf3b4dd00ddbf08 upstream.

Doing faccessat("/afs/some/directory", 0) triggers a BUG in the permissions
check code.

Fix this by just removing the BUG section.  If no permissions are asked
for, just return okay if the file exists.

Also:

 (1) Split up the directory check so that it has separate if-statements
     rather than if-else-if (e.g. checking for MAY_EXEC shouldn't skip the
     check for MAY_READ and MAY_WRITE).

 (2) Check for MAY_CHDIR as MAY_EXEC.

Without the main fix, the following BUG may occur:

 kernel BUG at fs/afs/security.c:386!
 invalid opcode: 0000 [#1] SMP PTI
 ...
 RIP: 0010:afs_permission+0x19d/0x1a0 [kafs]
 ...
 Call Trace:
  ? inode_permission+0xbe/0x180
  ? do_faccessat+0xdc/0x270
  ? do_syscall_64+0x60/0x1f0
  ? entry_SYSCALL_64_after_hwframe+0x49/0xbe

Fixes: 00d3b7a4533e ("[AFS]: Add security support.")
Reported-by: Jonathan Billings <jsbillings@jsbillings.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/afs/security.c

index 24f0e2ca2c2561fd357992c6a966ff4d08673d7d..fcf2b07b1571a4bde3d565d93f45600041ac2a8f 100644 (file)
@@ -323,18 +323,14 @@ int afs_permission(struct inode *inode, int mask)
               mask, access, S_ISDIR(inode->i_mode) ? "dir" : "file");
 
        if (S_ISDIR(inode->i_mode)) {
-               if (mask & MAY_EXEC) {
+               if (mask & (MAY_EXEC | MAY_READ | MAY_CHDIR)) {
                        if (!(access & AFS_ACE_LOOKUP))
                                goto permission_denied;
-               } else if (mask & MAY_READ) {
-                       if (!(access & AFS_ACE_LOOKUP))
-                               goto permission_denied;
-               } else if (mask & MAY_WRITE) {
+               }
+               if (mask & MAY_WRITE) {
                        if (!(access & (AFS_ACE_DELETE | /* rmdir, unlink, rename from */
                                        AFS_ACE_INSERT))) /* create, mkdir, symlink, rename to */
                                goto permission_denied;
-               } else {
-                       BUG();
                }
        } else {
                if (!(access & AFS_ACE_LOOKUP))