* [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
@ 2026-01-22 14:07 Ondrej Mosnacek
2026-01-26 22:52 ` Paul Moore
0 siblings, 1 reply; 7+ messages in thread
From: Ondrej Mosnacek @ 2026-01-22 14:07 UTC (permalink / raw)
To: Andrew Morton, Eric W . Biederman
Cc: linux-kernel, linux-security-module, selinux
The user.* sysctls implement the ctl_table_root::permissions hook and
they override the file access mode based on the CAP_SYS_RESOURCE
capability (at most rwx if capable, at most r-- if not). The capability
is being checked unconditionally, so if an LSM denies the capability, an
audit record may be logged even when access is in fact granted.
Given the logic in the set_permissions() function in kernel/ucount.c and
the unfortunate way the permission checking is implemented, it doesn't
seem viable to avoid false positive denials by deferring the capability
check. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c)
- switch from ns_capable() to ns_capable_noaudit(), so that the check
never logs an audit record.
Fixes: dbec28460a89 ("userns: Add per user namespace sysctls.")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
---
kernel/ucount.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/ucount.c b/kernel/ucount.c
index 586af49fc03e4..fc4a8f2d30965 100644
--- a/kernel/ucount.c
+++ b/kernel/ucount.c
@@ -47,7 +47,7 @@ static int set_permissions(struct ctl_table_header *head,
int mode;
/* Allow users with CAP_SYS_RESOURCE unrestrained access */
- if (ns_capable(user_ns, CAP_SYS_RESOURCE))
+ if (ns_capable_noaudit(user_ns, CAP_SYS_RESOURCE))
mode = (table->mode & S_IRWXU) >> 6;
else
/* Allow all others at most read-only access */
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
2026-01-22 14:07 [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit() Ondrej Mosnacek
@ 2026-01-26 22:52 ` Paul Moore
2026-01-27 1:47 ` Serge E. Hallyn
0 siblings, 1 reply; 7+ messages in thread
From: Paul Moore @ 2026-01-26 22:52 UTC (permalink / raw)
To: Ondrej Mosnacek
Cc: Andrew Morton, Eric W . Biederman, linux-kernel,
linux-security-module, selinux
On Thu, Jan 22, 2026 at 9:25 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
>
> The user.* sysctls implement the ctl_table_root::permissions hook and
> they override the file access mode based on the CAP_SYS_RESOURCE
> capability (at most rwx if capable, at most r-- if not). The capability
> is being checked unconditionally, so if an LSM denies the capability, an
> audit record may be logged even when access is in fact granted.
>
> Given the logic in the set_permissions() function in kernel/ucount.c and
> the unfortunate way the permission checking is implemented, it doesn't
> seem viable to avoid false positive denials by deferring the capability
> check. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c)
> - switch from ns_capable() to ns_capable_noaudit(), so that the check
> never logs an audit record.
>
> Fixes: dbec28460a89 ("userns: Add per user namespace sysctls.")
> Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> ---
> kernel/ucount.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Paul Moore <paul@paul-moore.com>
--
paul-moore.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
2026-01-26 22:52 ` Paul Moore
@ 2026-01-27 1:47 ` Serge E. Hallyn
2026-01-27 8:05 ` Ondrej Mosnacek
0 siblings, 1 reply; 7+ messages in thread
From: Serge E. Hallyn @ 2026-01-27 1:47 UTC (permalink / raw)
To: Paul Moore
Cc: Ondrej Mosnacek, Andrew Morton, Eric W . Biederman, linux-kernel,
linux-security-module, selinux
On Mon, Jan 26, 2026 at 05:52:03PM -0500, Paul Moore wrote:
> On Thu, Jan 22, 2026 at 9:25 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> >
> > The user.* sysctls implement the ctl_table_root::permissions hook and
> > they override the file access mode based on the CAP_SYS_RESOURCE
> > capability (at most rwx if capable, at most r-- if not). The capability
> > is being checked unconditionally, so if an LSM denies the capability, an
> > audit record may be logged even when access is in fact granted.
> >
> > Given the logic in the set_permissions() function in kernel/ucount.c and
> > the unfortunate way the permission checking is implemented, it doesn't
> > seem viable to avoid false positive denials by deferring the capability
> > check. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c)
> > - switch from ns_capable() to ns_capable_noaudit(), so that the check
> > never logs an audit record.
> >
> > Fixes: dbec28460a89 ("userns: Add per user namespace sysctls.")
> > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > ---
> > kernel/ucount.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Reviewed-by: Paul Moore <paul@paul-moore.com>
Acked-by: Serge Hallyn <serge@hallyn.com>
Looks good to me. What tree should this go through? Network?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
2026-01-27 1:47 ` Serge E. Hallyn
@ 2026-01-27 8:05 ` Ondrej Mosnacek
2026-01-27 22:09 ` Paul Moore
0 siblings, 1 reply; 7+ messages in thread
From: Ondrej Mosnacek @ 2026-01-27 8:05 UTC (permalink / raw)
To: Serge E. Hallyn
Cc: Paul Moore, Andrew Morton, Eric W . Biederman, linux-kernel,
linux-security-module, selinux
On Tue, Jan 27, 2026 at 2:55 AM Serge E. Hallyn <serge@hallyn.com> wrote:
>
> On Mon, Jan 26, 2026 at 05:52:03PM -0500, Paul Moore wrote:
> > On Thu, Jan 22, 2026 at 9:25 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> > >
> > > The user.* sysctls implement the ctl_table_root::permissions hook and
> > > they override the file access mode based on the CAP_SYS_RESOURCE
> > > capability (at most rwx if capable, at most r-- if not). The capability
> > > is being checked unconditionally, so if an LSM denies the capability, an
> > > audit record may be logged even when access is in fact granted.
> > >
> > > Given the logic in the set_permissions() function in kernel/ucount.c and
> > > the unfortunate way the permission checking is implemented, it doesn't
> > > seem viable to avoid false positive denials by deferring the capability
> > > check. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c)
> > > - switch from ns_capable() to ns_capable_noaudit(), so that the check
> > > never logs an audit record.
> > >
> > > Fixes: dbec28460a89 ("userns: Add per user namespace sysctls.")
> > > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > > ---
> > > kernel/ucount.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > Reviewed-by: Paul Moore <paul@paul-moore.com>
>
> Acked-by: Serge Hallyn <serge@hallyn.com>
>
> Looks good to me. What tree should this go through? Network?
Andrew has already applied the two patches I posted into his
mm-nonmm-unstable branch, so I assume they are set to go through his
tree.
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/log/?h=mm-nonmm-unstable
--
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
2026-01-27 8:05 ` Ondrej Mosnacek
@ 2026-01-27 22:09 ` Paul Moore
2026-02-22 19:58 ` Andrew Morton
0 siblings, 1 reply; 7+ messages in thread
From: Paul Moore @ 2026-01-27 22:09 UTC (permalink / raw)
To: Andrew Morton
Cc: Ondrej Mosnacek, Serge E. Hallyn, Eric W . Biederman,
linux-kernel, linux-security-module, selinux
On Tue, Jan 27, 2026 at 3:05 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
>
> On Tue, Jan 27, 2026 at 2:55 AM Serge E. Hallyn <serge@hallyn.com> wrote:
> >
> > On Mon, Jan 26, 2026 at 05:52:03PM -0500, Paul Moore wrote:
> > > On Thu, Jan 22, 2026 at 9:25 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> > > >
> > > > The user.* sysctls implement the ctl_table_root::permissions hook and
> > > > they override the file access mode based on the CAP_SYS_RESOURCE
> > > > capability (at most rwx if capable, at most r-- if not). The capability
> > > > is being checked unconditionally, so if an LSM denies the capability, an
> > > > audit record may be logged even when access is in fact granted.
> > > >
> > > > Given the logic in the set_permissions() function in kernel/ucount.c and
> > > > the unfortunate way the permission checking is implemented, it doesn't
> > > > seem viable to avoid false positive denials by deferring the capability
> > > > check. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c)
> > > > - switch from ns_capable() to ns_capable_noaudit(), so that the check
> > > > never logs an audit record.
> > > >
> > > > Fixes: dbec28460a89 ("userns: Add per user namespace sysctls.")
> > > > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > > > ---
> > > > kernel/ucount.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > Reviewed-by: Paul Moore <paul@paul-moore.com>
> >
> > Acked-by: Serge Hallyn <serge@hallyn.com>
> >
> > Looks good to me. What tree should this go through? Network?
>
> Andrew has already applied the two patches I posted into his
> mm-nonmm-unstable branch, so I assume they are set to go through his
> tree.
Andrew, any chance we can get a reply to these threads when you merge
a patch into your tree?
--
paul-moore.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
2026-01-27 22:09 ` Paul Moore
@ 2026-02-22 19:58 ` Andrew Morton
2026-02-22 20:44 ` Paul Moore
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2026-02-22 19:58 UTC (permalink / raw)
To: Paul Moore
Cc: Ondrej Mosnacek, Serge E. Hallyn, Eric W . Biederman,
linux-kernel, linux-security-module, selinux
On Tue, 27 Jan 2026 17:09:40 -0500 Paul Moore <paul@paul-moore.com> wrote:
> > > > > Fixes: dbec28460a89 ("userns: Add per user namespace sysctls.")
> > > > > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > > > > ---
> > > > > kernel/ucount.c | 2 +-
> > > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > Reviewed-by: Paul Moore <paul@paul-moore.com>
> > >
> > > Acked-by: Serge Hallyn <serge@hallyn.com>
> > >
> > > Looks good to me. What tree should this go through? Network?
> >
> > Andrew has already applied the two patches I posted into his
> > mm-nonmm-unstable branch, so I assume they are set to go through his
> > tree.
>
> Andrew, any chance we can get a reply to these threads when you merge
> a patch into your tree?
I already spray out soooo much email.
A better approach would be for me to become more chatty. Reply
"thanks, applied <reasons> <caveats> <etc>". Shall do this.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
2026-02-22 19:58 ` Andrew Morton
@ 2026-02-22 20:44 ` Paul Moore
0 siblings, 0 replies; 7+ messages in thread
From: Paul Moore @ 2026-02-22 20:44 UTC (permalink / raw)
To: Andrew Morton
Cc: Ondrej Mosnacek, Serge E. Hallyn, Eric W . Biederman,
linux-kernel, linux-security-module, selinux
On Sun, Feb 22, 2026 at 2:58 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Tue, 27 Jan 2026 17:09:40 -0500 Paul Moore <paul@paul-moore.com> wrote:
>
> > > > > > Fixes: dbec28460a89 ("userns: Add per user namespace sysctls.")
> > > > > > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > > > > > ---
> > > > > > kernel/ucount.c | 2 +-
> > > > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > > >
> > > > > Reviewed-by: Paul Moore <paul@paul-moore.com>
> > > >
> > > > Acked-by: Serge Hallyn <serge@hallyn.com>
> > > >
> > > > Looks good to me. What tree should this go through? Network?
> > >
> > > Andrew has already applied the two patches I posted into his
> > > mm-nonmm-unstable branch, so I assume they are set to go through his
> > > tree.
> >
> > Andrew, any chance we can get a reply to these threads when you merge
> > a patch into your tree?
>
> I already spray out soooo much email.
>
> A better approach would be for me to become more chatty. Reply
> "thanks, applied <reasons> <caveats> <etc>". Shall do this.
Appreciated, thank you.
--
paul-moore.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-22 20:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-22 14:07 [PATCH] ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit() Ondrej Mosnacek
2026-01-26 22:52 ` Paul Moore
2026-01-27 1:47 ` Serge E. Hallyn
2026-01-27 8:05 ` Ondrej Mosnacek
2026-01-27 22:09 ` Paul Moore
2026-02-22 19:58 ` Andrew Morton
2026-02-22 20:44 ` Paul Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox