bpf: Fix deadlock in freeing of special fields in NMI
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest1 patch 10 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/1 | bpf: fix deadlock in special field destruction in NMIkernel/ kernel/ | +89 | 10 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH bpf-next 0/1] bpf: Fix deadlock in freeing of special fields in NMI
Hello,
While following up on a Sashiko report [1], I found that referenced kptr destructors can run from NMI context. One way to trigger this is from a tracing program attached to tp_btf/nmi_handler while a map element is being torn down.
This is a discards any approach from the previous series [2], thus starting fresh with a new one.
This changes the existing eager freeing behavior of bpf_obj_free_fields to only freeing certain fields in irqs_disabled contexts.
These fields not safe to free in irqs_disabled contexts like nmi include BPF_KPTR_REF, BPF_KPTR_PERCPU, BPF_UPTR, BPF_LIST_HEAD, and BPF_RB_ROOT.
The freeing of the fields under those conditions will now be done by the bpf memory allocator, which has a safe destructor mechanism that guarantees the fields are freed in a non-irqs_disabled context.
Some changes were required to the hashtab map specifically. When the above listed fields are present, the map is converted at initialization time to the non-prealloc variant. Additionally, the in-place field updates used by LRU and percpu maps were disabled when these special fields are present, to avoid leaking references and overwriting those fields when we can't free them immediately.
The relevant discussion for this change is here [2]
Kind regards,
Justin Suess
[1] https://lore.kernel.org/bpf/[email protected]/
[2] https://lore.kernel.org/bpf/[email protected]/
[3] https://lore.kernel.org/bpf/agCXEJKJh-JGMhjG@zenbox/
Justin Suess (1):
bpf: fix deadlock in special field destruction in NMI
kernel/bpf/hashtab.c | 93 +++++++++++++++++++++++++++++++++++++++----- kernel/bpf/syscall.c | 8 +++- 2 files changed, 89 insertions(+), 12 deletions(-)
base-commit: 576482b55c19e7ec00e162a0fde4c4f1a95128c7
Signature · 1 line
2.53.0