bpf: Fix deadlock in kptr dtor in nmi
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest2 patches 17 repliesIn review
- v22 patches 6 repliesSuperseded
- v14 patches 3 repliesSuperseded
Patches in v3 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | bpf: Offload kptr destructors that run from NMIinclude/ include/ kernel/ +3 more | +232 | 17 replies | |
| 2/2 | selftests/bpf: Add kptr destructor NMI exercisertools/ tools/ | +670 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.
Cover letter [bpf-next v3 0/2] bpf: Fix deadlock in kptr dtor 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.
That is problematic because referenced kptr destructor paths are not universally NMI-safe. In particular, they may rely on operations such as call_rcu(), which can deadlock when reached from NMI context.
This is v3 of the series.
Changes since v2:
The previous version of the series used three atomics and had an ABA race condition. This version of the series moves both the idle and active job queues to pcpu_freelists, which are designed for the push/pop operations and better handle NMI.
The number of atomics was reduced from 3 -> 1, using a counter that tracks only demand, reducing complexity significantly.
See the patch one commit message for the full details on the new surplus accounting mechanism.
The verifier changes were fixed as well to account for a case found by Sashiko; because we are now only inlining in the non-dtor case, there was a bug (introduced by the patch) where an xchg call insn could be polymorphic with respect to referenced and unreferenced kptrs. This is fixed with a new verifier check.
Finally, the selftests had some small adjustments. The counters were moved to u64 atomics from u32 non-atomics to decrease potential test flakiness. There was a small change on when kern_sync_rcu is called.
1. bpf: Offload kptr destructors that run from NMI
2. selftests/bpf: Add kptr destructor NMI exerciser
Kind regards,
Justin Suess
[1] https://lore.kernel.org/bpf/[email protected]/
[2] https://lore.kernel.org/bpf/afYLJAT9brXkWxz2@zenbox/
[3] https://lore.kernel.org/bpf/[email protected]/
v2: https://lore.kernel.org/bpf/[email protected]/
v1: https://lore.kernel.org/bpf/[email protected]/
Justin Suess (2):
bpf: Offload kptr destructors that run from NMI selftests/bpf: Add kptr destructor NMI exerciser
include/linux/bpf.h | 16 + include/linux/bpf_verifier.h | 2 + kernel/bpf/fixups.c | 33 +- kernel/bpf/helpers.c | 24 +- kernel/bpf/syscall.c | 159 +++++++ kernel/bpf/verifier.c | 13 + .../selftests/bpf/prog_tests/kptr_dtor_nmi.c | 258 +++++++++++ .../selftests/bpf/progs/kptr_dtor_nmi.c | 412 ++++++++++++++++++ 8 files changed, 902 insertions(+), 15 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/kptr_dtor_nmi.c create mode 100644 tools/testing/selftests/bpf/progs/kptr_dtor_nmi.c
base-commit: 2ca6723a5f7b68c739dba47b2639e3eaa7884b09
Signature · 1 line
2.53.0