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

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 <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20250516192803.838659-2-amir73il@gmail.com

authored by

Amir Goldstein and committed by
Jan Kara
90d12380 b9b410cc

+2 -9
+2 -9
fs/notify/fanotify/fanotify_user.c
··· 1334 1334 * A group with FAN_UNLIMITED_MARKS does not contribute to mark count 1335 1335 * in the limited groups account. 1336 1336 */ 1337 + BUILD_BUG_ON(!(FANOTIFY_ADMIN_INIT_FLAGS & FAN_UNLIMITED_MARKS)); 1337 1338 if (!FAN_GROUP_FLAG(group, FAN_UNLIMITED_MARKS) && 1338 1339 !inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_FANOTIFY_MARKS)) 1339 1340 return ERR_PTR(-ENOSPC); ··· 1638 1637 goto out_destroy_group; 1639 1638 } 1640 1639 1640 + BUILD_BUG_ON(!(FANOTIFY_ADMIN_INIT_FLAGS & FAN_UNLIMITED_QUEUE)); 1641 1641 if (flags & FAN_UNLIMITED_QUEUE) { 1642 - fd = -EPERM; 1643 - if (!capable(CAP_SYS_ADMIN)) 1644 - goto out_destroy_group; 1645 1642 group->max_events = UINT_MAX; 1646 1643 } else { 1647 1644 group->max_events = fanotify_max_queued_events; 1648 - } 1649 - 1650 - if (flags & FAN_UNLIMITED_MARKS) { 1651 - fd = -EPERM; 1652 - if (!capable(CAP_SYS_ADMIN)) 1653 - goto out_destroy_group; 1654 1645 } 1655 1646 1656 1647 if (flags & FAN_ENABLE_AUDIT) {