Skip to content

Commit e84acaf

Browse files
ameryhunggregkh
authored andcommitted
bpf: Do not allow deleting local storage in NMI
[ Upstream commit 350de5b ] 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: a10787e ("bpf: Enable task local storage for tracing programs") Signed-off-by: Amery Hung <ameryhung@gmail.com> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://patch.msgid.link/20260319025716.2361065-1-ameryhung@gmail.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4f273d3 commit e84acaf

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

kernel/bpf/bpf_local_storage.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ int bpf_selem_unlink(struct bpf_local_storage_elem *selem)
393393
unsigned long flags;
394394
int err;
395395

396+
if (in_nmi())
397+
return -EOPNOTSUPP;
398+
396399
if (unlikely(!selem_linked_to_storage_lockless(selem)))
397400
/* selem has already been unlinked from sk */
398401
return 0;

0 commit comments

Comments
 (0)