* [PATCH bpf] bpf, lsm: Remove bpf_lsm_release_secctx from sleepable_lsm_hooks
@ 2026-11-19 6:18 梓川咲太
2026-11-19 6:27 ` Alexei Starovoitov
0 siblings, 1 reply; 3+ messages in thread
From: 梓川咲太 @ 2026-11-19 6:18 UTC (permalink / raw)
To: bpf; +Cc: security, kpsingh, matt, ast, daniel, andrii, stable
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: BoBppy <inkxiao12@gmail.com>
---
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_mmap_file)
BTF_ID(func, bpf_lsm_netlink_send)
BTF_ID(func, bpf_lsm_path_notify)
-BTF_ID(func, bpf_lsm_release_secctx)
BTF_ID(func, bpf_lsm_sb_alloc_security)
BTF_ID(func, bpf_lsm_sb_eat_lsm_opts)
BTF_ID(func, bpf_lsm_sb_kern_mount)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH bpf] bpf, lsm: Remove bpf_lsm_release_secctx from sleepable_lsm_hooks
2026-11-19 6:18 [PATCH bpf] bpf, lsm: Remove bpf_lsm_release_secctx from sleepable_lsm_hooks 梓川咲太
@ 2026-11-19 6:27 ` Alexei Starovoitov
2026-11-19 6:40 ` Yingke Xiao
0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2026-11-19 6:27 UTC (permalink / raw)
To: 梓川咲太, bpf
Cc: security, kpsingh, matt, ast, daniel, andrii, stable
On Thu Nov 19, 2026 at 6:18 AM UTC, 梓川咲太 wrote:
> 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: BoBppy <inkxiao12@gmail.com>
This is not a real name.
I'm dropping all of your patches.
Teach your bot basics first.
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH bpf] bpf, lsm: Remove bpf_lsm_release_secctx from sleepable_lsm_hooks
2026-11-19 6:27 ` Alexei Starovoitov
@ 2026-11-19 6:40 ` Yingke Xiao
0 siblings, 0 replies; 3+ messages in thread
From: Yingke Xiao @ 2026-11-19 6:40 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: bpf, security, kpsingh, matt, ast, daniel, andrii, stable
Hi Alexei,
I sincerely apologize for the confusion caused by my Gmail display name.
I am an academic security researcher, not an AI bot. The display name
on my personal Google account was inadvertently set to a fictional
alias, and I completely understand and respect the kernel's strict
Developer Certificate of Origin (DCO) requirement for real names. I
have now corrected my sender name to my real name.
The patch itself was manually analyzed, developed, and verified on
QEMU x86_64 running 7.4.0-rc3 and 6.12.118 LTS:
- Context: security_release_secctx() is called in atomic/RCU/softirq
context by Netfilter (e.g., ct_seq_start() holding rcu_read_lock(),
and nfqnl_enqueue_packet() in RX softirq).
- Issue: Having bpf_lsm_release_secctx listed in sleepable_lsm_hooks
allows lsm.s/ programs to call sleeping helpers/kfuncs (like
bpf_copy_from_user), which triggers "scheduling while atomic" warnings
or RCU stalls in those paths.
- Verification: Tested in QEMU with a custom BPF reproducer loading an
lsm.s/release_secctx program. Pre-patch loads successfully; post-patch
is rejected with -EINVAL.
I will re-send a clean v2 with my verified legal name in the
Signed-off-by and commit metadata.
Again, my apologies for the oversight regarding the sender identity,
and thank you for keeping the mailing list standards high.
Sincerely,
Yingke Xiao
Alexei Starovoitov <alexei.starovoitov@gmail.com> 于2026年11月19日周四 01:27写道:
>
> On Thu Nov 19, 2026 at 6:18 AM UTC, 梓川咲太 wrote:
> > 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: BoBppy <inkxiao12@gmail.com>
>
> This is not a real name.
> I'm dropping all of your patches.
> Teach your bot basics first.
>
> pw-bot: cr
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 6:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 6:18 [PATCH bpf] bpf, lsm: Remove bpf_lsm_release_secctx from sleepable_lsm_hooks 梓川咲太
2026-11-19 6:27 ` Alexei Starovoitov
2026-11-19 6:40 ` Yingke Xiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox