All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] bpf: Fix task work use-after-free on deletion
@ 2026-10-28  7:35 Yun Lu
  2026-10-28  7:35 ` [PATCH bpf-next 1/2] bpf: Retire task work before reclaiming hash elements Yun Lu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Yun Lu @ 2026-10-28  7:35 UTC (permalink / raw)
  To: bpf
  Cc: Yun Lu, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, John Fastabend, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Mykyta Yatsenko, Shuah Khan

From: Yun Lu <luyun@kylinos.cn>

This series fixes a task-work use-after-free when a BPF program schedules
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 context 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. If the callback enters RUNNING outside that waiting set, the
final destructor cannot stop it from accessing the freed key or value.
Patch 1 includes an allowed interleaving and a KASAN stack excerpt from a
controlled reproducer on the base unfixed kernel.

Patch 1 retires task-work slots before non-preallocated HASH/RHASH storage
is returned to the allocator, including abandoned RHASH candidates. It
also orders ordinary cancellation as FREED, conditional unpublish, then
map-owned reference disposal. Existing callback read-side protection and
element grace periods provide the lifetime guarantee.

Patch 2 adds 24 selftests for the retirement gate and compatibility: both
notification modes, live updates, and last-user-reference cleanup followed
by reopening the map by ID. Its callback only counts deliveries, allowing
an unfixed-kernel comparison without deliberately dereferencing freed
storage.

This is a separate series from the captured-task and irq_work BUSY fixes.
It is based on bpf-next commit 7c3188f84b54, which contains those fixes.

Testing on x86-64 QEMU/KVM:

- Same test_progs binary on both kernels, with KASAN, PROVE_LOCKING and
  PROVE_RCU: the unfixed kernel fails exactly the six retirement
  return-value assertions and passes the other 18 cases; the fixed
  kernel passes all 24, with no skips.
- An out-of-tree reproducer triggers the native KASAN report quoted in
  patch 1 on the unfixed kernel on every tested boot; on the fixed kernel
  the stale-pointer schedule is rejected with -ENOENT and no report
  occurs.

[1] https://lore.kernel.org/all/20261012061915.231254-1-luyun_611@163.com/

Yun Lu (2):
  bpf: Retire task work before reclaiming hash elements
  selftests/bpf: Check task work scheduling on retired values

 include/linux/bpf.h                           |   2 +
 kernel/bpf/hashtab.c                          |   7 +
 kernel/bpf/helpers.c                          |  80 +++++-
 .../bpf/prog_tests/task_work_retire.c         | 240 ++++++++++++++++++
 .../selftests/bpf/progs/task_work_retire.c    |  84 ++++++
 5 files changed, 403 insertions(+), 10 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/task_work_retire.c
 create mode 100644 tools/testing/selftests/bpf/progs/task_work_retire.c


base-commit: 7c3188f84b54d8e7643f6ec8454824df2823ba73
-- 
2.43.0


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

end of thread, other threads:[~2026-10-30  8:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28  7:35 [PATCH bpf-next 0/2] bpf: Fix task work use-after-free on deletion Yun Lu
2026-10-28  7:35 ` [PATCH bpf-next 1/2] bpf: Retire task work before reclaiming hash elements Yun Lu
2026-10-28 17:22   ` Alexei Starovoitov
2026-10-30  8:42     ` luyun
2026-10-28  7:35 ` [PATCH bpf-next 2/2] selftests/bpf: Check task work scheduling on Yun Lu
2026-10-28  8:22   ` bot+bpf-ci
2026-10-28 17:00 ` [PATCH bpf-next 0/2] bpf: Fix task work use-after-free on deletion Mykyta Yatsenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.