Skip to content

Commit 378831e

Browse files
committed
afs: Fix directory permissions check
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 [raspberrypi#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: 00d3b7a ("[AFS]: Add security support.") Reported-by: Jonathan Billings <jsbillings@jsbillings.org> Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 21b9f1c commit 378831e

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎fs/afs/security.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,14 @@ int afs_permission(struct inode *inode, int mask)
372372
mask, access, S_ISDIR(inode->i_mode) ? "dir" : "file");
373373

374374
if (S_ISDIR(inode->i_mode)) {
375-
if (mask & MAY_EXEC) {
375+
if (mask & (MAY_EXEC | MAY_READ | MAY_CHDIR)) {
376376
if (!(access & AFS_ACE_LOOKUP))
377377
goto permission_denied;
378-
} else if (mask & MAY_READ) {
379-
if (!(access & AFS_ACE_LOOKUP))
380-
goto permission_denied;
381-
} else if (mask & MAY_WRITE) {
378+
}
379+
if (mask & MAY_WRITE) {
382380
if (!(access & (AFS_ACE_DELETE | /* rmdir, unlink, rename from */
383381
AFS_ACE_INSERT))) /* create, mkdir, symlink, rename to */
384382
goto permission_denied;
385-
} else {
386-
BUG();
387383
}
388384
} else {
389385
if (!(access & AFS_ACE_LOOKUP))

0 commit comments

Comments
 (0)