BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v7 0/2] bpf: Track borrowed iterator result lifetimes
@ 2026-10-21 21:07 Xu Yunxiang
  2026-10-21 21:07 ` [PATCH bpf-next v7 1/2] bpf: Track borrowed iterator results by default Xu Yunxiang
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Xu Yunxiang @ 2026-10-21 21:07 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, eddyz87, memxor, ameryhung, yonghong.song,
	puranjay

Make non-RCU, non-acquired struct iterator results borrow the current
element lifetime by default. KF_ITER_RET_INDEPENDENT marks the explicit
exception for results whose lifetime is independent of the iterator.

Trusted field loads and dynptr constructors propagate the source lifetime
so derived pointers stay in the invalidation graph. Next preserves the
iterator itself and invalidates old dependents before both return
outcomes; destroy propagates outstanding-child errors.

As Alexei pointed out, the trusted-field rule is generic. Patch 1 now
explains why an inode pointer loaded from an acquired file becomes
invalid when that file reference is released, and how the same rule
applies to fields derived from an iterator result. Patch 2 adds VFS
tests for the valid before-release access and the rejected after-release
access alongside the existing iterator lifetime tests.

The field-propagation overlap with Kumar's related work remains. This
series introduces no general kfunc borrowed-return annotation; the
separate bpf_real_data_inode() return-lifetime gap remains outside its
scope. The iterator policy has no dependency on that annotation.

Changes in v7:
  - Explain the generic trusted-field lifetime rule and the file/inode
    example in patch 1's commit log, as requested by Alexei.
  - Add a positive and negative VFS test for that example in patch 2.
  - Rebase onto bpf-next b116ac6087541. The implementation's added and
    removed lines are unchanged from posted v6; the field-load hunk's
    context now includes the upstream __nullable handling.

v6:
https://lore.kernel.org/r/20260927120406.1041915-1-xyx2021@mail.ustc.edu.cn
Alexei's v6 review:
https://lore.kernel.org/r/DMA2SZ5PRG4N.3I51MHSTWUUTS@gmail.com
Kumar's related work:
https://lore.kernel.org/r/DLGYPZAL708V.3GFLANAPH2L8O@gmail.com

Validation on this candidate with a matching bpf_testmod:
  - W=1 verifier, full kernel and modules builds passed.
  - Changed BPF objects and required fixture compiled strictly.
  - iters: 1/122 passed; 0 skipped.
  - dynptr: 2/137 passed; 0 skipped.
  - file_reader: 1/10 passed; 0 skipped.
  - verifier_vfs_accept: 1/7 passed; 0 skipped.
  - verifier_vfs_reject: 1/13 passed; 0 skipped.
  - kmem_cache_iter: 1/3 passed; 0 skipped.
  - dmabuf_iter: 1/4 passed; 0 skipped.

The new before-release VFS program loaded on both the unmodified
baseline and this candidate. The after-release program loaded on the
baseline and was rejected by this candidate with the expected scalar
access diagnostic. These annotated programs are load-only.

The VMs used panic_on_warn and panic_on_oops. No WARN_ON report,
Oops or panic was found. Unprivileged BPF was enabled only in the
isolated guests.

The broad test_progs build used BPF_STRICT_BUILD=0; no compile skips
were reported. The unfiltered full
suite, sanitizer and architecture matrices were not run. The fresh
baseline comparison covers the new VFS example.

Please queue the verifier fix for stable after it reaches the BPF tree.

Xu Yunxiang (2):
  bpf: Track borrowed iterator results by default
  selftests/bpf: Test borrowed iterator result lifetimes

 Documentation/bpf/bpf_iterators.rst           |  10 +
 include/linux/btf.h                           |   1 +
 kernel/bpf/btf.c                              |  13 +-
 kernel/bpf/verifier.c                         | 103 ++++-
 .../selftests/bpf/progs/iters_testmod.c       | 370 ++++++++++++++++++
 .../selftests/bpf/progs/verifier_vfs_accept.c |  17 +
 .../selftests/bpf/progs/verifier_vfs_reject.c |  19 +
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  25 ++
 .../selftests/bpf/test_kmods/bpf_testmod.h    |   4 +
 .../bpf/test_kmods/bpf_testmod_kfunc.h        |   5 +
 10 files changed, 548 insertions(+), 19 deletions(-)


base-commit: b116ac6087541d3d98031e786adbe9c733cd6df3
-- 
2.43.0


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

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-21 21:07 [PATCH bpf-next v7 0/2] bpf: Track borrowed iterator result lifetimes Xu Yunxiang
2026-10-21 21:07 ` [PATCH bpf-next v7 1/2] bpf: Track borrowed iterator results by default Xu Yunxiang
2026-10-21 21:29   ` Amery Hung
2026-10-22  3:42   ` Alexei Starovoitov
2026-10-21 21:07 ` [PATCH bpf-next v7 2/2] selftests/bpf: Test borrowed iterator result lifetimes Xu Yunxiang
2026-10-21 21:31   ` Amery Hung
2026-10-23 15:43 ` [PATCH bpf-next v7 0/2] bpf: Track " Justin Suess

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