Skip to content

Commit 90d1238

Browse files
amir73iljankara
authored andcommitted
fanotify: remove redundant permission checks
FAN_UNLIMITED_QUEUE and FAN_UNLIMITED_MARK flags are already checked as part of the CAP_SYS_ADMIN check for any FANOTIFY_ADMIN_INIT_FLAGS. Remove the individual CAP_SYS_ADMIN checks for these flags. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent b9b410c commit 90d1238

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
13341334
* A group with FAN_UNLIMITED_MARKS does not contribute to mark count
13351335
* in the limited groups account.
13361336
*/
1337+
BUILD_BUG_ON(!(FANOTIFY_ADMIN_INIT_FLAGS & FAN_UNLIMITED_MARKS));
13371338
if (!FAN_GROUP_FLAG(group, FAN_UNLIMITED_MARKS) &&
13381339
!inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_FANOTIFY_MARKS))
13391340
return ERR_PTR(-ENOSPC);
@@ -1637,21 +1638,13 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
16371638
goto out_destroy_group;
16381639
}
16391640

1641+
BUILD_BUG_ON(!(FANOTIFY_ADMIN_INIT_FLAGS & FAN_UNLIMITED_QUEUE));
16401642
if (flags & FAN_UNLIMITED_QUEUE) {
1641-
fd = -EPERM;
1642-
if (!capable(CAP_SYS_ADMIN))
1643-
goto out_destroy_group;
16441643
group->max_events = UINT_MAX;
16451644
} else {
16461645
group->max_events = fanotify_max_queued_events;
16471646
}
16481647

1649-
if (flags & FAN_UNLIMITED_MARKS) {
1650-
fd = -EPERM;
1651-
if (!capable(CAP_SYS_ADMIN))
1652-
goto out_destroy_group;
1653-
}
1654-
16551648
if (flags & FAN_ENABLE_AUDIT) {
16561649
fd = -EPERM;
16571650
if (!capable(CAP_AUDIT_WRITE))

0 commit comments

Comments
 (0)