BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/6] bpf: Fix async callback use-after-free on map deletion
@ 2026-11-11  2:43 Yun Lu
  2026-11-11  2:43 ` [PATCH bpf-next v3 1/6] bpf: Mark task work FREED before detaching it Yun Lu
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Yun Lu @ 2026-11-11  2:43 UTC (permalink / raw)
  To: ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai
  Cc: yatsenko, bpf

From: Yun Lu <luyun@kylinos.cn>

This series fixes a use-after-free when a BPF program schedules task
work, workqueue work or a timer through a value pointer retained across
map deletion. Review of the earlier task-work series [1] pointed out
that cancellation can leave the deleted value open to reinitialization.

The original reader keeps the element alive while it queues new work,
but that does not make the new callback part of the grace period freeing
the element. The final destructor cannot stop a callback that has already
started outside that waiting set from accessing the freed key or value.
Patch 2 includes the interleaving and a historical KASAN report from the
unmodified kernel.

Following Alexei's suggestions [2, 3], check task-work membership after
claiming PENDING, and check wq/timer membership only in the shared setter.
Leave async init unchanged. An unconfigured object cannot start a BPF
callback, so a newly initialized object rejected by the setter stays idle
until normal cleanup.

Keep the cancellation-order fixes separate: mark task work FREED or clear
cb->map before detaching the object. Only the first invalidator clears
the slot and disposes of its map-owned context reference. No hashtab or
allocator changes are needed.

Patches 1-3 fix task work and add its regression test. Patches 4-6 fix the
shared wq/timer paths, adjust rhash_timer and add the wq regression test.

Testing on x86-64 QEMU/KVM with KASAN, PROVE_LOCKING, PROVE_RCU and
DEBUG_ATOMIC_SLEEP:

- task_work_stress, wq and rhash_timer pass with the full series.
- The same test binary on the unfixed base fails exactly the three
  deleted-value -ENOENT checks: task-work scheduling and wq/timer
  set_callback return 0. These are expected negative-control failures.
- Directed two-canceller checks for task work and wq also pass.

Changes since v2:
- Combine wq/timer membership checking in the shared setter; leave init
  unchanged (Alexei).
- Check membership through the map's existing lookup operation and
  remove the extra RCU guard around the lookup (Alexei).
- Let only the first invalidator detach task work or an async callback
  object and dispose of its map-owned reference.
- Reuse task_work_stress, wq and rhash_timer to reduce the added test
  code; retain the recycled timer-field check.

v2: https://lore.kernel.org/all/20261106095747.471718-1-luyun_611@163.com/

Changes since v1:
- Replace slot poisoning and allocator hooks with lookup checks (Alexei).
- Separate FREED-before-detach from task-work membership (Alexei).
- Fix the same publication problem for wq and timers (Alexei, Mykyta).
- Expand task-work coverage and add wq/timer regression tests.

v1: https://lore.kernel.org/all/20261028073525.1035605-1-luyun_611@163.com/

[1] https://lore.kernel.org/all/20261012061915.231254-1-luyun_611@163.com/
[2] https://lore.kernel.org/all/DMGN8VM2BAOR.28NRNN51MCI8I@gmail.com/
[3] https://lore.kernel.org/all/DMOAQI1S0JBS.3N3WETHD2L6KQ@gmail.com/

Yun Lu (6):
  bpf: Mark task work FREED before detaching it
  bpf: Check task work value membership before scheduling
  selftests/bpf: Test task work scheduling on a deleted value
  bpf: Invalidate async callbacks before detaching them
  bpf: Check async callback value membership in the setter
  selftests/bpf: Test wq set_callback on a deleted value

 include/uapi/linux/bpf.h                      |   2 +
 kernel/bpf/helpers.c                          |  90 ++++++++++++++++++++++---
 tools/include/uapi/linux/bpf.h                |   2 +
 ...ing/selftests/bpf/prog_tests/rhash_timer.c |  24 +++----
 ...elftests/bpf/prog_tests/task_work_stress.c |  18 +++++
 .../testing/selftests/bpf/progs/rhash_timer.c |  26 ++-----
 ...ing/selftests/bpf/progs/task_work_stress.c |  17 +++++
 tools/testing/selftests/bpf/progs/wq.c        |  20 ++++++
 8 files changed, 156 insertions(+), 43 deletions(-)

base-commit: bd75869299f1d4ff6e9f45117cce28f8badee1cd

-- 
2.43.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-11  8:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  2:43 [PATCH bpf-next v3 0/6] bpf: Fix async callback use-after-free on map deletion Yun Lu
2026-11-11  2:43 ` [PATCH bpf-next v3 1/6] bpf: Mark task work FREED before detaching it Yun Lu
2026-11-11  3:26   ` sashiko-bot
2026-11-11  2:43 ` [PATCH bpf-next v3 2/6] bpf: Check task work value membership before scheduling Yun Lu
2026-11-11  8:19   ` bot+bpf-ci
2026-11-11  2:43 ` [PATCH bpf-next v3 3/6] selftests/bpf: Test task work scheduling on a deleted value Yun Lu
2026-11-11  2:43 ` [PATCH bpf-next v3 4/6] bpf: Invalidate async callbacks before detaching them Yun Lu
2026-11-11  4:22   ` sashiko-bot
2026-11-11  2:43 ` [PATCH bpf-next v3 5/6] bpf: Check async callback value membership in the setter Yun Lu
2026-11-11  4:43   ` sashiko-bot
2026-11-11  2:43 ` [PATCH bpf-next v3 6/6] selftests/bpf: Test wq set_callback on a deleted value Yun Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox