]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ipc: don't audit capability check in ipc_permissions()
authorOndrej Mosnacek <omosnace@redhat.com>
Thu, 22 Jan 2026 14:13:03 +0000 (15:13 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 1 Feb 2026 00:16:07 +0000 (16:16 -0800)
The IPC sysctls implement the ctl_table_root::permissions hook and they
override the file access mode based on the CAP_CHECKPOINT_RESTORE
capability, which is being checked regardless of whether any access is
actually denied or not, so if an LSM denies the capability, an audit
record may be logged even when access is in fact granted.

It wouldn't be viable to restructure the sysctl permission logic to only
check the capability when the access would be actually denied if it's not
granted.  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 emits an audit record.

Link: https://lkml.kernel.org/r/20260122141303.241133-1-omosnace@redhat.com
Fixes: 0889f44e2810 ("ipc: Check permissions for checkpoint_restart sysctls at open time")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Alexey Gladkov <legion@kernel.org>
Acked-by: Serge Hallyn <serge@hallyn.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Paul Moore <paul@paul-moore.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/capability.h
ipc/ipc_sysctl.c

index 1fb08922552c79535eb9fb5d066caa318c215d58..37db92b3d6f89ee07b2685070d63477daf63e494 100644 (file)
@@ -203,6 +203,12 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns)
                ns_capable(ns, CAP_SYS_ADMIN);
 }
 
+static inline bool checkpoint_restore_ns_capable_noaudit(struct user_namespace *ns)
+{
+       return ns_capable_noaudit(ns, CAP_CHECKPOINT_RESTORE) ||
+               ns_capable_noaudit(ns, CAP_SYS_ADMIN);
+}
+
 /* audit system wants to get cap info from files as well */
 int get_vfs_caps_from_disk(struct mnt_idmap *idmap,
                           const struct dentry *dentry,
index 15b17e86e198cfa78c0e9999cfbf08257729963a..9b087ebeb643b7792ac053a001b568f4b89cdf03 100644 (file)
@@ -214,7 +214,7 @@ static int ipc_permissions(struct ctl_table_header *head, const struct ctl_table
        if (((table->data == &ns->ids[IPC_SEM_IDS].next_id) ||
             (table->data == &ns->ids[IPC_MSG_IDS].next_id) ||
             (table->data == &ns->ids[IPC_SHM_IDS].next_id)) &&
-           checkpoint_restore_ns_capable(ns->user_ns))
+           checkpoint_restore_ns_capable_noaudit(ns->user_ns))
                mode = 0666;
        else
 #endif