security_release_secctx() invokes release_secctx LSM callbacks (selinux_release_secctx() and apparmor_release_secctx()), which only kfree(cp->context) and never sleep. Because the hook is non-blocking, Netfilter callers legitimately invoke security_release_secctx() under atomic, RCU, or softirq context: 1. net/netfilter/nf_conntrack_standalone.c: ct_seq_start() acquires rcu_read_lock() and holds it across ct_seq_show() -> ct_show_secctx() -> security_release_secctx(&ctx) until ct_seq_stop(). 2. net/netfilter/nfnetlink_queue.c: nfqnl_enqueue_packet() runs under rcu_read_lock() in packet RX softirq and calls nfqnl_build_packet_message(), which allocates with GFP_ATOMIC and calls security_release_secctx(&ctx). 3. net/netfilter/nf_conntrack_netlink.c: ctnetlink_conntrack_event() allocates with GFP_ATOMIC and calls ctnetlink_dump_secctx() -> security_release_secctx(&ctx). Listing BTF_ID(func, bpf_lsm_release_secctx) in sleepable_lsm_hooks lets BPF_PROG_TYPE_LSM sleepable programs (lsm.s/release_secctx) call blocking helpers/kfuncs such as bpf_copy_from_user() in atomic/RCU/softirq context, causing BUG: scheduling while atomic or RCU stalls. Remove bpf_lsm_release_secctx from sleepable_lsm_hooks. Verified by line inspection on 7.4.0-rc3 (20eef29b7c84), 6.12.118 (bpf_lsm.c:347), and 6.6.162 (bpf_lsm.c:337), and live QEMU BPF verifier runs on x86_64 7.4.0-rc3 and 6.12.118 (lsm.s/release_secctx: LOADED pre-patch -> REJECTED post-patch with -EINVAL, "bpf_lsm_release_secctx is not sleepable"). Fixes: 423f16108c9d ("bpf: Augment the set of sleepable LSM hooks") Cc: stable@vger.kernel.org # 5.10+ Signed-off-by: Yingke Xiao --- v1 -> v2: - Correct sender identity and Signed-off-by with real legal name per DCO. - Remove drafting notes. - No functional code changes. kernel/bpf/bpf_lsm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index 468e63d..c7d683e 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -368,7 +368,6 @@ BTF_ID(func, bpf_lsm_path_chown) BTF_ID(func, bpf_lsm_path_truncate) #endif BTF_ID(func, bpf_lsm_read_file) -BTF_ID(func, bpf_lsm_release_secctx) #ifdef CONFIG_SECURITY_PATH BTF_ID(func, bpf_lsm_sb_alloc_security) BTF_ID(func, bpf_lsm_sb_eat_lsm_opts) -- 2.43.0