* [PATCH bpf-next v2 1/1] bpf: Do not allow deleting local storage in NMI
@ 2026-03-19 2:57 Amery Hung
2026-03-19 19:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Amery Hung @ 2026-03-19 2:57 UTC (permalink / raw)
To: bpf
Cc: alexei.starovoitov, andrii, daniel, memxor, martin.lau, ameryhung,
kernel-team
Currently, local storage may deadlock when deferring freeing selem or
local storage through kfree_rcu(), call_rcu() or call_rcu_tasks_trace()
in NMI or reentrant. Since deleting selem in NMI is an unlikely use
case, partially mitigate it by returning error when calling from
bpf_xxx_storage_delete() helpers in NMI. Note that, it is still possible
to deadlock through reentrant. A full mitigation requires returning
error when irqs_disabled() is true, which, however is too heavy-handed
for bpf_xxx_storage_delete().
The long-term solution requires _nolock versions of call_rcu. Another
possible solution is to defer the free through irq_work [0], but it
would grow the size of selem, which is non-ideal.
The check is only needed in bpf_selem_unlink(), which is used by helpers
and syscalls. bpf_selem_unlink_nofail() is fine as it is called during
map and owner tear down that never run in NMI or reentrant.
[0] https://lore.kernel.org/bpf/20260205190233.912-1-alexei.starovoitov@gmail.com/
Fixes: a10787e6d58c ("bpf: Enable task local storage for tracing programs")
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Amery Hung <ameryhung@gmail.com>
---
kernel/bpf/bpf_local_storage.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index 69bb2a7a71bc..cad17ca8552f 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -393,6 +393,9 @@ int bpf_selem_unlink(struct bpf_local_storage_elem *selem)
unsigned long flags;
int err;
+ if (in_nmi())
+ return -EOPNOTSUPP;
+
if (unlikely(!selem_linked_to_storage_lockless(selem)))
/* selem has already been unlinked from sk */
return 0;
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH bpf-next v2 1/1] bpf: Do not allow deleting local storage in NMI
2026-03-19 2:57 [PATCH bpf-next v2 1/1] bpf: Do not allow deleting local storage in NMI Amery Hung
@ 2026-03-19 19:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-19 19:10 UTC (permalink / raw)
To: Amery Hung
Cc: bpf, alexei.starovoitov, andrii, daniel, memxor, martin.lau,
kernel-team
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:
On Wed, 18 Mar 2026 19:57:16 -0700 you wrote:
> Currently, local storage may deadlock when deferring freeing selem or
> local storage through kfree_rcu(), call_rcu() or call_rcu_tasks_trace()
> in NMI or reentrant. Since deleting selem in NMI is an unlikely use
> case, partially mitigate it by returning error when calling from
> bpf_xxx_storage_delete() helpers in NMI. Note that, it is still possible
> to deadlock through reentrant. A full mitigation requires returning
> error when irqs_disabled() is true, which, however is too heavy-handed
> for bpf_xxx_storage_delete().
>
> [...]
Here is the summary with links:
- [bpf-next,v2,1/1] bpf: Do not allow deleting local storage in NMI
https://git.kernel.org/bpf/bpf-next/c/350de5b8a9be
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-19 19:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19 2:57 [PATCH bpf-next v2 1/1] bpf: Do not allow deleting local storage in NMI Amery Hung
2026-03-19 19:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox