Skip to content

Commit 27c9520

Browse files
WOnder93gregkh
authored andcommitted
fanotify: avoid/silence premature LSM capability checks
[ Upstream commit 0d5ee33 ] Make sure calling capable()/ns_capable() actually leads to access denied when false is returned, because these functions emit an audit record when a Linux Security Module denies the capability, which makes it difficult to avoid allowing/silencing unnecessary permissions in security policies (namely with SELinux). Where the return value just used to set a flag, use the non-auditing ns_capable_noaudit() instead. Fixes: 7cea2a3 ("fanotify: support limited functionality for unprivileged users") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Reviewed-by: Paul Moore <paul@paul-moore.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Link: https://patch.msgid.link/20260216150625.793013-2-omosnace@redhat.com Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0d19bce commit 27c9520

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

fs/notify/fanotify/fanotify_user.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,17 +1611,18 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
16111611
pr_debug("%s: flags=%x event_f_flags=%x\n",
16121612
__func__, flags, event_f_flags);
16131613

1614-
if (!capable(CAP_SYS_ADMIN)) {
1615-
/*
1616-
* An unprivileged user can setup an fanotify group with
1617-
* limited functionality - an unprivileged group is limited to
1618-
* notification events with file handles or mount ids and it
1619-
* cannot use unlimited queue/marks.
1620-
*/
1621-
if ((flags & FANOTIFY_ADMIN_INIT_FLAGS) ||
1622-
!(flags & (FANOTIFY_FID_BITS | FAN_REPORT_MNT)))
1623-
return -EPERM;
1614+
/*
1615+
* An unprivileged user can setup an fanotify group with limited
1616+
* functionality - an unprivileged group is limited to notification
1617+
* events with file handles or mount ids and it cannot use unlimited
1618+
* queue/marks.
1619+
*/
1620+
if (((flags & FANOTIFY_ADMIN_INIT_FLAGS) ||
1621+
!(flags & (FANOTIFY_FID_BITS | FAN_REPORT_MNT))) &&
1622+
!capable(CAP_SYS_ADMIN))
1623+
return -EPERM;
16241624

1625+
if (!ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN)) {
16251626
/*
16261627
* Setting the internal flag FANOTIFY_UNPRIV on the group
16271628
* prevents setting mount/filesystem marks on this group and
@@ -2006,8 +2007,8 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
20062007
* A user is allowed to setup sb/mount/mntns marks only if it is
20072008
* capable in the user ns where the group was created.
20082009
*/
2009-
if (!ns_capable(group->user_ns, CAP_SYS_ADMIN) &&
2010-
mark_type != FAN_MARK_INODE)
2010+
if (mark_type != FAN_MARK_INODE &&
2011+
!ns_capable(group->user_ns, CAP_SYS_ADMIN))
20112012
return -EPERM;
20122013

20132014
/*

0 commit comments

Comments
 (0)