Refactor verifier object relationship tracking
Subsystems (7)
v6 cover Refactor verifier object relationship tracking
Hi all,
This patchset cleans up dynptr handling, refactors object relationship tracking in the verifier by introducing parent_id and folding ref_obj_id into id, and fixes dynptr use-after-free bugs where file/skb dynptrs are not invalidated when the parent referenced object is freed.
* Motivation *
In BPF qdisc programs, an skb can be freed through kfuncs. However, since dynptr does not track the parent referenced object (e.g., skb), the verifier does not invalidate the dynptr after the skb is freed, resulting in use-after-free. The same issue also affects file dynptr.
The figure below shows the current state of object tracking. The verifier tracks objects using three fields: id for nullness tracking, ref_obj_id for lifetime tracking, and dynptr_id for tracking the parent dynptr of a slice (PTR_TO_MEM only). While dynptr_id links slices to their parent dynptr, there is no field that links a dynptr back to its parent skb. When the skb is freed via release_reference(ref_obj_id=1), only objects with ref_obj_id=1 are invalidated. Since skb dynptr is non-referenced (ref_obj_id=0), the dynptr and its derived slices remain accessible.
Current: object (id, ref_obj_id, dynptr_id)
id = unique id of the object (for nullness tracking)
ref_obj_id = id of the referenced object (for lifetime tracking) dynptr_id = id of the parent dynptr (only for PTR_TO_MEM slices)
skb (0,1,0)
^^
! No link from dynptr to skb !
|+------------------------------+
| bpf_dynptr_clone |
dynptr A (2,0,0) dynptr C (4,0,0)
^ ^
bpf_dynptr_slice | |
| |
slice B (3,0,2) slice D (5,0,4)* Why not simply use ref_obj_id to track the parent? *
A natural first approach is to link dynptr to its parent by sharing the parent's ref_obj_id and propagating it to slices. Now, releasing the skb via release_reference(ref_obj_id=1) correctly invalidates all derived objects.
Attempted fix: share parent's ref_obj_id
skb (0,1,0)
^^
||
|+------------------------------+
| bpf_dynptr_clone |
dynptr A (2,1,0) dynptr C (4,1,0)
^ ^
bpf_dynptr_slice | |
| |
slice B (3,1,2) slice D (5,1,4)However, this approach does not generalize to all dynptr types. Referenced dynptrs such as file dynptr acquire their own ref_obj_id to track the dynptr's lifetime. Since ref_obj_id is already used for the dynptr's own reference, it cannot also be used to point to the parent file object. While it is possible to add specialized handling for individual dynptr types [0], it adds complexity and does not generalize.
An alternative approach is to avoid introducing a new field and instead repurpose ref_obj_id as parent_id by folding lifetime tracking into id [1]. In this design, each object is represented as (id, ref_obj_id) where id is used for both nullness and lifetime tracking, and ref_obj_id tracks the parent object's id.
Attempted: object (id, ref_obj_id)
id = id of the object (for nullness and lifetime tracking)
ref_obj_id = id of the parent object
' = id is referenced
skb (1',0)
^^
||
bpf_dynptr_from_skb |+------------------------------+
| bpf_dynptr_clone(A, C) |
dynptr A (2,1') dynptr C (4,1')
^ ^
bpf_dynptr_slice | |
| |
slice B (3,2) slice D (5,4)However, this design cannot express the relationship between referenced socket pointers and their casted counterparts. After pointer casting, the original and casted pointers need the same lifetime (same ref_obj_id in the current design) but different nullness (different id). The casted pointer may be NULL even if the original is valid. With id serving as the only field for both nullness and lifetime, and ref_obj_id repurposed as parent, there is no way to express "different identity, same lifetime."
Referenced socket pointer (expressed using current design):
C = ptr_casting_function(A)
ptr A (1,1,0) ptr C (2,1,0)
^ ^
| |
ptr C may be NULL even if ptr A is valid but they have the same lifetime
* New Design: parent_id with branch splitting and intermediate reference *
The patchset folds ref_obj_id into id and adds parent_id to bpf_reg_state (patch 5). A child object's parent_id points to the parent object's id. This replaces the PTR_TO_MEM-specific dynptr_id. Whether a register is referenced is determined by checking if its id appears in the reference array via reg_is_referenced() rather than reading a dedicated ref_obj_id field.
Pointer casting:
The challenge with pointer casting is that a cast result may be NULL even when the source is valid, requiring distinct identity but shared lifetime. This is solved using branch splitting: when a helper like bpf_sk_fullsock() is called with a referenced pointer, the verifier pushes an explicit NULL branch and assigns the cast result the same id as the source. Since the cast may return NULL for a non-NULL input, the NULL case is explored as a separate verifier branch. This allows releasing any of the original or cast pointers to invalidate all others, while avoiding the need for a separate tracking mechanism.
Referenced dynptrs:
The challenge with referenced dynptrs is that clones of a referenced dynptr have the same lifetime but different identities. When a referenced dynptr is overwritten, only slices derived from it will be invalidated. To solve this, the verifier creates an intermediate reference. This reference serves as a shared lifetime anchor for the dynptr and all its clones. All clones share the same parent_id but get unique ids for independent slice tracking. Releasing a referenced dynptr releases the intermediate reference, which in turn invalidates all clones and their derived slices. If the parent object is released while the intermediate reference still exists, it is reported as a leaked reference.
Release cascading:
When releasing an object, release_reference() performs a stack-based DFS to invalidate all descendants. It walks the object tree via parent_id links, invalidating registers and dynptr stack slots. Child references encountered during traversal are reported as leaked references.
parent_id is also added to bpf_reference_state to enable intermediate reference. When acquiring a reference, a parent_id can be specified to link the new reference to an existing one (e.g., file dynptr's intermediate reference has parent_id linking to the file's reference).
Final: object (id, parent_id)
id = unique id of the object (for nullness and lifetime
tracking)
parent_id = id of the parent object (for object relationship
tracking)
I = intermediate reference serving as lifetime anchor in
acquired_refs
' = id is referenced (appears in reference array)
skb (1',0)
^^
||
bpf_dynptr_from_skb |+------------------------------+
| bpf_dynptr_clone(A, C) |
dynptr A (2,1') dynptr C (4,1')
^ ^
bpf_dynptr_slice | |
| |
slice B (3,2) slice D (5,4)* Preserving reg->id after null-check *
For parent_id tracking to work, child objects need to refer to the parent's id. This requires two preparatory changes: assigning reg->id when reading referenced kptrs from program context (patch 3), and preserving reg->id of pointer objects after null-check (patch 4). Previously, null-check would clear reg->id, making it impossible for children to reference the parent afterward. The latter causes a slight increase in verified states for some programs. One selftest object sees +19 states (+5.01%). For Meta BPF objects, the increase is also minor, with the largest being +34 states (+3.63%).
* Object relationship in different scenarios (for reference) *
The figures below show how the final design handles all four combinations of referenced/non-referenced dynptr with referenced/non-referenced parent.
(1) Non-referenced dynptr with referenced parent (e.g., skb in Qdisc):
skb (1',0)
^^
||
bpf_dynptr_from_skb |+------------------------------+
| bpf_dynptr_clone(A, C) |
dynptr A (2,1') dynptr C (4,1')
dynptr A and C live independently(2) Non-referenced dynptr with non-referenced parent (e.g., skb in TC, always valid):
bpf_dynptr_from_skb
bpf_dynptr_clone(A, C)
dynptr A (1,0) dynptr C (2,0)
dynptr A and C live independently
(3) Referenced dynptr with referenced parent:
file (1',0)
^
bpf_dynptr_from_file |
I (2',1') <-- intermediate reference
^^
||
|+-------------------------------+
| bpf_dynptr_clone(A, C) |
dynptr A (3,2') dynptr C (4,2')
dynptr A and C have the same lifetimeReleasing either dynptr releases I, invalidating both. Releasing file (1') detects I as a leaked reference.
(4) Referenced dynptr with non-referenced parent:
bpf_ringbuf_reserve_dynptr
I (1',0) <-- intermediate reference
^^
|| |+--------------------------------+
| bpf_dynptr_clone(A, C) |
dynptr A (2,1') dynptr C (3,1')
dynptr A and C have the same lifetime
[0] https://lore.kernel.org/bpf/[email protected]/
[1] https://github.com/ameryhung/bpf/commits/obj_relationship_v2_no_parent_id/
Changelog:
v5 -> v6
- Squash "bpf: Fold ref_obj_id into id and introduce virtual references" (v5 patch 9) into "bpf: Refactor object relationship tracking and fix dynptr UAF bug" (now patch 5). ref_obj_id is removed in the same patch that introduces parent_id, eliminating the intermediate state where both coexist (Eduard)
- Drop virtual references for pointer casting. Instead, cast results reuse the source pointer's id and use branch splitting to explore the NULL case as a separate verifier branch. This avoids adding virtual reference infrastructure for a case that can be handled more simply (Eduard, Andrii)
- Address nit from Eduard
v4 -> v5
- Add patch 9 folding ref_obj_id into id and introducing virtual references for pointer casting and referenced dynptr clones (Eduard, Andrii)
- Add patch 10 fixing dynptr ref counting to scan all call frames instead of only the current frame (Eduard)
- Add utility function validate_ref_obj() (Eduard)
v3 -> v4
- Add patch 1 clean up mark_stack_slot_obj_read() and callers (to address v3 ignoring err returned from mark_dynptr_read) (Andrii)
- Fix release_reference() and move the logic allowing destroying a referenced object when refcnt > 1 from destroy_if_stack_slots_dynptr() to release_reference() (Mykyta)
- Add patch 7 introducing ref_obj_desc and unifying ref_obj handling (to address Eduard's concern about unclear meta->{id,ref_obj_id} initialization/use and confusing function arguments of process_dynptr_func())
- Add patch 8 unifying release_regno handling so that bpf_kptr_xchg also use release_reference()
v2 -> v3
- Rebase to bpf-next/master
- Update veristat numbers
- Update commit msg to explain multiple dropped checks (Mykyta, Andrii)
- Reuse idmap as idstack in release_reference() and check for duplicate id (Mykyta, Andrii)
- Change to use RUN_TEST for qdisc dynptr selftest (Eduard)
v1 -> v2
- Redesign: Use object (id, ref_obj_id, parent_id) instead of (id, ref_obj_id) as it cannot express ptr casting without introducing specialized code to handle the case
- Use stack-based DFS to release objects to avoid recursion (Andrii)
- Keep reg->id after null check
- Add dynptr cleanup
- Fix dynptr kfunc arg type determination
- Add a file dynptr UAF selftest
---
Amery Hung (13):
bpf: Simplify mark_stack_slot_obj_read() and callers
bpf: Unify dynptr handling in the verifier
bpf: Assign reg->id when getting referenced kptr from ctx
bpf: Preserve reg->id of pointer objects after null-check
bpf: Refactor object relationship tracking and fix dynptr UAF bug
bpf: Remove redundant dynptr arg check for helper
bpf: Unify referenced object tracking in verifier
bpf: Unify release handling for helpers and kfuncs
bpf: Fix dynptr ref counting to scan all call frames selftests/bpf: Test creating dynptr from dynptr data and slice selftests/bpf: Test using slice after invalidating dynptr clone selftests/bpf: Test using file dynptr after the reference on file is
dropped
selftests/bpf: Test using dynptr after freeing the underlying object
include/linux/bpf.h | 4 +- include/linux/bpf_verifier.h | 100 +- kernel/bpf/btf.c | 2 +- kernel/bpf/fixups.c | 2 +- kernel/bpf/helpers.c | 2 +- kernel/bpf/log.c | 18 +- kernel/bpf/states.c | 11 +- kernel/bpf/verifier.c | 1068 +++++++---------- .../selftests/bpf/prog_tests/bpf_qdisc.c | 8 + .../selftests/bpf/prog_tests/cb_refs.c | 2 +- .../selftests/bpf/prog_tests/spin_lock.c | 4 +- ..._qdisc_dynptr_use_after_invalidate_clone.c | 74 ++ .../progs/bpf_qdisc_fail__invalid_dynptr.c | 68 ++ ...f_qdisc_fail__invalid_dynptr_cross_frame.c | 74 ++ .../bpf_qdisc_fail__invalid_dynptr_slice.c | 70 ++ .../selftests/bpf/progs/cgrp_kfunc_failure.c | 6 +- .../testing/selftests/bpf/progs/dynptr_fail.c | 52 +- .../selftests/bpf/progs/file_reader_fail.c | 60 + .../selftests/bpf/progs/iters_state_safety.c | 4 +- .../selftests/bpf/progs/iters_testmod_seq.c | 12 +- .../selftests/bpf/progs/map_kptr_fail.c | 2 +- .../selftests/bpf/progs/task_kfunc_failure.c | 6 +- .../bpf/progs/test_ringbuf_map_key.c | 11 +- .../selftests/bpf/progs/user_ringbuf_fail.c | 4 +- .../bpf/progs/verifier_global_ptr_args.c | 2 +- .../bpf/progs/verifier_ref_tracking.c | 2 +- .../selftests/bpf/progs/verifier_sock.c | 6 +- .../selftests/bpf/progs/verifier_vfs_reject.c | 2 +- .../selftests/bpf/progs/wakeup_source_fail.c | 2 +- tools/testing/selftests/bpf/verifier/calls.c | 24 - 30 files changed, 957 insertions(+), 745 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_dynptr_use_after_invalidate_clone.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr_cross_frame.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr_slice.c
Signature · 1 line
2.53.0-Meta
PATCH v6 1/13 bpf: Simplify mark_stack_slot_obj_read() and callers
Rename mark_stack_slot_obj_read() as mark_stack_slots_scratched() and directly call it from functions processing iter, dynptr and irq_flag. Commit 6762e3a0bce5 ("bpf: simplify liveness to use (callsite, depth) keyed func_instances") has removed the dynamic liveness component in mark_stack_slot_obj_read(). The function effectively only marks stack slots as scratched and always succeed. Therefore, return void, drop the unused bpf_reg_state argument and rename it to mark_stack_slots_scratched() to reflect what it does now.
In addition, to prepare for unifying dynptr handling, dynptr_get_spi() will be moved out of mark_dynptr_read(). As mark_dynptr_read() would join mark_iter_read() as a thin wrapper of mark_stack_slots_scratched(), just open code these helpers.
--- kernel/bpf/verifier.c | 69 +++++++++++++------------------------------ 1 file changed, 21 insertions(+), 48 deletions(-)
kernel/bpf/verifier.c +21 -48
@@ -3006,50 +3006,13 @@ static int sort_subprogs_topo(struct bpf_verifier_env *env)return ret; } -static int mark_stack_slot_obj_read (struct bpf_verifier_env *env,struct bpf_reg_state *reg, -int spi,int nr_slots) +static void mark_stack_slots_scratched (struct bpf_verifier_env *env, +int spi,int nr_slots) {int i;for (i =0 ; i < nr_slots; i++)mark_stack_slot_scratched (env, spi - i); -return 0 ; -} - -static int mark_dynptr_read (struct bpf_verifier_env *env,struct bpf_reg_state *reg) -{ -int spi; - -/* For CONST_PTR_TO_DYNPTR, it must have already been done by -* check_reg_arg in check_helper_call and mark_btf_func_reg_size in -* check_kfunc_call. -*/ -if (reg->type ==CONST_PTR_TO_DYNPTR ) -return 0 ; - spi =dynptr_get_spi (env, reg); -if (spi <0 ) -return spi; -/* Caller ensures dynptr is valid and initialized, which means spi is in -* bounds and spi is the first dynptr slot. Simply mark stack slot as -* read. -*/ -return mark_stack_slot_obj_read (env, reg, spi,BPF_DYNPTR_NR_SLOTS ); -} - -static int mark_iter_read (struct bpf_verifier_env *env,struct bpf_reg_state *reg, -int spi,int nr_slots) -{ -return mark_stack_slot_obj_read (env, reg, spi, nr_slots); -} - -static int mark_irq_flag_read (struct bpf_verifier_env *env,struct bpf_reg_state *reg) -{ -int spi; - - spi =irq_flag_get_spi (env, reg); -if (spi <0 ) -return spi; -return mark_stack_slot_obj_read (env, reg, spi,1 ); }/* This function is supposed to be used by the following 32-bit optimization
@@ -7255,7 +7218,7 @@ static int process_kptr_func(struct bpf_verifier_env *env, int regno,static int process_dynptr_func (struct bpf_verifier_env *env,struct bpf_reg_state *reg,argno_t argno,int insn_idx,enum bpf_arg_type arg_type,int clone_ref_obj_id) { -int err; +int spi, err =0 ;if (reg->type !=PTR_TO_STACK && reg->type !=CONST_PTR_TO_DYNPTR ) { verbose(env,
@@ -7317,7 +7280,17 @@ static int process_dynptr_func(struct bpf_verifier_env *env, struct bpf_reg_statreturn -EINVAL ; } - err =mark_dynptr_read (env, reg); +if (reg->type !=CONST_PTR_TO_DYNPTR ) { + spi =dynptr_get_spi (env, reg); +if (spi <0 ) +return spi; + +/* +* For CONST_PTR_TO_DYNPTR, reg is already scratched by check_reg_arg +* in check_helper_call and mark_btf_func_reg_size in check_kfunc_call. +*/ +mark_stack_slots_scratched (env, spi,BPF_DYNPTR_NR_SLOTS ); + } }return err; }
@@ -7427,9 +7400,7 @@ static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *if (spi <0 )return spi; - err =mark_iter_read (env, reg, spi, nr_slots); -if (err) -return err; +mark_stack_slots_scratched (env, spi, nr_slots);/* remember meta->iter info for process_iter_next_call() */ meta->iter.spi = spi;
@@ -11393,7 +11364,7 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env,static int process_irq_flag (struct bpf_verifier_env *env,struct bpf_reg_state *reg,argno_t argno,struct bpf_kfunc_call_arg_meta *meta) { -int err, kfunc_class =IRQ_NATIVE_KFUNC ; +int err, spi, kfunc_class =IRQ_NATIVE_KFUNC ;bool irq_save; if (meta->func_id == special_kfunc_list[KF_bpf_local_irq_save] ||
@@ -11434,9 +11405,11 @@ static int process_irq_flag(struct bpf_verifier_env *env, struct bpf_reg_state *return err; } - err =mark_irq_flag_read (env, reg); -if (err) -return err; + spi =irq_flag_get_spi (env, reg); +if (spi <0 ) +return spi; + +mark_stack_slots_scratched (env, spi,1 ); err =unmark_stack_slot_irq_flag (env, reg, kfunc_class);if (err)
Signature · 1 line
2.53.0-Meta
PATCH v6 2/13 bpf: Unify dynptr handling in the verifier
In reply to Amery HungSimplify dynptr checking for helper and kfunc by unifying it. Remember the initialized dynptr (i.e.,g !(arg_type |= MEM_UNINIT)) pass to a dynptr kfunc during process_dynptr_func() so that we can easily retrieve the information for verification later. By saving it in meta->dynptr, there is no need to call dynptr helpers such as dynptr_id(), dynptr_ref_obj_id() and dynptr_type() in check_func_arg().
Remove and open code the helpers in process_dynptr_func() when saving id, ref_obj_id, and type.
Besides, since dynptr ref_obj_id information is now pass around in meta->bpf_dynptr_desc, drop the check in helper_multiple_ref_obj_use.
--- include/linux/bpf_verifier.h | 13 ++- kernel/bpf/verifier.c | 178 +++++++---------------------------- 2 files changed, 40 insertions(+), 151 deletions(-)
include/linux/bpf_verifier.h +8 -5
@@ -1438,6 +1438,13 @@ struct bpf_map_desc {int uid; }; +/* The last initialized dynptr; Populated by process_dynptr_func() */ +struct bpf_dynptr_desc { +enum bpf_dynptr_type type; +u32 id; +u32 ref_obj_id; +}; +struct bpf_kfunc_call_arg_meta {/* In parameters */ struct btf *btf;
@@ -1478,16 +1485,12 @@ struct bpf_kfunc_call_arg_meta {struct {struct btf_field *field; } arg_rbtree_root; -struct { -enum bpf_dynptr_type type; -u32 id; -u32 ref_obj_id; - } initialized_dynptr;struct {u8 spi;u8 frameno; } iter;struct bpf_map_desc map; +struct bpf_dynptr_desc dynptr;u64 mem_size; };
kernel/bpf/verifier.c +32 -146
300 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v6 02/13] bpf: Unify dynptr handling in the verifier
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] bpf_dynptr_slice() and bpf_dynptr_slice_rdwr() do not assign a ref_obj_id to their returned slices, allowing use-after-free on refcounted dynptrs (e.g., ringbuf). --
commit eeb57bbf5794cf8b41c585dbed5238392c9e5bcd
Author: Amery Hung <[email protected]>
bpf: Unify dynptr handling in the verifier
This commit simplifies dynptr checking for helpers and kfuncs by unifying it. It remembers the initialized dynptr passed to a dynptr kfunc during process_dynptr_func(), saving it in meta->dynptr to avoid redundant helper calls in check_func_arg().
Quoted 3 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
Quoted 4 lines
kernel/bpf/verifier.c +0
-0@@ -12867,11 +12753,11 @@ static int check_special_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_ca } }
kernel/bpf/verifier.c static int check_special_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_ca · line 12763
Quoted 10 lines
kernel/bpf/verifier.c +2
-2-if (!meta->initialized_dynptr.id) { +if (!meta->dynptr.id) {verifier_bug (env,"no dynptr id" );return -EFAULT ; } - regs[BPF_REG_0 ].dynptr_id = meta->initialized_dynptr.id; + regs[BPF_REG_0 ].dynptr_id = meta->dynptr.id;/* we don't need to set BPF_REG_0's ref obj id * because packet slices are not refcounted (see
[Severity: Critical]
This is a pre-existing issue, but does this code leave slices of refcounted dynptrs vulnerable to a use-after-free?
When bpf_dynptr_slice() or bpf_dynptr_slice_rdwr() is called on a refcounted dynptr (like a ringbuf or file dynptr), the returned PTR_TO_MEM slice is assigned a dynptr_id, but not a ref_obj_id.
When the underlying dynptr is later released (for example, via bpf_ringbuf_discard_dynptr()), the verifier calls unmark_stack_slots_dynptr() which attempts to invalidate the associated slices by calling release_reference(env, ref_obj_id).
However, because the slice does not have its ref_obj_id populated here, release_reference() fails to find and invalidate the slice's register. This allows a BPF program to retain a valid pointer and safely read or write to the slice after the underlying memory has been freed.
I note this is fixed later in the series by commit 94d3da1c0d85d ("bpf:
Refactor object relationship tracking and fix dynptr UAF bug").
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH bpf-next v6 02/13] bpf: Unify dynptr handling in the verifier
In reply to Amery HungMykyta Yatsenko requested inline field comments for the ref_obj_id field in v2, noting it would help with clarity. While id and ref_obj_id are documented in struct bpf_reg_state earlier in the file…
Quoted 5 lines
include/linux/bpf_verifier.h +0
-0
include/linux/bpf_verifier.h struct bpf_map_desc { · line 1446
Quoted 9 lines
include/linux/bpf_verifier.h +6
-0@@ -1438,6 +1438,13 @@ struct bpf_map_desc {int uid; }; +/* The last initialized dynptr; Populated by process_dynptr_func() */ +struct bpf_dynptr_desc { +enum bpf_dynptr_type type; +u32 id; +u32 ref_obj_id; +};
Mykyta Yatsenko requested inline field comments for the ref_obj_id field in v2, noting it would help with clarity. While id and ref_obj_id are documented in struct bpf_reg_state earlier in the file, should inline comments be added here for consistency?
The CI bot also flagged this in v3 and v4, and it remains unaddressed in the final version.
Quoted 11 lines
include/linux/bpf_verifier.h +1
-3+struct bpf_kfunc_call_arg_meta {/* In parameters */ struct btf *btf;@@ -1478,16 +1485,12 @@ struct bpf_kfunc_call_arg_meta {struct {struct btf_field *field; } arg_rbtree_root; -struct { -enum bpf_dynptr_type type; -u32 id;
include/linux/bpf_verifier.h struct bpf_kfunc_call_arg_meta { · line 1495
Quoted 10 lines
include/linux/bpf_verifier.h +1
-2-u32 ref_obj_id; - } initialized_dynptr;struct {u8 spi;u8 frameno; } iter;struct bpf_map_desc map; +struct bpf_dynptr_desc dynptr;u64 mem_size; };
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26613892466
PATCH v6 3/13 bpf: Assign reg->id when getting referenced kptr from ctx
In reply to Amery HungAssign reg->id when getting referenced kptr from read program context to be consistent with R0 of KF_ACQUIRE kfunc. skb dynptr will track the referenced skb in qdisc programs using a new field reg->parent_id in a later patch.
--- kernel/bpf/verifier.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +3 -2
@@ -6208,8 +6208,6 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct b }else {mark_reg_known_zero (env, regs, value_regno); -if (type_may_be_null (info.reg_type)) - regs[value_regno].id = ++env->id_gen;/* A load of ctx field could have different * actual load size with the one encoded in the * insn. When the dst is PTR, it is for sure not
@@ -6219,8 +6217,11 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct bif (base_type (info.reg_type) ==PTR_TO_BTF_ID ) { regs[value_regno].btf = info.btf; regs[value_regno].btf_id = info.btf_id; + regs[value_regno].id = info.ref_obj_id; regs[value_regno].ref_obj_id = info.ref_obj_id; } +if (type_may_be_null (info.reg_type) && !regs[value_regno].id) + regs[value_regno].id = ++env->id_gen; } regs[value_regno].type = info.reg_type; }
Signature · 1 line
2.53.0-Meta
PATCH v6 4/13 bpf: Preserve reg->id of pointer objects after null-check
In reply to Amery HungPreserve reg->id of pointer objects after null-checking the register so that children objects derived from it can still refer to it in the new object relationship tracking mechanism introduced in a later patch. This change incurs a slight increase in the number of states in one selftest bpf object, rbtree_search.bpf.o. For Meta bpf objects, the increase of states is also negligible.
Selftest BPF objects with insns_diff > 0
Program Insns (A) Insns (B) Insns (DIFF) States (A) States (B) States (DIFF) ------------------------ --------- --------- -------------- ---------- ---------- -------------
rbtree_search 6820 7326 +506 (+7.42%) 379 398 +19 (+5.01%)
Meta BPF objects with insns_diff > 0
Program Insns (A) Insns (B) Insns (DIFF) States (A) States (B) States (DIFF) ------------------------ --------- --------- -------------- ---------- ---------- ------------- ned_imex_be_tclass 52 57 +5 (+9.62%) 5 6 +1 (+20.00%) ned_imex_be_tclass 52 57 +5 (+9.62%) 5 6 +1 (+20.00%) ned_skop_auto_flowlabel 523 526 +3 (+0.57%) 39 40 +1 (+2.56%) ned_skop_mss 289 292 +3 (+1.04%) 20 20 +0 (+0.00%) ned_skopt_bet_classifier 78 82 +4 (+5.13%) 8 8 +0 (+0.00%) dctcp_update_alpha 252 320 +68 (+26.98%) 21 27 +6 (+28.57%) dctcp_update_alpha 252 320 +68 (+26.98%) 21 27 +6 (+28.57%) ned_ts_func 119 126 +7 (+5.88%) 6 7 +1 (+16.67%) tw_egress 1119 1128 +9 (+0.80%) 95 96 +1 (+1.05%) tw_ingress 1128 1137 +9 (+0.80%) 95 96 +1 (+1.05%) tw_tproxy_router 4380 4465 +85 (+1.94%) 114 118 +4 (+3.51%) tw_tproxy_router4 3093 3170 +77 (+2.49%) 83 88 +5 (+6.02%) ttls_tc_ingress 34656 35717 +1061 (+3.06%) 936 970 +34 (+3.63%) tw_twfw_egress 222327 222338 +11 (+0.00%) 10563 10564 +1 (+0.01%) tw_twfw_ingress 78295 78299 +4 (+0.01%) 3825 3826 +1 (+0.03%) tw_twfw_tc_eg 222839 222859 +20 (+0.01%) 10584 10585 +1 (+0.01%) tw_twfw_tc_in 78295 78299 +4 (+0.01%) 3825 3826 +1 (+0.03%) tw_twfw_egress 8080 8085 +5 (+0.06%) 456 456 +0 (+0.00%) tw_twfw_ingress 8053 8056 +3 (+0.04%) 454 454 +0 (+0.00%) tw_twfw_tc_eg 8154 8174 +20 (+0.25%) 456 457 +1 (+0.22%) tw_twfw_tc_in 8060 8063 +3 (+0.04%) 455 455 +0 (+0.00%) tw_twfw_egress 222327 222338 +11 (+0.00%) 10563 10564 +1 (+0.01%) tw_twfw_ingress 78295 78299 +4 (+0.01%) 3825 3826 +1 (+0.03%) tw_twfw_tc_eg 222839 222859 +20 (+0.01%) 10584 10585 +1 (+0.01%) tw_twfw_tc_in 78295 78299 +4 (+0.01%) 3825 3826 +1 (+0.03%) tw_twfw_egress 8080 8085 +5 (+0.06%) 456 456 +0 (+0.00%) tw_twfw_ingress 8053 8056 +3 (+0.04%) 454 454 +0 (+0.00%) tw_twfw_tc_eg 8154 8174 +20 (+0.25%) 456 457 +1 (+0.22%) tw_twfw_tc_in 8060 8063 +3 (+0.04%) 455 455 +0 (+0.00%)
Looking into rbtree_search, the reason for such increase is that the verifier has to explore the main loop shown below for one more iteration until state pruning decides the current state is safe.
long rbtree_search(void *ctx)
{
...
bpf_spin_lock(&glock0);
rb_n = bpf_rbtree_root(&groot0);
while (can_loop) {
if (!rb_n) {
bpf_spin_unlock(&glock0);
return __LINE__;
}
n = rb_entry(rb_n, struct node_data, r0);
if (lookup_key == n->key0)
break;
if (nr_gc < NR_NODES)
gc_ns[nr_gc++] = rb_n;
if (lookup_key < n->key0)
rb_n = bpf_rbtree_left(&groot0, rb_n);
else
rb_n = bpf_rbtree_right(&groot0, rb_n);
}
...
}Below is what the verifier sees at the start of each iteration (65: may_goto) after preserving id of rb_n. Without id of rb_n, the verifier stops exploring the loop at iter 16.
rb_n gc_ns[15]
iter 15 257 257
iter 16 290 257 rb_n: idmap add 257->290
gc_ns[15]: check 257 != 290 --> state not equal
iter 17 325 257 rb_n: idmap add 290->325
gc_ns[15]: idmap add 257->257 --> state safe
--- kernel/bpf/verifier.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
kernel/bpf/verifier.c +4 -9
@@ -15570,15 +15570,10 @@ static void mark_ptr_or_null_reg(struct bpf_func_state *state,mark_ptr_not_null_reg (reg); -if (!reg_may_point_to_spin_lock (reg)) { -/* For not-NULL ptr, reg->ref_obj_id will be reset -* in release_reference(). -* -* reg->id is still used by spin_lock ptr. Other -* than spin_lock ptr type, reg->id can be reset. -*/ - reg->id =0 ; - } +/* +* reg->id is preserved for object relationship tracking +* and spin_lock lock state tracking +*/ } }
Signature · 1 line
2.53.0-Meta
PATCH v6 5/13 bpf: Refactor object relationship tracking and fix dynptr UAF bug
In reply to Amery HungRefactor object relationship tracking in the verifier and fix a dynptr use-after-free bug where file/skb dynptrs are not invalidated when the parent referenced object is freed.
Add parent_id to bpf_reg_state to precisely track child-parent relationships. A child object's parent_id points to the parent object's id. This replaces the PTR_TO_MEM-specific dynptr_id.
Remove ref_obj_id from bpf_reg_state by folding its role into the existing id field. Previously, id tracked pointer identity for null checking while ref_obj_id tracked the owning reference for lifetime management. These are now unified: acquire helpers and kfuncs set id to the acquired reference id, and release paths use id directly.
Add reg_is_referenced() which checks if a register is referenced by looking up its id in the reference array. This replaces all former ref_obj_id checks.
For release_reference(), invalidating an object now also invalidates all descendants by traversing the object tree. This is done using stack-based DFS to avoid recursive call chains of release_reference() -> unmark_stack_slots_dynptr() -> release_reference(). Referenced objects encountered during tree traversal are reported as leaked references.
Add parent_id to bpf_reference_state to enable hierarchical reference tracking. When acquiring a reference, a parent_id can be specified to link the new reference to an existing one (e.g., referenced dynptrs acquire a reference with parent_id linking to the parent object's reference).
Pointer casting:
For pointer casting helpers (bpf_sk_fullsock, bpf_tcp_sock), instead of propagating ref_obj_id, the cast result reuses the same reference id as the source pointer. Since the cast may return NULL for a non-NULL input, the NULL case is explored as a separate verifier branch. This allows releasing any of the original or cast pointers to invalidate all others.
Referenced dynptrs:
When constructing a referenced dynptr, acquire a intermediate reference with parent_id linking to the parent referenced object. The dynptr and all clones share the same parent_id (pointing to the intermediate ref) but get unique ids for independent slice tracking. Releasing a referenced dynptr releases the parent reference, which in turn invalidates all clones and their derived slices.
Owning to non-owning reference conversion:
After converting owning to non-owning by clearing id (e.g., object(id=1) -> object(id=0)), the verifier releases the reference state via release_reference_nomark().
Note that the error message "reference has not been acquired before" in the helper and kfunc release paths is removed. This message was already unreachable. The verifier only calls release_reference() after confirming the reference is valid, so the condition could never trigger in practice.
--- include/linux/bpf.h | 4 +- include/linux/bpf_verifier.h | 77 +-- kernel/bpf/btf.c | 2 +- kernel/bpf/fixups.c | 2 +- kernel/bpf/log.c | 18 +- kernel/bpf/states.c | 11 +- kernel/bpf/verifier.c | 560 +++++++++--------- .../selftests/bpf/prog_tests/spin_lock.c | 4 +- .../testing/selftests/bpf/progs/dynptr_fail.c | 4 +- .../selftests/bpf/progs/iters_state_safety.c | 4 +- .../selftests/bpf/progs/iters_testmod_seq.c | 12 +- 11 files changed, 338 insertions(+), 360 deletions(-)
include/linux/bpf.h +2 -2
@@ -1062,7 +1062,7 @@ struct bpf_insn_access_aux {struct {struct btf *btf;u32 btf_id; -u32 ref_obj_id; +u32 ref_id; }; };struct bpf_verifier_log *log;/* for verbose logs */
@@ -1631,7 +1631,7 @@ struct bpf_ctx_arg_aux {enum bpf_reg_type reg_type;struct btf *btf;u32 btf_id; -u32 ref_obj_id; +u32 ref_id;bool refcounted; };
include/linux/bpf_verifier.h +28 -49
134 lines not on this page · raw message
kernel/bpf/btf.c +1 -1
@@ -6957,7 +6957,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, info->reg_type = ctx_arg_info->reg_type; info->btf = ctx_arg_info->btf ? : btf_vmlinux; info->btf_id = ctx_arg_info->btf_id; - info->ref_obj_id = ctx_arg_info->ref_obj_id; + info->ref_id = ctx_arg_info->ref_id;return true; } }
kernel/bpf/fixups.c +1 -1
@@ -870,7 +870,7 @@ int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)case PTR_TO_BTF_ID :case PTR_TO_BTF_ID |PTR_UNTRUSTED :/* PTR_TO_BTF_ID | MEM_ALLOC always has a valid lifetime, unlike -* PTR_TO_BTF_ID, and an active ref_obj_id, but the same cannot +* PTR_TO_BTF_ID, and an active referenced id, but the same cannot * be said once it is marked PTR_UNTRUSTED, hence we must handle * any faults for loads into such types. BPF_WRITE is disallowed * for this case.
kernel/bpf/log.c +8 -10
@@ -665,8 +665,8 @@ static void print_reg_state(struct bpf_verifier_env *env,verbose_a ("id=%d" , reg->id & ~BPF_ADD_CONST );if (reg->id &BPF_ADD_CONST )verbose (env,"%+d" , reg->delta); -if (reg->ref_obj_id) -verbose_a ("ref_obj_id=%d" , reg->ref_obj_id); +if (reg->parent_id) +verbose_a ("parent_id=%d" , reg->parent_id);if (type_is_non_owning_ref (reg->type))verbose_a ("%s" ,"non_own_ref" );if (type_is_map_ptr (t)) {
@@ -768,21 +768,19 @@ void print_verifier_state(struct bpf_verifier_env *env, const struct bpf_verifieverbose (env,"=dynptr_%s(" ,dynptr_type_str (reg->dynptr.type));if (reg->id)verbose_a ("id=%d" , reg->id); -if (reg->ref_obj_id) -verbose_a ("ref_id=%d" , reg->ref_obj_id); -if (reg->dynptr_id) -verbose_a ("dynptr_id=%d" , reg->dynptr_id); +if (reg->parent_id) +verbose_a ("parent_id=%d" , reg->parent_id);verbose (env,")" );break ;case STACK_ITER : -/* only main slot has ref_obj_id set; skip others */ -if (!reg->ref_obj_id) +/* only main slot has id set; skip others */ +if (!reg->id)continue ; -verbose (env," fp%d=iter_%s(ref_id=%d,state=%s,depth=%u)" , +verbose (env," fp%d=iter_%s(id=%d,state=%s,depth=%u)" , (-i -1 ) *BPF_REG_SIZE ,iter_type_str (reg->iter.btf, reg->iter.btf_id), - reg->ref_obj_id,iter_state_str (reg->iter.state), + reg->id,iter_state_str (reg->iter.state), reg->iter.depth);break ;case STACK_MISC :
kernel/bpf/states.c +6 -5
@@ -489,7 +489,7 @@ static bool regs_exact(const struct bpf_reg_state *rold, {return memcmp (rold, rcur, offsetof(struct bpf_reg_state , id)) ==0 &&check_ids (rold->id, rcur->id, idmap) && -check_ids (rold->ref_obj_id, rcur->ref_obj_id, idmap); +check_ids (rold->parent_id, rcur->parent_id, idmap); }enum exact_level {
@@ -614,7 +614,7 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,range_within (rold, rcur) &&tnum_in (rold->var_off, rcur->var_off) &&check_ids (rold->id, rcur->id, idmap) && -check_ids (rold->ref_obj_id, rcur->ref_obj_id, idmap); +check_ids (rold->parent_id, rcur->parent_id, idmap);case PTR_TO_PACKET_META :case PTR_TO_PACKET :/* We must have at least as much range as the old ptr
@@ -794,7 +794,8 @@ static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old, cur_reg = &cur->stack[spi].spilled_ptr;if (old_reg->dynptr.type != cur_reg->dynptr.type || old_reg->dynptr.first_slot != cur_reg->dynptr.first_slot || - !check_ids (old_reg->ref_obj_id, cur_reg->ref_obj_id, idmap)) + !check_ids (old_reg->id, cur_reg->id, idmap) || + !check_ids (old_reg->parent_id, cur_reg->parent_id, idmap))return false;break ;case STACK_ITER :
@@ -810,13 +811,13 @@ static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old, old_reg->iter.btf_id != cur_reg->iter.btf_id || old_reg->iter.state != cur_reg->iter.state ||/* ignore {old_reg,cur_reg}->iter.depth, see above */ - !check_ids(old_reg->ref_obj_id, cur_reg->ref_obj_id, idmap)) + !check_ids(old_reg->id, cur_reg->id, idmap)) return false;break ;case STACK_IRQ_FLAG : old_reg = &old->stack[spi].spilled_ptr; cur_reg = &cur->stack[spi].spilled_ptr; -if (!check_ids (old_reg->ref_obj_id, cur_reg->ref_obj_id, idmap) || +if (!check_ids (old_reg->id, cur_reg->id, idmap) || old_reg->irq.kfunc_class != cur_reg->irq.kfunc_class)return false;break ;
kernel/bpf/verifier.c +280 -280
1,147 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/spin_lock.c +2 -2
@@ -13,8 +13,8 @@ static struct {const char *err_msg; } spin_lock_fail_tests[] = { {"lock_id_kptr_preserve" , -"[0-9]\\+: (bf) r1 = r0 ; R0=ptr_foo(id=2,ref_obj_id=2)" -" R1=ptr_foo(id=2,ref_obj_id=2) refs=2\n" +"[0-9]\\+: (bf) r1 = r0 ; R0=ptr_foo(id=2)" +" R1=ptr_foo(id=2) refs=2\n" "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n" "R1 type=ptr_ expected=percpu_ptr_" }, { "lock_id_global_zero",
tools/testing/selftests/bpf/progs/dynptr_fail.c +2 -2
@@ -78,7 +78,7 @@ static int get_map_val_dynptr(struct bpf_dynptr *ptr)* bpf_ringbuf_submit/discard_dynptr call */ SEC("?raw_tp") -__failure __msg("Unreleased reference id=2") +__failure __msg("Unreleased reference id=1")int ringbuf_missing_release1 (void *ctx) {struct bpf_dynptr ptr = {};
@@ -91,7 +91,7 @@ int ringbuf_missing_release1(void *ctx) } SEC("?raw_tp") -__failure __msg("Unreleased reference id=4") +__failure __msg("Unreleased reference id=3") int ringbuf_missing_release2(void *ctx) {struct bpf_dynptr ptr1, ptr2;
tools/testing/selftests/bpf/progs/iters_state_safety.c +2 -2
@@ -30,7 +30,7 @@ int force_clang_to_emit_btf_for_externs(void *ctx) SEC("?raw_tp") __success __log_level(2) -__msg("fp-8=iter_num(ref_id=1,state=active,depth=0)") +__msg("fp-8=iter_num(id=1,state=active,depth=0)")int create_and_destroy (void *ctx) {struct bpf_iter_num iter;
@@ -196,7 +196,7 @@ int leak_iter_from_subprog_fail(void *ctx) SEC("?raw_tp") __success __log_level(2) -__msg("fp-8=iter_num(ref_id=1,state=active,depth=0)") +__msg("fp-8=iter_num(id=1,state=active,depth=0)")int valid_stack_reuse (void *ctx) {struct bpf_iter_num iter;
tools/testing/selftests/bpf/progs/iters_testmod_seq.c +6 -6
@@ -20,8 +20,8 @@ __s64 res_empty; SEC("raw_tp/sys_enter") __success __log_level(2) -__msg("fp-16=iter_testmod_seq(ref_id=1,state=active,depth=0)") -__msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)") +__msg("fp-16=iter_testmod_seq(id=1,state=active,depth=0)") +__msg("fp-16=iter_testmod_seq(id=1,state=drained,depth=0)") __msg("call bpf_iter_testmod_seq_destroy")int testmod_seq_empty (const void *ctx) {
@@ -38,8 +38,8 @@ __s64 res_full; SEC("raw_tp/sys_enter") __success __log_level(2) -__msg("fp-16=iter_testmod_seq(ref_id=1,state=active,depth=0)") -__msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)") +__msg("fp-16=iter_testmod_seq(id=1,state=active,depth=0)") +__msg("fp-16=iter_testmod_seq(id=1,state=drained,depth=0)") __msg("call bpf_iter_testmod_seq_destroy")int testmod_seq_full (const void *ctx) {
@@ -58,8 +58,8 @@ static volatile int zero = 0; SEC("raw_tp/sys_enter") __success __log_level(2) -__msg("fp-16=iter_testmod_seq(ref_id=1,state=active,depth=0)") -__msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)") +__msg("fp-16=iter_testmod_seq(id=1,state=active,depth=0)") +__msg("fp-16=iter_testmod_seq(id=1,state=drained,depth=0)") __msg("call bpf_iter_testmod_seq_destroy")int testmod_seq_truncated (const void *ctx) {
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v6 05/13] bpf: Refactor object relationship tracking and fix dynptr UAF bug
Should this path invalidate the dangling child references and continue rather than returning -EINVAL immediately?
Quoted 3 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
Quoted 1 line
kernel/bpf/verifier.c +0
-0@@ -8907,26 +8878,83 @@ static int release_reference_nomark(struct bpf_verifier_state *state, int ref_ob
[ ... ]
Quoted 3 lines
kernel/bpf/verifier.c +3
-0+/* Release id and objects derived from it iteratively in a DFS manner */ +static int release_reference (struct bpf_verifier_env *env,int id) +{
[ ... ]
Quoted 4 lines
kernel/bpf/verifier.c +4
-0+while ((id =idstack_pop (idstack))) { +/* +* Child references are inaccessible after parent is released, +* any child references that exist at this point are a leak.
kernel/bpf/verifier.c static int release_reference_nomark(struct bpf_verifier_state *state, int ref_ob · line 8939
Quoted 10 lines
kernel/bpf/verifier.c +10
-0+*/ +for (i =0 ; i < vstate->acquired_refs; i++) { +if (vstate->refs[i].type !=REF_TYPE_PTR ) +continue ; +if (vstate->refs[i].parent_id != id) +continue ; +verbose (env,"Leaking reference id=%d alloc_insn=%d. Release it first.\n" , + vstate->refs[i].id, vstate->refs[i].insn_idx); +return -EINVAL ; + }
Should this path invalidate the dangling child references and continue rather than returning -EINVAL immediately?
Eduard Zingerman raised this in the v5 discussion:
Thinking some more about it, the mere presence of dangling objects with the same lifetime is not an error. The error would happen if such objects are accessed. Should the verifier invalidate such dangling objects instead of signaling an error immediately?
The current code returns -EINVAL as soon as it finds a child reference whose parent_id still points at the released parent. Would invalidating those child references instead of rejecting allow programs that never access the dangling objects to verify?
Reference: https://lore.kernel.org/bpf/[email protected]/
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26613892466
Re: [PATCH bpf-next v6 05/13] bpf: Refactor object relationship tracking and fix dynptr UAF bug
In reply to Amery HungOn Thu, 2026-05-28 at 18:49 -0700, Amery Hung wrote:
I think refsafe() needs an update.
[...]
kernel/bpf/states.c
Quoted 4 lines
kernel/bpf/states.c +0
-0
I think refsafe() needs an update as well.
Something like:
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -886,6 +886,7 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c
for (i = 0; i < old->acquired_refs; i++) {
if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap) ||
+ !check_ids(old->refs[i].parent_id, cur->refs[i].parent_id, idmap) ||
old->refs[i].type != cur->refs[i].type)
return false;
switch (old->refs[i].type) {Wdyt?
[...]
Re: [PATCH bpf-next v6 05/13] bpf: Refactor object relationship tracking and fix dynptr UAF bug
Quoted 28 lines · Eduard Zingerman
On Thu, 2026-05-28 at 18:49 -0700, Amery Hung wrote:
I think
refsafe()needs an update.Acked-by Eduard Zingerman <[email protected]>[...]
kernel/bpf/states.c
Quoted 4 lines
kernel/bpf/states.c +0
-0I think
refsafe()needs an update as well.
Something like:--- a/kernel/bpf/states.c +++ b/kernel/bpf/states.c @@ -886,6 +886,7 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c for (i = 0; i < old->acquired_refs; i++) { if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap) || + !check_ids(old->refs[i].parent_id, cur->refs[i].parent_id, idmap) || old->refs[i].type != cur->refs[i].type) return false; switch (old->refs[i].type) {
Quoted 1 line
Wdyt?
You are right. It needs to compare parent_id, but maybe only for REF_TYPE_PTR like below.
for (i = 0; i < old->acquired_refs; i++) {
if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap) ||
old->refs[i].type != cur->refs[i].type)
return false;
switch (old->refs[i].type) {
- case REF_TYPE_PTR:
case REF_TYPE_IRQ:
break;+ case REF_TYPE_PTR:
+ if (old->refs[i].parent_id != cur->refs[i].parent_id)
+ return false;
+ break;
Quoted 2 lines
[...]
Eduard Zingerman
maintainerRe: [PATCH bpf-next v6 05/13] bpf: Refactor object relationship tracking and fix dynptr UAF bug
Quoted 29 lines · Amery Hung
Quoted 28 lines · Eduard Zingerman
On Thu, 2026-05-28 at 18:49 -0700, Amery Hung wrote:
I think
refsafe()needs an update.Acked-by Eduard Zingerman <[email protected]>[...]
kernel/bpf/states.c
Quoted 4 lines
kernel/bpf/states.c +0
-0I think
refsafe()needs an update as well.
Something like:--- a/kernel/bpf/states.c +++ b/kernel/bpf/states.c @@ -886,6 +886,7 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c for (i = 0; i < old->acquired_refs; i++) { if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap) || + !check_ids(old->refs[i].parent_id, cur->refs[i].parent_id, idmap) || old->refs[i].type != cur->refs[i].type) return false; switch (old->refs[i].type) {
Quoted 4 lines
Quoted 1 line
Wdyt?
You are right. It needs to compare
parent_id, but maybe only forREF_TYPE_PTRlike below.
check_ids() should handle the case when parent_id is zero correctly, so I think both variants are fine.
Quoted 16 lines
for (i = 0; i < old->acquired_refs; i++) { if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap) || old->refs[i].type != cur->refs[i].type) return false; switch (old->refs[i].type) {(quoted diff) +4
-1- case REF_TYPE_PTR: case REF_TYPE_IRQ: break; + case REF_TYPE_PTR: + if (old->refs[i].parent_id != cur->refs[i].parent_id) + return false; + break;Quoted 4 lines
[...]
Re: [PATCH bpf-next v6 05/13] bpf: Refactor object relationship tracking and fix dynptr UAF bug
Quoted 31 lines · Eduard Zingerman
Quoted 29 lines · Amery Hung
Quoted 28 lines · Eduard Zingerman
On Thu, 2026-05-28 at 18:49 -0700, Amery Hung wrote:
I think
refsafe()needs an update.Acked-by Eduard Zingerman <[email protected]>[...]
kernel/bpf/states.c
Quoted 4 lines
kernel/bpf/states.c +0
-0I think
refsafe()needs an update as well.
Something like:--- a/kernel/bpf/states.c +++ b/kernel/bpf/states.c @@ -886,6 +886,7 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c for (i = 0; i < old->acquired_refs; i++) { if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap) || + !check_ids(old->refs[i].parent_id, cur->refs[i].parent_id, idmap) || old->refs[i].type != cur->refs[i].type) return false; switch (old->refs[i].type) {
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Wdyt?
You are right. It needs to compare
parent_id, but maybe only forREF_TYPE_PTRlike below.
check_ids()should handle the case whenparent_idis zero correctly, so I think both variants are fine.
if that's the only thing, maybe let's do it in the follow up?
Eduard,
are you Ack-ing the whole set?
Eduard Zingerman
maintainerRe: [PATCH bpf-next v6 05/13] bpf: Refactor object relationship tracking and fix dynptr UAF bug
Quoted 37 lines · Alexei Starovoitov
Quoted 36 lines · Eduard Zingerman
Quoted 33 lines · Amery Hung
Quoted 28 lines · Eduard Zingerman
On Thu, 2026-05-28 at 18:49 -0700, Amery Hung wrote:
I think
refsafe()needs an update.Acked-by Eduard Zingerman <[email protected]>[...]
kernel/bpf/states.c
Quoted 4 lines
kernel/bpf/states.c +0
-0I think
refsafe()needs an update as well.
Something like:--- a/kernel/bpf/states.c +++ b/kernel/bpf/states.c @@ -886,6 +886,7 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c for (i = 0; i < old->acquired_refs; i++) { if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap) || + !check_ids(old->refs[i].parent_id, cur->refs[i].parent_id, idmap) || old->refs[i].type != cur->refs[i].type) return false; switch (old->refs[i].type) {Quoted 1 line
Wdyt?
You are right. It needs to compare
parent_id, but maybe only forREF_TYPE_PTRlike below.
Quoted 7 lines
Quoted 2 lines
check_ids()should handle the case whenparent_idis zero correctly, so I think both variants are fine.if that's the only thing, maybe let's do it in the follow up?
Eduard,
are you Ack-ing the whole set?
Yes, I think this set is safe to land.
(Note that there was also a nit from Mykyta, can be a follow-up as well).
PATCH v6 6/13 bpf: Remove redundant dynptr arg check for helper
In reply to Amery Hungunmark_stack_slots_dynptr() already makes sure that CONST_PTR_TO_DYNPTR cannot be released. process_dynptr_func() also prevents passing uninitialized dynptr to helpers expecting initialized dynptr. Now that unmark_stack_slots_dynptr() also reports error returned from release_reference(), there should be no reason to keep these redundant checks.
--- kernel/bpf/verifier.c | 21 +------------------ .../testing/selftests/bpf/progs/dynptr_fail.c | 6 +++--- .../selftests/bpf/progs/user_ringbuf_fail.c | 4 ++-- 3 files changed, 6 insertions(+), 25 deletions(-)
kernel/bpf/verifier.c +1 -20
@@ -8214,26 +8214,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, skip_type_check:if (arg_type_is_release (arg_type)) { -if (arg_type_is_dynptr (arg_type)) { -struct bpf_func_state *state =bpf_func (env, reg); -int spi; - -/* Only dynptr created on stack can be released, thus -* the get_spi and stack state checks for spilled_ptr -* should only be done before process_dynptr_func for -* PTR_TO_STACK. -*/ -if (reg->type ==PTR_TO_STACK ) { - spi =dynptr_get_spi (env, reg); -if (spi <0 || !state->stack[spi].spilled_ptr.id) { -verbose (env,"arg %d is an unacquired reference\n" , regno); -return -EINVAL ; - } - }else { -verbose (env,"cannot release unowned const bpf_dynptr\n" ); -return -EINVAL ; - } - }else if (!reg_is_referenced (env, reg) && !bpf_register_is_null (reg)) { +if (!arg_type_is_dynptr (arg_type) && !reg_is_referenced (env, reg) && !bpf_register_is_null (reg)) {verbose (env,"R%d must be referenced when passed to release function\n" , regno);return -EINVAL ;
tools/testing/selftests/bpf/progs/dynptr_fail.c +3 -3
@@ -136,7 +136,7 @@ int ringbuf_missing_release_callback(void *ctx)/* Can't call bpf_ringbuf_submit/discard_dynptr on a non-initialized dynptr */ SEC("?raw_tp") -__failure __msg("arg 1 is an unacquired reference") +__failure __msg("Expected an initialized dynptr as R1")int ringbuf_release_uninit_dynptr (void *ctx) {struct bpf_dynptr ptr;
@@ -650,7 +650,7 @@ int invalid_offset(void *ctx)/* Can't release a dynptr twice */ SEC("?raw_tp") -__failure __msg("arg 1 is an unacquired reference") +__failure __msg("Expected an initialized dynptr as R1")int release_twice (void *ctx) {struct bpf_dynptr ptr;
@@ -677,7 +677,7 @@ static int release_twice_callback_fn(__u32 index, void *data)* within a callback function, fails */ SEC("?raw_tp") -__failure __msg("arg 1 is an unacquired reference") +__failure __msg("Expected an initialized dynptr as R1")int release_twice_callback (void *ctx) {struct bpf_dynptr ptr;
tools/testing/selftests/bpf/progs/user_ringbuf_fail.c +2 -2
@@ -146,7 +146,7 @@ try_discard_dynptr(struct bpf_dynptr *dynptr, void *context)* not be able to read past the end of the pointer. */ SEC("?raw_tp") -__failure __msg("cannot release unowned const bpf_dynptr") +__failure __msg("CONST_PTR_TO_DYNPTR cannot be released")int user_ringbuf_callback_discard_dynptr (void *ctx) {bpf_user_ringbuf_drain (&user_ringbuf, try_discard_dynptr,NULL ,0 );
@@ -166,7 +166,7 @@ try_submit_dynptr(struct bpf_dynptr *dynptr, void *context)* not be able to read past the end of the pointer. */ SEC("?raw_tp") -__failure __msg("cannot release unowned const bpf_dynptr") +__failure __msg("CONST_PTR_TO_DYNPTR cannot be released")int user_ringbuf_callback_submit_dynptr (void *ctx) {bpf_user_ringbuf_drain (&user_ringbuf, try_submit_dynptr,NULL ,0 );
Signature · 1 line
2.53.0-Meta
PATCH v6 7/13 bpf: Unify referenced object tracking in verifier
In reply to Amery HungHelpers and kfuncs independently tracked referenced object metadata using standalone id fields in their respective arg_meta structs. This led to duplicated logic and inconsistent error handling between the two paths.
Introduce struct ref_obj_desc to consolidate id and parent_id along with a count of how many arguments carry a reference. Add update_ref_obj() to populate it from a bpf_reg_state, replacing open-coded assignments in check_func_arg(), check_kfunc_args(), and process_iter_arg(). Add validate_ref_obj() to check for ambiguous ref_obj before using it.
For ref_obj releasing helpers and kfuncs, keep checking it before calling update_ref_obj() for now. A later patch will make these functions not depending on ref_obj. For other users of ref_obj, move the checks to the use locations. For helper, this means moving the checks inside helper_multiple_ref_obj_use() to use locations. is_acquire_function() is dropped as ref_obj is never used.
Pass ref_obj_desc into process_dynptr_func()/mark_stack_slots_dynptr() instead of a bare parent_id to make it less confusing.
Drop the selftest introduced in 7ec899ac90a2 ("selftests/bpf: Negative test case for ref_obj_id in args") since the verifier no longer complains about ambiguous ref_obj if it is not used.
--- include/linux/bpf_verifier.h | 14 +- kernel/bpf/verifier.c | 122 +++++++++--------- .../bpf/progs/test_ringbuf_map_key.c | 11 +- tools/testing/selftests/bpf/verifier/calls.c | 24 ---- 4 files changed, 78 insertions(+), 93 deletions(-)
include/linux/bpf_verifier.h +13 -1
@@ -1424,6 +1424,18 @@ struct bpf_dynptr_desc {u32 parent_id; }; +/* +* The last seen rereferenced object; Updated by update_ref_obj() when a register refers to a +* referenced object. Used when the helper or kfunc is releasing a referenced object, casting +* a referenced object, returning allocated memory derived from referenced object or creating +* a dynptr with a referenced object as parent. +*/ +struct ref_obj_desc { +u32 id; +u32 parent_id; +u8 cnt; +}; +struct bpf_kfunc_call_arg_meta {/* In parameters */ struct btf *btf;
@@ -1432,7 +1444,6 @@ struct bpf_kfunc_call_arg_meta {const struct btf_type *func_proto;const char *func_name;/* Out parameters */ -u32 id;u8 release_regno;bool r0_rdonly;u32 ret_btf_id;
@@ -1470,6 +1481,7 @@ struct bpf_kfunc_call_arg_meta { } iter;struct bpf_map_desc map;struct bpf_dynptr_desc dynptr; +struct ref_obj_desc ref_obj;u64 mem_size; };
kernel/bpf/verifier.c +62 -60
266 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_ringbuf_map_key.c +3 -8
@@ -35,7 +35,7 @@ SEC("fentry/" SYS_PREFIX "sys_getpgid")int test_ringbuf_mem_map_key (void *ctx) {int cur_pid =bpf_get_current_pid_tgid () >>32 ; -struct sample *sample, sample_copy; +struct sample *sample;int *lookup_val;if (cur_pid != pid)
@@ -55,16 +55,11 @@ int test_ringbuf_mem_map_key(void *ctx) lookup_val = (int *)bpf_map_lookup_elem (&hash_map, sample);__sink (lookup_val); -/* workaround - memcpy is necessary so that verifier doesn't -* complain with: -* verifier internal error: more than one arg with ref_obj_id R3 -* when trying to do bpf_map_update_elem(&hash_map, sample, &sample->seq, BPF_ANY); -* +/* * Since bpf_map_lookup_elem above uses 'sample' as key, test using * sample field as value below */ -__builtin_memcpy (&sample_copy, sample,sizeof (struct sample )); -bpf_map_update_elem (&hash_map, &sample_copy, &sample->seq,BPF_ANY ); +bpf_map_update_elem (&hash_map, sample, &sample->seq,BPF_ANY );bpf_ringbuf_submit (sample,0 );return 0 ;
tools/testing/selftests/bpf/verifier/calls.c +0 -24
@@ -2410,27 +2410,3 @@ .errstr_unpriv = "", .prog_type = BPF_PROG_TYPE_CGROUP_SKB, }, -{ - "calls: several args with ref_obj_id", - .insns = { -/* Reserve at least sizeof(struct iphdr) bytes in the ring buffer. -* With a smaller size, the verifier would reject the call to -* bpf_tcp_raw_gen_syncookie_ipv4 before we can reach the -* ref_obj_id error. -*/ -BPF_MOV64_IMM (BPF_REG_2 ,20 ), -BPF_MOV64_IMM (BPF_REG_3 ,0 ), -BPF_LD_MAP_FD (BPF_REG_1 ,0 ), -BPF_RAW_INSN (BPF_JMP |BPF_CALL ,0 ,0 ,0 , BPF_FUNC_ringbuf_reserve), -/* if r0 == 0 goto <exit> */ -BPF_JMP_IMM (BPF_JEQ ,BPF_REG_0 ,0 ,3 ), -BPF_MOV64_REG (BPF_REG_1 ,BPF_REG_0 ), -BPF_MOV64_REG (BPF_REG_2 ,BPF_REG_0 ), -BPF_RAW_INSN (BPF_JMP |BPF_CALL ,0 ,0 ,0 , BPF_FUNC_tcp_raw_gen_syncookie_ipv4), - BPF_EXIT_INSN(), - }, - .fixup_map_ringbuf = { 2 }, - .result = REJECT, - .errstr = "more than one arg with ref_obj_id", - .prog_type = BPF_PROG_TYPE_SCHED_CLS, -},
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v6 07/13] bpf: Unify referenced object tracking in verifier
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing validation for multiple referenced objects in BPF helper release paths causes incorrect…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing validation for multiple referenced objects in BPF helper release paths causes incorrect reference releasing and memory leaks. --
commit 1ad7c42ef2c2cadcc679c403e24d66c882bd0438
Author: Amery Hung <[email protected]>
bpf: Unify referenced object tracking in verifier
This commit unifies referenced object tracking in the verifier by replacing standalone id fields with a consolidated ref_obj_desc struct. It introduces update_ref_obj() to populate the struct from bpf_reg_state, replacing open-coded assignments in functions like check_func_arg() and check_helper_call().
Quoted 4 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
Quoted 17 lines
kernel/bpf/verifier.c +2
-9@@ -8226,15 +8232,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, meta->release_regno = regno; } -if (reg_is_referenced (env, reg) &&base_type (arg_type) !=ARG_KPTR_XCHG_DEST ) { -if (meta->id) { -verbose (env,"more than one arg with referenced id R%d %u %u" , - regno, reg->id, - meta->id); -return -EACCES ; - } - meta->id = reg->id; - } +if (reg_is_referenced (env, reg)) +update_ref_obj (&meta->ref_obj, reg);switch (base_type (arg_type)) {
[ ... ]
kernel/bpf/verifier.c static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn · line 10123
Quoted 8 lines
kernel/bpf/verifier.c +2
-2@@ -10119,8 +10119,8 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn err = -EINVAL ;if (arg_type_is_dynptr (fn->arg_type[meta.release_regno -BPF_REG_1 ])) { err =unmark_stack_slots_dynptr (env, ®s[meta.release_regno]); - }else if (func_id == BPF_FUNC_kptr_xchg && meta.id) { -u32 id = meta.id; + }else if (func_id == BPF_FUNC_kptr_xchg && meta.ref_obj.id) { +u32 id = meta.ref_obj.id;
[Severity: High]
Does this code inadvertently cause memory leaks when bpf_kptr_xchg() is called with NULL as the second argument?
Because ARG_KPTR_XCHG_DEST is no longer excluded in check_func_arg(), the first argument (map_value) will populate meta.ref_obj.id if it is a referenced object.
When the second argument (ptr) is NULL, it isn't referenced, so update_ref_obj() isn't called for it. As a result, meta.ref_obj.id holds the ID of the first argument, and the verifier incorrectly releases it from the reference state.
At runtime, the helper merely exchanges NULL into the kptr field and does not free the map_value object. However, because the verifier considers it released, the BPF program cannot explicitly free it later, leading to a forced memory leak of the allocated kernel object.
I noticed this issue was fixed later in the patch series in commit a23fc3d5455bd ("bpf: Unify release handling for helpers and kfuncs").
Quoted 3 lines
kernel/bpf/verifier.c +0
-0bool in_rcu =in_rcu_cs (env);struct bpf_func_state *state;struct bpf_reg_state *reg;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH bpf-next v6 07/13] bpf: Unify referenced object tracking in verifier
In reply to Amery HungThis isn't a bug, but there's a typo in the comment: 'rereferenced' should read 'referenced'.
Quoted 5 lines
include/linux/bpf_verifier.h +0
-0
include/linux/bpf_verifier.h struct bpf_dynptr_desc { · line 1432
Quoted 9 lines
include/linux/bpf_verifier.h +6
-0@@ -1424,6 +1424,18 @@ struct bpf_dynptr_desc {u32 parent_id; }; +/* +* The last seen rereferenced object; Updated by update_ref_obj() when a register refers to a +* referenced object. Used when the helper or kfunc is releasing a referenced object, casting +* a referenced object, returning allocated memory derived from referenced object or creating +* a dynptr with a referenced object as parent. +*/
This isn't a bug, but there's a typo in the comment: 'rereferenced' should read 'referenced'.
[ ... ]
Quoted 15 lines
kernel/bpf/verifier.c +7
-0@@ -231,9 +231,28 @@ static void bpf_map_key_store(struct bpf_insn_aux_data *aux, u64 state) (poisoned ?BPF_MAP_KEY_POISON :0ULL ); } +static void update_ref_obj (struct ref_obj_desc *ref_obj,struct bpf_reg_state *reg) +{ + ref_obj->id = reg->id; + ref_obj->parent_id = reg->parent_id; + ref_obj->cnt++; +} +
kernel/bpf/verifier.c static void bpf_map_key_store(struct bpf_insn_aux_data *aux, u64 state) · line 250
Quoted 10 lines
kernel/bpf/verifier.c +10
-0+static int validate_ref_obj (struct bpf_verifier_env *env,struct ref_obj_desc *ref_obj) +{ +if (ref_obj->cnt >1 ) { +verifier_bug (env,"function expects only one referenced object but got %d\n" , + ref_obj->cnt); +return -EFAULT ; + } + +return 0 ; +}
A review comment in lore raised a concern that verifier_bug() should not be used for user-triggered errors. Since ref_obj->cnt is determined by the number of referenced arguments provided by the BPF program, a user could intentionally trigger this warning by passing multiple referenced objects.
Since verifier_bug() expands to BPF_WARN_ONCE(), triggering a warning via user-controlled input could be problematic if panic_on_warn is enabled.
Would it be safer to gracefully reject the program using verbose() and returning -EINVAL, similar to how it is handled for release kfuncs earlier in this patch?
[ ... ]
Quoted 5 lines
kernel/bpf/verifier.c +0
-1@@ -8226,15 +8232,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, meta->release_regno = regno; } -if (reg_is_referenced (env, reg) &&base_type (arg_type) !=ARG_KPTR_XCHG_DEST ) {
kernel/bpf/verifier.c static int check_func_arg(struct bpf_verifier_env *env, u32 arg, · line 8236
Quoted 10 lines
kernel/bpf/verifier.c +2
-8-if (meta->id) { -verbose (env,"more than one arg with referenced id R%d %u %u" , - regno, reg->id, - meta->id); -return -EACCES ; - } - meta->id = reg->id; - } +if (reg_is_referenced (env, reg)) +update_ref_obj (&meta->ref_obj, reg);
Does removing the ARG_KPTR_XCHG_DEST guard introduce a regression for bpf_kptr_xchg?
Looking at bpf_kptr_xchg's signature:
void *bpf_kptr_xchg(void *dst, void *ptr__in_or_null)
The dst argument (ARG_KPTR_XCHG_DEST) can be a field of a referenced allocated object. For example, consider bpf_kptr_xchg(&obj->kptr_field, NULL) where obj is a referenced object (id=X from bpf_obj_new).
Argument processing order in check_helper_call is arg0 (dst, R1) then arg1 (ptr, R2):
- dst (R1): reg_is_referenced true (id=X) -> update_ref_obj sets meta.ref_obj.id = X
- ptr (R2): NULL -> reg_is_referenced false -> no update; arg_type_is_release sets release_regno = R2
Final meta.ref_obj.id = X.
In check_helper_call's release block, the code then executes:
} else if (func_id == BPF_FUNC_kptr_xchg && meta.ref_obj.id) {
u32 id = meta.ref_obj.id;
...
err = release_reference_nomark(env->cur_state, id);
...
bpf_for_each_reg_in_vstate(...) {
if (reg->id == id)
mark_reg_invalid(env, reg);
}
}This releases obj's reference (id X) and invalidates all registers holding obj, even though obj is still live and was never meant to be released.
Under the old code, the ARG_KPTR_XCHG_DEST exclusion prevented this, so meta.id stayed 0. The release path then fell through to the bpf_register_is_null(®s[meta.release_regno]) check (R2 is NULL) and returned 0 - the correct behavior.
The retained comment on the kptr_xchg release path is now incorrect:
kernel/bpf/verifier.c static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn · line 10412
Quoted 10 lines
kernel/bpf/verifier.c +3
-3@@ -10407,17 +10407,15 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn - }else if (meta.id) { - err =release_reference (env, meta.id); + }else if (meta.ref_obj.id) { + err =release_reference (env, meta.ref_obj.id); }else if (bpf_register_is_null (®s[meta.release_regno])) { -/* meta.id can only be 0 if register that is meant to be +/* meta.ref_obj.id can only be 0 if register that is meant to be * released is NULL, which must be > R0. */
The comment states meta.ref_obj.id can only be 0 if the release register is NULL, but with the ARG_KPTR_XCHG_DEST guard removed, ref_obj.id can be taken from the dst argument (R1) which is a different register than the release register (R2). So ref_obj.id can be non-zero while the release register (R2) is NULL.
This appears to corrupt reference-tracking state for valid BPF programs that clear a kptr field on a still-held allocated object. A later bpf_obj_drop(obj) would be incorrectly rejected since the reference was already consumed.
This is corrected by commit 99727f36d6be ("bpf: Unify release handling for helpers and kfuncs") later in this series, which rewrites the release path to operate on the actual release register and short-circuits if that register is NULL.
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26613892466
PATCH v6 8/13 bpf: Unify release handling for helpers and kfuncs
In reply to Amery HungIntroduce release_reg() to consolidate the release logic shared by both helpers and kfuncs: dynptr release, kptr_xchg percpu-to-RCU conversion, regular reference release, and NULL pass-through. NULL pass-through is only allowed if the prototype indicates the argument may be null.
Determine release_regno from the function prototype/metadata before argument checking, rather than discovering it dynamically during argument processing. For helpers, scan the arg_type array in check_func_proto() via check_proto_release_reg(). For kfuncs, set release_regno to BPF_REG_1 in bpf_fetch_kfunc_arg_meta() when KF_RELEASE is set. In the future when we start adding decl_tag to kfunc arguments, we can just look at the function prototype instead of a release_regno.
Extract ref_convert_alloc_rcu_protected() and invalidate_rcu_protected_refs() to make it more clear what the code is doing. For ref_convert_alloc_rcu_protected(), it pre-converts MEM_ALLOC | MEM_PERCPU registers to MEM_RCU (clearing id so they survive), then calls release_reference() to invalidate the remaining registers and release the reference state.
Add KF_RELEASE to bpf_dynptr_file_discard() so its release_regno is set via fetch_kfunc_meta rather than being assigned manually in the dynptr argument processing. Set arg_type to ARG_PTR_TO_DYNPTR for KF_ARG_PTR_TO_DYNPTR so that check_func_arg_reg_off() correctly allows non-zero stack offsets for dynptr release arguments same as helper.
--- include/linux/bpf_verifier.h | 6 +- kernel/bpf/helpers.c | 2 +- kernel/bpf/verifier.c | 198 +++++++++--------- .../selftests/bpf/prog_tests/cb_refs.c | 2 +- .../selftests/bpf/progs/cgrp_kfunc_failure.c | 6 +- .../selftests/bpf/progs/map_kptr_fail.c | 2 +- .../selftests/bpf/progs/task_kfunc_failure.c | 6 +- .../bpf/progs/verifier_global_ptr_args.c | 2 +- .../bpf/progs/verifier_ref_tracking.c | 2 +- .../selftests/bpf/progs/verifier_sock.c | 6 +- .../selftests/bpf/progs/verifier_vfs_reject.c | 2 +- .../selftests/bpf/progs/wakeup_source_fail.c | 2 +- 12 files changed, 122 insertions(+), 114 deletions(-)
include/linux/bpf_verifier.h +3 -3
@@ -1426,9 +1426,9 @@ struct bpf_dynptr_desc {/* * The last seen rereferenced object; Updated by update_ref_obj() when a register refers to a -* referenced object. Used when the helper or kfunc is releasing a referenced object, casting -* a referenced object, returning allocated memory derived from referenced object or creating -* a dynptr with a referenced object as parent. +* referenced object. Used when the helper or kfunc is casting a referenced object, returning +* allocated memory derived from referenced object or creating a dynptr with a referenced +* object as parent. */ struct ref_obj_desc {u32 id;
kernel/bpf/helpers.c +1 -1
@@ -4957,7 +4957,7 @@ BTF_ID_FLAGS(func, bpf_stream_print_stack, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, bpf_dynptr_from_file) -BTF_ID_FLAGS(func, bpf_dynptr_file_discard) +BTF_ID_FLAGS(func, bpf_dynptr_file_discard, KF_RELEASE) BTF_ID_FLAGS(func, bpf_timer_cancel_async)BTF_KFUNCS_END (common_btf_ids)
kernel/bpf/verifier.c +103 -95
304 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/cb_refs.c +1 -1
@@ -11,7 +11,7 @@ struct {const char *prog_name;const char *err_msg; } cb_refs_tests[] = { - { "underflow_prog", "must point to scalar, or struct with scalar" }, + { "underflow_prog", "release kfunc bpf_kfunc_call_test_release expects referenced PTR_TO_BTF_ID passed to R1" }, { "leak_prog", "Possibly NULL pointer passed to helper R2" }, { "nested_cb", "Unreleased reference id=4 alloc_insn=2" }, /* alloc_insn=2{4,5} */ { "non_cb_transfer_ref", "Unreleased reference id=4 alloc_insn=1" }, /* alloc_insn=1{1,2} */
tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c +3 -3
@@ -154,7 +154,7 @@ int BPF_PROG(cgrp_kfunc_xchg_unreleased, struct cgroup *cgrp, const char *path) } SEC("tp_btf/cgroup_mkdir") -__failure __msg("must be referenced or trusted") +__failure __msg("release kfunc bpf_cgroup_release expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(cgrp_kfunc_rcu_get_release, struct cgroup *cgrp, const char *path) {struct cgroup *kptr;
@@ -191,7 +191,7 @@ int BPF_PROG(cgrp_kfunc_release_untrusted, struct cgroup *cgrp, const char *path } SEC("tp_btf/cgroup_mkdir") -__failure __msg("R1 pointer type STRUCT cgroup must point") +__failure __msg("release kfunc bpf_cgroup_release expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(cgrp_kfunc_release_fp, struct cgroup *cgrp, const char *path) {struct cgroup *acquired = (struct cgroup *)&path;
@@ -237,7 +237,7 @@ int BPF_PROG(cgrp_kfunc_release_null, struct cgroup *cgrp, const char *path) } SEC("tp_btf/cgroup_mkdir") -__failure __msg("release kernel function bpf_cgroup_release expects") +__failure __msg("release kfunc bpf_cgroup_release expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(cgrp_kfunc_release_unacquired, struct cgroup *cgrp, const char *path) {/* Cannot release trusted cgroup pointer which was not acquired. */
tools/testing/selftests/bpf/progs/map_kptr_fail.c +1 -1
@@ -252,7 +252,7 @@ int reject_untrusted_store_to_ref(struct __sk_buff *ctx) } SEC("?tc") -__failure __msg("R2 must be referenced") +__failure __msg("release helper bpf_kptr_xchg expects referenced PTR_TO_BTF_ID passed to R2") int reject_untrusted_xchg(struct __sk_buff *ctx) {struct prog_test_ref_kfunc *p;
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +3 -3
@@ -178,7 +178,7 @@ int BPF_PROG(task_kfunc_release_untrusted, struct task_struct *task, u64 clone_f } SEC("tp_btf/task_newtask") -__failure __msg("R1 pointer type STRUCT task_struct must point") +__failure __msg("release kfunc bpf_task_release expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(task_kfunc_release_fp, struct task_struct *task, u64 clone_flags) {struct task_struct *acquired = (struct task_struct *)&clone_flags;
@@ -224,7 +224,7 @@ int BPF_PROG(task_kfunc_release_null, struct task_struct *task, u64 clone_flags) } SEC("tp_btf/task_newtask") -__failure __msg("release kernel function bpf_task_release expects") +__failure __msg("release kfunc bpf_task_release expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(task_kfunc_release_unacquired, struct task_struct *task, u64 clone_flags) {/* Cannot release trusted task pointer which was not acquired. */
@@ -313,7 +313,7 @@ int BPF_PROG(task_access_comm4, struct task_struct *task, const char *buf, bool } SEC("tp_btf/task_newtask") -__failure __msg("R1 must be referenced or trusted") +__failure __msg("release kfunc bpf_task_release expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(task_kfunc_release_in_map, struct task_struct *task, u64 clone_flags) {struct task_struct *local;
tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c +1 -1
@@ -153,7 +153,7 @@ __weak int subprog_trusted_destroy(struct task_struct *task __arg_trusted) SEC("?tp_btf/task_newtask") __failure __log_level(2) -__msg("release kernel function bpf_task_release expects refcounted PTR_TO_BTF_ID") +__msg("release kfunc bpf_task_release expects referenced PTR_TO_BTF_ID passed to R1")int BPF_PROG (trusted_destroy_fail ,struct task_struct *task,u64 clone_flags) {return subprog_trusted_destroy (task);
tools/testing/selftests/bpf/progs/verifier_ref_tracking.c +1 -1
@@ -1288,7 +1288,7 @@ l1_%=: r1 = r6; \ SEC("tc") __description("reference tracking: bpf_sk_release(listen_sk)") -__failure __msg("R1 must be referenced when passed to release function") +__failure __msg("release helper bpf_sk_release expects referenced PTR_TO_BTF_ID passed to R1")__naked void bpf_sk_release_listen_sk (void ) { asm volatile (
tools/testing/selftests/bpf/progs/verifier_sock.c +3 -3
@@ -603,7 +603,7 @@ l2_%=: r0 = *(u32*)(r0 + %[bpf_tcp_sock_snd_cwnd]); \ SEC("tc") __description("bpf_sk_release(skb->sk)") -__failure __msg("R1 must be referenced when passed to release function") +__failure __msg("release helper bpf_sk_release expects referenced PTR_TO_BTF_ID passed to R1")__naked void bpf_sk_release_skb_sk (void ) { asm volatile (" \
@@ -620,7 +620,7 @@ l0_%=: r0 = 0; \ SEC("tc") __description("bpf_sk_release(bpf_sk_fullsock(skb->sk))") -__failure __msg("R1 must be referenced when passed to release function") +__failure __msg("release helper bpf_sk_release expects referenced PTR_TO_BTF_ID passed to R1")__naked void bpf_sk_fullsock_skb_sk (void ) { asm volatile (" \
@@ -644,7 +644,7 @@ l1_%=: r1 = r0; \ SEC("tc") __description("bpf_sk_release(bpf_tcp_sock(skb->sk))") -__failure __msg("R1 must be referenced when passed to release function") +__failure __msg("release helper bpf_sk_release expects referenced PTR_TO_BTF_ID passed to R1")__naked void bpf_tcp_sock_skb_sk (void ) { asm volatile (" \
tools/testing/selftests/bpf/progs/verifier_vfs_reject.c +1 -1
@@ -80,7 +80,7 @@ int BPF_PROG(get_task_exe_file_kfunc_unreleased) } SEC("lsm.s/file_open") -__failure __msg("release kernel function bpf_put_file expects") +__failure __msg("release kfunc bpf_put_file expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(put_file_kfunc_unacquired, struct file *file) {/* Can't release an unacquired pointer. */
tools/testing/selftests/bpf/progs/wakeup_source_fail.c +1 -1
@@ -42,7 +42,7 @@ int wakeup_source_access_lock_fields(void *ctx) } SEC("syscall") -__failure __msg("type=scalar expected=fp") +__failure __msg("release kfunc bpf_wakeup_sources_read_unlock expects referenced PTR_TO_BTF_ID passed to R1") int wakeup_source_unlock_no_lock(void *ctx) {struct bpf_ws_lock *lock = (void *)0x1 ;
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v6 08/13] bpf: Unify release handling for helpers and kfuncs
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Hardcoding `release_regno = BPF_REG_1` for `KF_RELEASE` kfuncs bypasses reference tracking for…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Hardcoding release_regno = BPF_REG_1 for KF_RELEASE kfuncs bypasses reference tracking for kfuncs that take the release argument in a different register, leading to a potential double-free.
- [Low] The verifier incorrectly relies on !!meta.dynptr.id to determine if the released argument is a dynptr, introducing a latent bug that rejects valid programs.
--
commit a23fc3d5455bdc1edfa4672854ea0a5f28d72d11
Author: Amery Hung <[email protected]>
Subject: bpf: Unify release handling for helpers and kfuncs
This commit introduces release_reg() to consolidate the release logic shared by both helpers and kfuncs. It determines release_regno from the function prototype/metadata before argument checking, setting it to BPF_REG_1 for KF_RELEASE kfuncs, and extracting RCU ref tracking invalidation into helper functions.
Quoted 4 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
Quoted 9 lines
kernel/bpf/verifier.c +0
-5@@ -10116,37 +10182,11 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn }if (meta.release_regno) { - err = -EINVAL ; -if (arg_type_is_dynptr (fn->arg_type[meta.release_regno -BPF_REG_1 ])) { - err =unmark_stack_slots_dynptr (env, ®s[meta.release_regno]); - }else if (func_id == BPF_FUNC_kptr_xchg && meta.ref_obj.id) { -u32 id = meta.ref_obj.id;
[ ... ]
kernel/bpf/verifier.c static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn · line 10189
Quoted 13 lines
kernel/bpf/verifier.c +5
-8- }else if (meta.ref_obj.id) { - err =release_reference (env, meta.ref_obj.id); - }else if (bpf_register_is_null (®s[meta.release_regno])) { -/* meta.ref_obj.id can only be 0 if register that is meant to be -* released is NULL, which must be > R0. -*/ - err =0 ; - } +struct bpf_reg_state *reg = ®s[meta.release_regno]; +bool convert_rcu = (func_id == BPF_FUNC_kptr_xchg) &&in_rcu_cs (env) && + (reg->type &MEM_ALLOC ) && (reg->type &MEM_PERCPU ); + + err =release_reg (env, reg, convert_rcu, !!meta.dynptr.id);
[Severity: Low]
Does this logic correctly determine if the released argument is a dynptr?
By using !!meta.dynptr.id, it checks if any referenced dynptr was processed. If a hypothetical helper takes both a normal PTR_TO_BTF_ID to release and a separate referenced dynptr, wouldn't meta.dynptr.id be non-zero, causing release_reg() to incorrectly treat the released argument as a dynptr and spuriously reject the program?
The previous code correctly checked arg_type_is_dynptr(fn->arg_type[...]).
Quoted 3 lines
kernel/bpf/verifier.c +0
-0if (err)return err; }
[ ... ]
kernel/bpf/verifier.c int bpf_fetch_kfunc_arg_meta(struct bpf_verifier_env *env, · line 12430
Quoted 8 lines
kernel/bpf/verifier.c +4
-0@@ -12403,6 +12424,10 @@ int bpf_fetch_kfunc_arg_meta(struct bpf_verifier_env *env, meta->kfunc_flags = *kfunc.flags; +/* Only support release referenced argument passed by register */ +if (is_kfunc_release (meta)) + meta->release_regno =BPF_REG_1 ; +
[Severity: High]
Does hardcoding meta->release_regno = BPF_REG_1 bypass reference tracking for kfuncs that take the release argument in a different register?
If a new kfunc or an out-of-tree module kfunc is introduced that takes a KF_RELEASE object in a register other than R1 (e.g., void bpf_my_release(int flags, struct my_obj *obj)), it seems an attacker could pass 0 in R1. Since R1 is a scalar, the validation loop would skip pointer checks. release_reg() would then be called on regs[1], silently succeeding because it is NULL, while the runtime kfunc frees the object in R2, leading to a double-free.
The previous code correctly identified the release register dynamically in check_kfunc_args().
Quoted 2 lines
kernel/bpf/verifier.c +0
-0return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v6 9/13 bpf: Fix dynptr ref counting to scan all call frames
In reply to Amery HungWhen checking whether a referenced dynptr can be overwritten, destroy_if_dynptr_stack_slot only counted sibling dynptrs in the current call frame. If a clone sharing the same virtual ref parent existed in a different frame (e.g., passed to a subprog), it would not be counted, causing the verifier to incorrectly reject the overwrite with "cannot overwrite referenced dynptr".
Fix by extracting the counting into dynptr_ref_cnt() which uses bpf_for_each_reg_in_vstate_mask() to scan dynptr stack slots across all call frames.
--- kernel/bpf/verifier.c | 52 ++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 23 deletions(-)
kernel/bpf/verifier.c +29 -23
@@ -786,10 +786,29 @@ static void mark_reg_invalid(const struct bpf_verifier_env *env, struct bpf_reg___mark_reg_unknown (env, reg); } +static int dynptr_ref_cnt (struct bpf_verifier_env *env,int v_parent_id) +{ +struct bpf_stack_state *stack; +struct bpf_func_state *state; +struct bpf_reg_state *reg; +int ref_cnt =0 ; + +bpf_for_each_reg_in_vstate_mask (env->cur_state, state, reg, stack,1 <<STACK_DYNPTR , ({ +if (!stack || stack->slot_type[0 ] !=STACK_DYNPTR ) +continue ; +if (!stack->spilled_ptr.dynptr.first_slot) +continue ; +if (stack->spilled_ptr.parent_id == v_parent_id) + ref_cnt++; + })); + +return ref_cnt; +} +static int destroy_if_dynptr_stack_slot (struct bpf_verifier_env *env,struct bpf_func_state *state,int spi) { -int i, err =0 ; +int err =0 ;/* We always ensure that STACK_DYNPTR is never set partially, * hence just checking for slot_type[0] is enough. This is
@@ -803,28 +822,15 @@ static int destroy_if_dynptr_stack_slot(struct bpf_verifier_env *env,if (!state->stack[spi].spilled_ptr.dynptr.first_slot) spi = spi +1 ; -if (dynptr_type_referenced (state->stack[spi].spilled_ptr.dynptr.type)) { -int v_parent_id = state->stack[spi].spilled_ptr.parent_id; -int ref_cnt =0 ; - -/* -* A referenced dynptr can be overwritten only if there is at -* least one other dynptr sharing the same virtual ref parent, -* ensuring the reference can still be properly released. -*/ -for (i =0 ; i < state->allocated_stack /BPF_REG_SIZE ; i++) { -if (state->stack[i].slot_type[0 ] !=STACK_DYNPTR ) -continue ; -if (!state->stack[i].spilled_ptr.dynptr.first_slot) -continue ; -if (state->stack[i].spilled_ptr.parent_id == v_parent_id) - ref_cnt++; - } - -if (ref_cnt <=1 ) { -verbose (env,"cannot overwrite referenced dynptr\n" ); -return -EINVAL ; - } +/* +* A referenced dynptr can be overwritten only if there is at +* least one other dynptr sharing the same virtual ref parent, +* ensuring the reference can still be properly released. +*/ +if (dynptr_type_referenced (state->stack[spi].spilled_ptr.dynptr.type) && +dynptr_ref_cnt (env, state->stack[spi].spilled_ptr.parent_id) <=1 ) { +verbose (env,"cannot overwrite referenced dynptr\n" ); +return -EINVAL ; }/* Invalidate the dynptr and any derived slices */
Signature · 1 line
2.53.0-Meta
PATCH v6 10/13 selftests/bpf: Test creating dynptr from dynptr data and slice
In reply to Amery HungThe verifier currently does not allow creating dynptr from dynptr data or slice. Add a selftest to test this explicitly.
--- .../testing/selftests/bpf/progs/dynptr_fail.c | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+)
tools/testing/selftests/bpf/progs/dynptr_fail.c +42 -0
@@ -705,6 +705,48 @@ int dynptr_from_mem_invalid_api(void *ctx)return 0 ; } +/* Cannot create dynptr from dynptr data */ +SEC("?raw_tp") +__failure __msg("Unsupported reg type mem for bpf_dynptr_from_mem data") +int dynptr_from_dynptr_data(void *ctx) +{ +struct bpf_dynptr ptr, ptr2; +__u8 *data; + +if (get_map_val_dynptr (&ptr)) +return 0 ; + + data =bpf_dynptr_data (&ptr,0 ,sizeof (__u32)); +if (!data) +return 0 ; + +/* this should fail */ +bpf_dynptr_from_mem (data,sizeof (__u32),0 , &ptr2); + +return 0 ; +} + +/* Cannot create dynptr from dynptr slice */ +SEC("?tc") +__failure __msg("Unsupported reg type mem for bpf_dynptr_from_mem data") +int dynptr_from_dynptr_slice(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr, ptr2; +struct ethhdr *hdr; +char buffer[sizeof (*hdr)] = {}; + +bpf_dynptr_from_skb (skb,0 , &ptr); + + hdr =bpf_dynptr_slice_rdwr (&ptr,0 , buffer,sizeof (buffer)); +if (!hdr) +return SK_DROP ; + +/* this should fail */ +bpf_dynptr_from_mem (hdr,sizeof (*hdr),0 , &ptr2); + +return SK_PASS ; +} + SEC("?tc") __failure __msg("cannot overwrite referenced dynptr") __log_level(2)int dynptr_pruning_overwrite (struct __sk_buff *ctx)
Signature · 1 line
2.53.0-Meta
PATCH v6 11/13 selftests/bpf: Test using slice after invalidating dynptr clone
In reply to Amery HungThe parent object of a cloned dynptr is skb not the original dynptr. Invalidate the original dynptr should not prevent the program from using the slice derived from the cloned dynptr.
--- .../selftests/bpf/prog_tests/bpf_qdisc.c | 8 ++ ..._qdisc_dynptr_use_after_invalidate_clone.c | 74 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_dynptr_use_after_invalidate_clone.c
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c +8 -0
@@ -8,6 +8,10 @@#include "bpf_qdisc_fifo.skel.h" #include "bpf_qdisc_fq.skel.h" #include "bpf_qdisc_fail__incompl_ops.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr_slice.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr_cross_frame.skel.h" +#include "bpf_qdisc_dynptr_use_after_invalidate_clone.skel.h" #define LO_IFINDEX 1
@@ -223,6 +227,10 @@ void test_ns_bpf_qdisc(void)test_qdisc_attach_to_non_root ();if (test__start_subtest ("incompl_ops" ))test_incompl_ops (); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr_cross_frame); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr_slice); +RUN_TESTS (bpf_qdisc_dynptr_use_after_invalidate_clone); }void serial_test_bpf_qdisc_default (void )
tools/testing/selftests/bpf/progs/bpf_qdisc_dynptr_use_after_invalidate_clone.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v6 11/13] selftests/bpf: Test using slice after invalidating dynptr clone
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The commit adds #includes and RUN_TESTS calls for three new BPF skeleton headers, but completely…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The commit adds #includes and RUN_TESTS calls for three new BPF skeleton headers, but completely omits the corresponding .c source files, causing compilation to fail. --
commit 3e0cbdc36c0aac54acdb8e69cb8a14baf7548c43
Author: Amery Hung <[email protected]>
selftests/bpf: Test using slice after invalidating dynptr clone
This commit adds a test to verify that invalidating an original dynptr does not prevent a BPF program from using a slice derived from a cloned dynptr. It adds the new test program and updates the bpf_qdisc test suite to run it.
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c line 13
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c +3
-0@@ -8,6 +8,10 @@#include "bpf_qdisc_fifo.skel.h" #include "bpf_qdisc_fq.skel.h" #include "bpf_qdisc_fail__incompl_ops.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr_slice.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr_cross_frame.skel.h"
[Severity: Low]
Does this break the build when compiling this specific commit?
The corresponding source files for these three headers are not present in this patch, which will cause a build failure. It appears these files are actually added later in the series in commit f9d9931d5afe8f4e515a543c5a58e4dec2ad1899 (selftests/bpf: Test using dynptr after freeing the underlying object).
Could these includes and their associated RUN_TESTS() calls be moved to the later patch to ensure the tree remains fully bisectable?
Quoted 1 line
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c +1
-0+#include "bpf_qdisc_dynptr_use_after_invalidate_clone.skel.h"
[ ... ]
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c +4
-0@@ -223,6 +227,10 @@ void test_ns_bpf_qdisc(void)test_qdisc_attach_to_non_root ();if (test__start_subtest ("incompl_ops" ))test_incompl_ops (); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr_cross_frame); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr_slice); +RUN_TESTS (bpf_qdisc_dynptr_use_after_invalidate_clone); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
[email protected]
AI reviewRe: [PATCH bpf-next v6 11/13] selftests/bpf: Test using slice after invalidating dynptr clone
In reply to Amery HungThree of these four skeleton headers are generated from progs source files that do not exist yet at this commit. Only bpf_qdisc_dynptr_use_after_invalidate_clone.c is added here:
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c line 14
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c +4
-0@@ -8,6 +8,10 @@#include "bpf_qdisc_fifo.skel.h" #include "bpf_qdisc_fq.skel.h" #include "bpf_qdisc_fail__incompl_ops.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr_slice.skel.h" +#include "bpf_qdisc_fail__invalid_dynptr_cross_frame.skel.h" +#include "bpf_qdisc_dynptr_use_after_invalidate_clone.skel.h"
Three of these four skeleton headers are generated from progs source files that do not exist yet at this commit. Only bpf_qdisc_dynptr_use_after_invalidate_clone.c is added here:
git ls-tree -r 96063d161a74 -- progs/
bpf_qdisc_dynptr_use_after_invalidate_clone.c
The progs source files bpf_qdisc_fail__invalid_dynptr.c, bpf_qdisc_fail__invalid_dynptr_slice.c and bpf_qdisc_fail__invalid_dynptr_cross_frame.c are only added later in c8e177e9eaaf ("selftests/bpf: Test using dynptr after freeing the underlying object").
The selftests Makefile generates .skel.h only from existing progs/*.c:
TRUNNER_BPF_SRCS := $(notdir $(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
TRUNNER_BPF_SKELS := $(patsubst %.c,$(TRUNNER_OUTPUT)/%.skel.h, \
$(TRUNNER_BPF_SRCS))With the three sources missing, their .skel.h headers are never generated, so compiling prog_tests/bpf_qdisc.c fails with something like:
fatal error: bpf_qdisc_fail__invalid_dynptr.skel.h: No such file or directory
Does this break the selftests build at this commit? The build appears to stay broken across 96063d161a74..c8e177e9eaaf until the later commit adds the three progs sources.
Could the three invalid_dynptr* includes (and their matching RUN_TESTS calls below) move to the same commit that adds their progs sources, so each patch builds on its own?
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c void test_ns_bpf_qdisc(void) · line 234
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c +4
-0@@ -223,6 +227,10 @@ void test_ns_bpf_qdisc(void)test_qdisc_attach_to_non_root ();if (test__start_subtest ("incompl_ops" ))test_incompl_ops (); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr_cross_frame); +RUN_TESTS (bpf_qdisc_fail__invalid_dynptr_slice); +RUN_TESTS (bpf_qdisc_dynptr_use_after_invalidate_clone); }
The wiring for bpf_qdisc_dynptr_use_after_invalidate_clone itself looks self-contained and correct in this commit; only the three invalid_dynptr* references arrive before their sources.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26613892466
PATCH v6 12/13 selftests/bpf: Test using file dynptr after the reference on file is dropped
In reply to Amery HungFile dynptr and slice should be invalidated when the parent file's reference is dropped in the program. Without the verifier tracking dyntpr's parent referenced object, the dynptr would continute to be incorrectly used even if the underlying file is being tear down or gone.
--- .../selftests/bpf/progs/file_reader_fail.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+)
tools/testing/selftests/bpf/progs/file_reader_fail.c +60 -0
@@ -50,3 +50,63 @@ int xdp_no_dynptr_type(struct xdp_md *xdp)bpf_dynptr_file_discard (&dynptr);return 0 ; } + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task); +struct bpf_dynptr dynptr; +char buf[64 ]; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr)) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + +bpf_dynptr_read (buf,sizeof (buf), &dynptr,0 ,0 ); +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +} + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_slice_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task); +struct bpf_dynptr dynptr; +char *data; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr)) + goto out; + + data =bpf_dynptr_data (&dynptr,0 ,1 ); +if (!data) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + + *data ='x' ; +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +}
Signature · 1 line
2.53.0-Meta
Re: [PATCH bpf-next v6 12/13] selftests/bpf: Test using file dynptr after the reference on file is dropped
Quoted 54 lines · Amery Hung
File dynptr and slice should be invalidated when the parent file's reference is dropped in the program. Without the verifier tracking dyntpr's parent referenced object, the dynptr would continute to be incorrectly used even if the underlying file is being tear down or gone.
Signed-off-by Amery Hung <[email protected]>--- .../selftests/bpf/progs/file_reader_fail.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+)tools/testing/selftests/bpf/progs/file_reader_fail.c +36
-0@@ -50,3 +50,63 @@ int xdp_no_dynptr_type(struct xdp_md *xdp)bpf_dynptr_file_discard (&dynptr);return 0 ; } + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task); +struct bpf_dynptr dynptr; +char buf[64 ]; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr)) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + +bpf_dynptr_read (buf,sizeof (buf), &dynptr,0 ,0 ); +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +} + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_slice_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task);
tools/testing/selftests/bpf/progs/file_reader_fail.c int xdp_no_dynptr_type(struct xdp_md *xdp) · line 98
Quoted 10 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +10
-0+struct bpf_dynptr dynptr; +char *data; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr)) + goto out; + + data =bpf_dynptr_data (&dynptr,0 ,1 );
File dynptr is always read-only, so bpf_dynptr_data() always returns NULL. Verifier does not know this (not sure if we should address it). Maybe it makes sense to remove this call or substitute by probe read, just to avoid confusing example.
Quoted 14 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +14
-0+if (!data) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + + *data ='x' ; +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +}
Re: [PATCH bpf-next v6 12/13] selftests/bpf: Test using file dynptr after the reference on file is dropped
Quoted 63 lines · Mykyta Yatsenko
Quoted 61 lines · Amery Hung
File dynptr and slice should be invalidated when the parent file's reference is dropped in the program. Without the verifier tracking dyntpr's parent referenced object, the dynptr would continute to be incorrectly used even if the underlying file is being tear down or gone.
Signed-off-by Amery Hung <[email protected]>--- .../selftests/bpf/progs/file_reader_fail.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+)tools/testing/selftests/bpf/progs/file_reader_fail.c +43
-0@@ -50,3 +50,63 @@ int xdp_no_dynptr_type(struct xdp_md *xdp)bpf_dynptr_file_discard (&dynptr);return 0 ; } + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task); +struct bpf_dynptr dynptr; +char buf[64 ]; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr)) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + +bpf_dynptr_read (buf,sizeof (buf), &dynptr,0 ,0 ); +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +} + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_slice_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task); +struct bpf_dynptr dynptr; +char *data; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr))
Quoted 9 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c int xdp_no_dynptr_type(struct xdp_md *xdp) · line 98
Quoted 3 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +3
-0+ goto out; + + data =bpf_dynptr_data (&dynptr,0 ,1 );File dynptr is always read-only, so
bpf_dynptr_data()always returns NULL. Verifier does not know this (not sure if we should address it). Maybe it makes sense to remove this call or substitute by probe read, just to avoid confusing example.
Thanks for taking a look at the selftests and pointing this out. Does replacing it with bpf_dynptr_slice() make sense to you?
Quoted 15 lines
Quoted 14 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +14
-0+if (!data) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + + *data ='x' ; +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +}
Re: [PATCH bpf-next v6 12/13] selftests/bpf: Test using file dynptr after the reference on file is dropped
Quoted 75 lines · Amery Hung
Quoted 63 lines · Mykyta Yatsenko
Quoted 61 lines · Amery Hung
File dynptr and slice should be invalidated when the parent file's reference is dropped in the program. Without the verifier tracking dyntpr's parent referenced object, the dynptr would continute to be incorrectly used even if the underlying file is being tear down or gone.
Signed-off-by Amery Hung <[email protected]>--- .../selftests/bpf/progs/file_reader_fail.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+)tools/testing/selftests/bpf/progs/file_reader_fail.c +43
-0@@ -50,3 +50,63 @@ int xdp_no_dynptr_type(struct xdp_md *xdp)bpf_dynptr_file_discard (&dynptr);return 0 ; } + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task); +struct bpf_dynptr dynptr; +char buf[64 ]; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr)) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + +bpf_dynptr_read (buf,sizeof (buf), &dynptr,0 ,0 ); +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +} + +SEC("lsm/file_open") +__failure +__msg("Leaking reference id={{[0-9]+}} alloc_insn={{[0-9]+}}. Release it first.") +int use_file_dynptr_slice_after_put_file(void *ctx) +{ +struct task_struct *task =bpf_get_current_task_btf (); +struct file *file =bpf_get_task_exe_file (task); +struct bpf_dynptr dynptr; +char *data; + +if (!file) +return 0 ; + +if (bpf_dynptr_from_file (file,0 , &dynptr))Quoted 9 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c int xdp_no_dynptr_type(struct xdp_md *xdp) · line 98
Quoted 3 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +3
-0+ goto out; + + data =bpf_dynptr_data (&dynptr,0 ,1 );File dynptr is always read-only, so
bpf_dynptr_data()always returns NULL. Verifier does not know this (not sure if we should address it). Maybe it makes sense to remove this call or substitute by probe read, just to avoid confusing example.
Quoted 3 lines
Thanks for taking a look at the selftests and pointing this out. Does replacing it with
bpf_dynptr_slice()make sense to you?
That'll do, but bpf_dynptr_read() is more straightforward API for reading file dynptr, as you always have to copy the data.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +14
-0+if (!data) + goto out; + +/* this should fail - file dynptr should be discarded first to prevent resource leak */ +bpf_put_file (file); + + *data ='x' ; +return 0 ; + +out: +bpf_dynptr_file_discard (&dynptr); +bpf_put_file (file); +return 0 ; +}
PATCH v6 13/13 selftests/bpf: Test using dynptr after freeing the underlying object
In reply to Amery HungMake sure the verifier invalidates the dynptr and dynptr slice derived from an skb after the skb is freed.
--- .../progs/bpf_qdisc_fail__invalid_dynptr.c | 68 +++++++++++++++++ ...f_qdisc_fail__invalid_dynptr_cross_frame.c | 74 +++++++++++++++++++ .../bpf_qdisc_fail__invalid_dynptr_slice.c | 70 ++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr_cross_frame.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr_slice.c
tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr.c new file +68 -0
@@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <vmlinux.h> +#include "bpf_experimental.h" +#include "bpf_qdisc_common.h" +#include "bpf_misc.h" + +char _license[] SEC("license") = "GPL"; + +int proto; + +SEC("struct_ops") +__failure __msg("Expected an initialized dynptr as R1") +int BPF_PROG(invalid_dynptr, struct sk_buff *skb, struct Qdisc *sch, + struct bpf_sk_buff_ptr *to_free) +{ +struct bpf_dynptr ptr; +struct ethhdr *hdr; + +bpf_dynptr_from_skb ((struct __sk_buff *)skb,0 , &ptr); + +bpf_qdisc_skb_drop (skb, to_free); + + hdr =bpf_dynptr_slice (&ptr,0 ,NULL ,sizeof (*hdr)); +if (!hdr) +return NET_XMIT_DROP ; + + proto = hdr->h_proto; + +return NET_XMIT_DROP ; +} + +SEC("struct_ops") +__auxiliary +struct sk_buff *BPF_PROG (bpf_qdisc_test_dequeue ,struct Qdisc *sch) +{ +return NULL ; +} + +SEC("struct_ops") +__auxiliary +int BPF_PROG (bpf_qdisc_test_init ,struct Qdisc *sch,struct nlattr *opt, +struct netlink_ext_ack *extack) +{ +return 0 ; +} + +SEC("struct_ops") +__auxiliary +void BPF_PROG (bpf_qdisc_test_reset ,struct Qdisc *sch) +{ +} + +SEC("struct_ops") +__auxiliary +void BPF_PROG (bpf_qdisc_test_destroy ,struct Qdisc *sch) +{ +} + +SEC(".struct_ops") +struct Qdisc_ops test = { + .enqueue = (void *)invalid_dynptr, + .dequeue = (void *)bpf_qdisc_test_dequeue, + .init = (void *)bpf_qdisc_test_init, + .reset = (void *)bpf_qdisc_test_reset, + .destroy = (void *)bpf_qdisc_test_destroy, + .id ="bpf_qdisc_test" , +};
tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr_cross_frame.c new file +74 -0
74 lines not on this page · raw message
tools/testing/selftests/bpf/progs/bpf_qdisc_fail__invalid_dynptr_slice.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Thu, 28 May 2026 18:49:23 -0700 you wrote:
Hi all,
This patchset cleans up dynptr handling, refactors object relationship tracking in the verifier by introducing
parent_idand foldingref_obj_idinto id, and fixes dynptr use-after-free bugs where file/skb dynptrs are not invalidated when the parent referenced object is freed.[...]
Here is the summary with links:
- [bpf-next,v6,01/13] bpf: Simplify mark_stack_slot_obj_read() and callers
https://git.kernel.org/bpf/bpf-next/c/bab08d1f7043 - [bpf-next,v6,02/13] bpf: Unify dynptr handling in the verifier https://git.kernel.org/bpf/bpf-next/c/b5c0a07eb2c2 - [bpf-next,v6,03/13] bpf: Assign reg->id when getting referenced kptr from ctx https://git.kernel.org/bpf/bpf-next/c/94ac7553361f - [bpf-next,v6,04/13] bpf: Preserve reg->id of pointer objects after null-check https://git.kernel.org/bpf/bpf-next/c/06d518a5583f - [bpf-next,v6,05/13] bpf: Refactor object relationship tracking and fix dynptr UAF bug https://git.kernel.org/bpf/bpf-next/c/308c7a0ae885 - [bpf-next,v6,06/13] bpf: Remove redundant dynptr arg check for helper https://git.kernel.org/bpf/bpf-next/c/92d681b42746 - [bpf-next,v6,07/13] bpf: Unify referenced object tracking in verifier https://git.kernel.org/bpf/bpf-next/c/b7dd2b388657 - [bpf-next,v6,08/13] bpf: Unify release handling for helpers and kfuncs https://git.kernel.org/bpf/bpf-next/c/bcfcb15fde94 - [bpf-next,v6,09/13] bpf: Fix dynptr ref counting to scan all call frames https://git.kernel.org/bpf/bpf-next/c/2eee6fe8ac2c - [bpf-next,v6,10/13] selftests/bpf: Test creating dynptr from dynptr data and slice https://git.kernel.org/bpf/bpf-next/c/fbcc68af6047 - [bpf-next,v6,11/13] selftests/bpf: Test using slice after invalidating dynptr clone https://git.kernel.org/bpf/bpf-next/c/925320666e06 - [bpf-next,v6,12/13] selftests/bpf: Test using file dynptr after the reference on file is dropped https://git.kernel.org/bpf/bpf-next/c/3f75a757a3af - [bpf-next,v6,13/13] selftests/bpf: Test using dynptr after freeing the underlying object https://git.kernel.org/bpf/bpf-next/c/60c7c3b880c8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html