All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/4] bpf: bound trusted fields to their parent's lifetime
@ 2026-10-14 17:30 Justin Suess
  2026-10-14 17:30 ` [PATCH bpf-next v1 1/4] bpf: Carry MEM_RCU for trusted fields with MEM_RCU parents Justin Suess
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Justin Suess @ 2026-10-14 17:30 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: bpf, Justin Suess

Howdy folks,

Two fixes to the lifetime of trusted fields.

A field in the __safe_trusted or __safe_trusted_or_null sets becomes
PTR_TRUSTED regardless of how its parent is kept alive: nothing ties
the resulting pointer to its parent's lifetime. There are two separate
cases, RCU-protected parents and referenced parents.

First, an RCU-protected parent, e.g. mm->exe_file read under
bpf_rcu_read_lock(), is MEM_RCU. It can hand out file->f_inode as
fully trusted, and the inode pointer survives bpf_rcu_read_unlock().
It remains dereferenceable without PROBE_MEM and passable to kfuncs
expecting trusted arguments after the grace period.

Second, a referenced parent has the same lifetime problem with release
kfuncs. A trusted field walked out of an acquired object stays usable
even after the reference to its parent is dropped. An in-tree example:
the file acquired from bpf_get_task_exe_file() is released at
bpf_put_file(), but an f_inode taken out of it stays trusted after the
object may be freed.

Fix both by making the walked field inherit its parent's bound.
Patch 1 substitutes MEM_RCU for PTR_TRUSTED when the parent is
MEM_RCU, so the field is invalidated with the critical section like
every other RCU pointer. Patch 3 sets the walked field's parent_id to
the parent's reference. Programs that relied on either escape will no
longer load, but the behavior they relied on was essentially a
use-after-free being papered over with deferred free mechanisms and
refcounts held outside BPF.

Patches 2 and 4 add reject and accept selftests for each.

Justin

Justin Suess (4):
  bpf: Carry MEM_RCU for trusted fields with MEM_RCU parents
  selftests/bpf: Test MEM_RCU carry-over for trusted fields
  bpf: Bind trusted fields to their parent's reference
  selftests/bpf: Test trusted-field invalidation on parent release

 kernel/bpf/verifier.c                         | 11 ++++-
 .../selftests/bpf/progs/verifier_vfs_accept.c | 40 +++++++++++++++
 .../selftests/bpf/progs/verifier_vfs_reject.c | 49 +++++++++++++++++++
 3 files changed, 98 insertions(+), 2 deletions(-)


base-commit: 763187dbbf83764a57d5811168ef9de7b9a60e2d
-- 
2.55.0


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

end of thread, other threads:[~2026-10-14 18:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 17:30 [PATCH bpf-next v1 0/4] bpf: bound trusted fields to their parent's lifetime Justin Suess
2026-10-14 17:30 ` [PATCH bpf-next v1 1/4] bpf: Carry MEM_RCU for trusted fields with MEM_RCU parents Justin Suess
2026-10-14 17:30 ` [PATCH bpf-next v1 2/4] selftests/bpf: Test MEM_RCU carry-over for trusted fields Justin Suess
2026-10-14 17:43   ` sashiko-bot
2026-10-14 18:05     ` Justin Suess
2026-10-14 17:30 ` [PATCH bpf-next v1 3/4] bpf: Bind trusted fields to their parent's reference Justin Suess
2026-10-14 17:30 ` [PATCH bpf-next v1 4/4] selftests/bpf: Test trusted-field invalidation on parent release Justin Suess

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.