[RFC PATCH v9 25/29] bpf: Register nsexec LSM hooks
From: Jarkko Sakkinen
Date: Mon Nov 30 2026 - 22:12:57 EST
BPF LSM programs need sleepable and untrusted hook classifications for
the nsexec LSM hooks in order to attach policies to nsexec
allocation, namespace sharing, cloning, signaling, and release.
Register bpf_lsm_nsexec_alloc, bpf_lsm_nsexec_share,
bpf_lsm_nsexec_clone, and bpf_lsm_nsexec_kill in
sleepable_lsm_hooks, and bpf_lsm_nsexec_alloc and
bpf_lsm_nsexec_free in untrusted_lsm_hooks under CONFIG_NSEXEC.
Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
---
kernel/bpf/bpf_lsm.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index ae23511fd811..41a62fb08656 100644
--- a/kernel/bpf/bpf_lsm.c
+++ b/kernel/bpf/bpf_lsm.c
@@ -16,6 +16,7 @@
#include <linux/btf_ids.h>
#include <linux/ima.h>
#include <linux/bpf-cgroup.h>
+#include <linux/nsexec.h>
/* For every LSM hook that allows attachment of BPF programs, declare a nop
* function where a BPF program can be attached. Notably, we qualify each with
@@ -404,6 +405,12 @@ BTF_ID(func, bpf_lsm_task_setscheduler)
BTF_ID(func, bpf_lsm_userns_create)
BTF_ID(func, bpf_lsm_bdev_alloc_security)
BTF_ID(func, bpf_lsm_bdev_setintegrity)
+#ifdef CONFIG_NSEXEC
+BTF_ID(func, bpf_lsm_nsexec_alloc)
+BTF_ID(func, bpf_lsm_nsexec_share)
+BTF_ID(func, bpf_lsm_nsexec_clone)
+BTF_ID(func, bpf_lsm_nsexec_kill)
+#endif /* CONFIG_NSEXEC */
BTF_SET_END(sleepable_lsm_hooks)
BTF_SET_START(untrusted_lsm_hooks)
@@ -422,6 +429,10 @@ BTF_ID(func, bpf_lsm_sk_free_security)
BTF_ID(func, bpf_lsm_task_free)
BTF_ID(func, bpf_lsm_bdev_alloc_security)
BTF_ID(func, bpf_lsm_bdev_free_security)
+#ifdef CONFIG_NSEXEC
+BTF_ID(func, bpf_lsm_nsexec_alloc)
+BTF_ID(func, bpf_lsm_nsexec_free)
+#endif /* CONFIG_NSEXEC */
BTF_SET_END(untrusted_lsm_hooks)
bool bpf_lsm_is_sleepable_hook(u32 btf_id)
--
2.47.3