BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/8] bpf: Fix async callback use-after-free on map deletion
@ 2026-11-06  9:57 Yun Lu
  2026-11-06  9:57 ` [PATCH bpf-next v2 1/8] bpf: Mark task work FREED before detaching it Yun Lu
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Yun Lu @ 2026-11-06  9:57 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 map value pointer retained
across 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 an allowed interleaving and a historical KASAN excerpt
from an unfixed kernel.

Following Alexei's suggestion [2], check whether the map lookup still
returns the value after publishing the context. For wq and timers, check
both init and the setter, since another CPU can configure the published
cb before init finishes its checks.

Keep the cancellation ordering fixes separate: mark task work FREED or
clear cb->map before detaching the object, so another canceller cannot
miss an old callback that can still start.

Patches 1-3 fix task work and add its selftests. Patches 4-8 fix the
shared wq/timer cancellation and admission paths, then add membership
checks and regression tests for each type.

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

- All 46 task-work membership subtests pass on the full series.
- The same 14 wq/timer subtests were run on the full series and on
  unfixed/partially fixed kernels as negative controls. Patches 1-3 and
  1-4 each fail ten checks: stale-value init returns 0 instead of the
  expected -ENOENT. With patches 1-5, only the five timer checks fail.
  These are expected negative-control failures. The full series passes
  all 14;

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/

Yun Lu (8):
  bpf: Mark task work FREED before detaching it
  bpf: Check task work value membership before scheduling
  selftests/bpf: Check task work value membership
  bpf: Order async callback admission and cancellation
  bpf: Check bpf_wq value membership before use
  selftests/bpf: Check bpf_wq value membership
  bpf: Check bpf_timer value membership before use
  selftests/bpf: Check bpf_timer value membership

 include/uapi/linux/bpf.h                      |   5 +-
 kernel/bpf/helpers.c                          | 126 +++++-
 tools/include/uapi/linux/bpf.h                |   5 +-
 .../bpf/prog_tests/bpf_timer_membership.c     | 199 +++++++++
 .../bpf/prog_tests/bpf_wq_membership.c        | 199 +++++++++
 .../selftests/bpf/prog_tests/rhash_timer.c    |  98 ++---
 .../bpf/prog_tests/task_work_membership.c     | 392 ++++++++++++++++++
 .../bpf/progs/bpf_timer_membership.c          | 161 +++++++
 .../selftests/bpf/progs/bpf_wq_membership.c   | 156 +++++++
 .../testing/selftests/bpf/progs/rhash_timer.c |  94 +++--
 .../bpf/progs/task_work_membership.c          | 158 +++++++
 11 files changed, 1476 insertions(+), 117 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_timer_membership.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_wq_membership.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/task_work_membership.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_timer_membership.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_wq_membership.c
 create mode 100644 tools/testing/selftests/bpf/progs/task_work_membership.c


base-commit: a3c8813409f13779fec225468aba7d4067a66468
-- 
2.43.0


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

end of thread, other threads:[~2026-11-09  9:51 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06  9:57 [PATCH bpf-next v2 0/8] bpf: Fix async callback use-after-free on map deletion Yun Lu
2026-11-06  9:57 ` [PATCH bpf-next v2 1/8] bpf: Mark task work FREED before detaching it Yun Lu
2026-11-06  9:57 ` [PATCH bpf-next v2 2/8] bpf: Check task work value membership before scheduling Yun Lu
2026-11-06  9:57 ` [PATCH bpf-next v2 3/8] selftests/bpf: Check task work value membership Yun Lu
2026-11-06 10:31   ` bot+bpf-ci
2026-11-06 10:56   ` sashiko-bot
2026-11-06  9:57 ` [PATCH bpf-next v2 4/8] bpf: Order async callback admission and cancellation Yun Lu
2026-11-06  9:57 ` [PATCH bpf-next v2 5/8] bpf: Check bpf_wq value membership before use Yun Lu
2026-11-06  9:57 ` [PATCH bpf-next v2 6/8] selftests/bpf: Check bpf_wq value membership Yun Lu
2026-11-06 10:31   ` bot+bpf-ci
2026-11-06 11:26   ` sashiko-bot
2026-11-06  9:57 ` [PATCH bpf-next v2 7/8] bpf: Check bpf_timer value membership before use Yun Lu
2026-11-06 10:31   ` bot+bpf-ci
2026-11-06  9:57 ` [PATCH bpf-next v2 8/8] selftests/bpf: Check bpf_timer value membership Yun Lu
2026-11-06 10:31   ` bot+bpf-ci
2026-11-06 11:51   ` sashiko-bot
2026-11-06 17:16 ` [PATCH bpf-next v2 0/8] bpf: Fix async callback use-after-free on map deletion Alexei Starovoitov
2026-11-09  9:50   ` luyun

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