Object relationship refactor followup
Subsystems (6)
cover Object relationship refactor followup
Hi,
The main patchset refactoring object relationship tracking in the verifier has landed and this is a followup that addresses the remaining feedback in v6 [0].
[0] https://lore.kernel.org/bpf/[email protected]/
Amery Hung (3):
bpf: Fix dead error check on acquire_reference() in check_kfunc_call
bpf: Compare parent_id in refsafe() for REF_TYPE_PTR selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test
kernel/bpf/states.c | 3 +++ kernel/bpf/verifier.c | 3 ++- tools/testing/selftests/bpf/progs/file_reader_fail.c | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.53.0-Meta
PATCH 1/3 bpf: Fix dead error check on acquire_reference() in check_kfunc_call
acquire_reference() returns a signed int that may be a negative errno but was converted to unsigned, which makes the subsequent error check deadcode. Fix it by declaring 'id' as int so the error path is taken correctly.
--- kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +2 -1
@@ -12817,9 +12817,10 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,struct bpf_kfunc_call_arg_meta meta;struct bpf_insn_aux_data *insn_aux;int err, insn_idx = *insn_idx_p; -u32 i, nargs, ptr_type_id, id;const struct btf_param *args; +u32 i, nargs, ptr_type_id;struct btf *desc_btf; +int id;/* skip for now, but return error when we find this in fixup_kfunc_call */ if (!insn->imm)
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v1 1/3] bpf: Fix dead error check on acquire_reference() in check_kfunc_call
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:
- [High] Missing error check on acquire_reference() in do_check_common allows BPF programs to bypass reference tracking and leak kernel resources. --
commit 259ddea87c590cd0902d75313fa1c99925c708fb
Author: Amery Hung <[email protected]>
bpf: Fix dead error check on acquire_reference() in check_kfunc_call
This commit changes the type of the 'id' variable from a u32 to an int so that negative error codes returned from acquire_reference() are checked correctly instead of being treated as large positive integers.
kernel/bpf/verifier.c static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, · line 12823
Quoted 13 lines
kernel/bpf/verifier.c +2
-1@@ -12817,9 +12817,10 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,struct bpf_kfunc_call_arg_meta meta;struct bpf_insn_aux_data *insn_aux;int err, insn_idx = *insn_idx_p; -u32 i, nargs, ptr_type_id, id;const struct btf_param *args; +u32 i, nargs, ptr_type_id;struct btf *desc_btf; +int id;
[Severity: High]
This isn't a bug introduced by this patch, but since we are fixing a missing error check on acquire_reference() here, could a similar issue exist in do_check_common() when initializing struct_ops program arguments?
In kernel/bpf/verifier.c:do_check_common():
/* Acquire references for struct_ops program arguments tagged with "__ref" */
if (!subprog && env->prog->type == BPF_PROG_TYPE_STRUCT_OPS) {
for (i = 0; i < aux->ctx_arg_info_size; i++)
aux->ctx_arg_info[i].ref_id = aux->ctx_arg_info[i].refcounted ?
acquire_reference(env, 0, 0) : 0;
}Since acquire_reference() can return a negative error like -ENOMEM, assigning it directly to aux->ctx_arg_info[i].ref_id (which is a u32) without checking for errors seems like it would swallow the error code.
Does this allow the verifier to successfully accept a BPF program without tracking the reference, potentially leading to a kernel resource leak when the reference isn't released at runtime?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH bpf-next v1 1/3] bpf: Fix dead error check on acquire_reference() in check_kfunc_call
In reply to Amery HungThis looks like a bug fix, but it does not carry a Fixes: tag. The dead error check appears to have been introduced when check_kfunc_call() began using the function-scoped 'u32 i, nargs…
Quoted 8 lines
bpf: Fix dead error check on
acquire_reference()incheck_kfunc_call
acquire_reference()returns a signed int that may be a negative errno but was converted to unsigned, which makes the subsequent error check deadcode. Fix it by declaring 'id' as int so the error path is taken correctly.Signed-off-by Amery Hung <[email protected]>
This looks like a bug fix, but it does not carry a Fixes: tag. The dead error check appears to have been introduced when check_kfunc_call() began using the function-scoped 'u32 i, nargs, ptr_type_id, id;' declaration in place of the earlier block-local 'int id'.
Should this include:
---
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/26983135146
Re: [PATCH bpf-next v1 1/3] bpf: Fix dead error check on acquire_reference() in check_kfunc_call
In reply to Amery HungQuoted 7 lines · Amery Hung
acquire_reference()returns a signed int that may be a negative errno but was converted to unsigned, which makes the subsequent error check deadcode. Fix it by declaring 'id' as int so the error path is taken correctly.Signed-off-by Amery Hung <[email protected]>---
[...]
PATCH 2/3 bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
In reply to Amery Hungrefsafe() compared each reference's id and type but not its parent_id, so two states whose PTR references differ only in the parent object they were derived from could be wrongly treated as equivalent and pruned. Fix it by checking parent_id too.
--- kernel/bpf/states.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/states.c +3 -0
@@ -890,6 +890,9 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *creturn false;switch (old->refs[i].type) {case REF_TYPE_PTR : +if (!check_ids (old->refs[i].parent_id, cur->refs[i].parent_id, idmap)) +return false; +break ;case REF_TYPE_IRQ :break ;case REF_TYPE_LOCK :
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
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:
- [High] Triggering WARN_ON_ONCE(1) in check_ids() via BPF_ID_MAP_SIZE exhaustion with leaked references. --
commit 22d2263c4d3e606f05ac37e06afa0b46878b3f51
Author: Amery Hung <[email protected]>
bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
This patch updates refsafe() to compare the parent_id of each reference for REF_TYPE_PTR, fixing an issue where two states could be wrongly treated as equivalent if their PTR references only differed in the parent object they were derived from.
kernel/bpf/states.c static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c · line 894
Quoted 9 lines
kernel/bpf/states.c +2
-0@@ -890,6 +890,9 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *creturn false;switch (old->refs[i].type) {case REF_TYPE_PTR : +if (!check_ids (old->refs[i].parent_id, cur->refs[i].parent_id, idmap)) +return false;
[Severity: High]
This is a pre-existing issue, but does adding this extra check_ids() call make it easier to trigger the WARN_ON_ONCE() in check_ids() via idmap exhaustion?
Because acquired_refs does not have an explicit limit, a BPF program could acquire many references (for example, via bpf_sk_lookup_tcp) and leak them before a branch merge point. When states_equal() invokes refsafe(), it calls check_ids() for each acquired reference.
The idmap has a fixed size based only on registers and stack slots:
include/linux/bpf_verifier.h:
#define BPF_ID_MAP_SIZE ((MAX_BPF_REG + MAX_BPF_STACK / BPF_REG_SIZE + \
MAX_STACK_ARG_SLOTS) * MAX_CALL_FRAMES)
If a program accumulates enough leaked references, checking them all will run out of idmap slots and trigger the warning:
kernel/bpf/states.c:check_ids() {
...
/* Reached the end of known mappings; haven't seen this id before */
if (idmap->cnt < BPF_ID_MAP_SIZE) {
...
return true;
}
/* We ran out of idmap slots, which should be impossible */
WARN_ON_ONCE(1);
return false;
}Since this patch maps up to two IDs per reference (the reference id and now the parent_id), does this allow exhausting the BPF_ID_MAP_SIZE much faster? Could a user intentionally leak enough references to trigger this warning and potentially panic the kernel if panic_on_warn is set?
Quoted 3 lines
kernel/bpf/states.c +1
-0+break ;case REF_TYPE_IRQ :break ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
In reply to Amery HungThis looks like a bug fix for parent_id tracking support. Should this include:
Quoted 4 lines
commit
89f2be9817e074d02702d22068104fb9fd9aa103Author: Amery Hung <[email protected]> Date: Thu Jun 4 15:09:03 2026 -0700
Quoted 8 lines
bpf: Compare
parent_idinrefsafe()forREF_TYPE_PTR
refsafe()compared each reference's id and type but not itsparent_id, so two states whose PTR references differ only in the parent object they were derived from could be wrongly treated as equivalent and pruned. Fix it by checkingparent_idtoo.Signed-off-by Amery Hung <[email protected]>
This looks like a bug fix for parent_id tracking support. Should this include:
When commit 308c7a0ae885 added parent_id tracking, it updated several safety-checking functions to compare parent_id but missed adding the parent_id check in refsafe() for the REF_TYPE_PTR case. This caused states with different parent objects to be incorrectly treated as equivalent during state pruning.
Quoted 5 lines
kernel/bpf/states.c +0
-0
kernel/bpf/states.c static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c · line 898
Quoted 9 lines
kernel/bpf/states.c +3
-0@@ -890,6 +890,9 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *creturn false;switch (old->refs[i].type) {case REF_TYPE_PTR : +if (!check_ids (old->refs[i].parent_id, cur->refs[i].parent_id, idmap)) +return false; +break ;case REF_TYPE_IRQ :break ;case REF_TYPE_LOCK :
This adds an extra check_ids() call for parent_id. Could this make it easier to trigger the WARN_ON_ONCE() in check_ids() via BPF_ID_MAP_SIZE exhaustion?
Since acquired_refs has no explicit limit, a BPF program could acquire and leak many references (e.g., via bpf_sk_lookup_tcp) before a branch merge point. When states_equal() invokes refsafe(), it calls check_ids() for each acquired reference.
The idmap has a fixed size based only on registers and stack slots:
include/linux/bpf_verifier.h:
#define BPF_ID_MAP_SIZE ((MAX_BPF_REG + MAX_BPF_STACK / BPF_REG_SIZE + \
MAX_STACK_ARG_SLOTS) * MAX_CALL_FRAMES)
If a program accumulates enough leaked references, checking them all will run out of idmap slots and trigger the warning:
kernel/bpf/states.c:check_ids() {
...
/* Reached the end of known mappings; haven't seen this id before */
if (idmap->cnt < BPF_ID_MAP_SIZE) {
...
return true;
}
/* We ran out of idmap slots, which should be impossible */
WARN_ON_ONCE(1);
return false;
}With this patch now checking both reference id and parent_id for REF_TYPE_PTR (doubling the idmap slot usage per reference), does this allow exhausting BPF_ID_MAP_SIZE much faster?
Could a user intentionally leak enough references to trigger this warning and potentially panic the kernel if panic_on_warn is set?
---
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/26983135146
Eduard Zingerman
maintainerRe: [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
Quoted 34 lines · On Thu, 2026-06-04 at 22:59 +0000, [email protected] wrote:
Quoted 4 lines
commit
89f2be9817e074d02702d22068104fb9fd9aa103
Author: Amery Hung <[email protected]>
Date: Thu Jun 4 15:09:03 2026 -0700Quoted 8 lines
bpf: Compare
parent_idinrefsafe()forREF_TYPE_PTR
refsafe()compared each reference's id and type but not itsparent_id, so two states whose PTR references differ only in the parent object they were derived from could be wrongly treated as equivalent and pruned. Fix it by checkingparent_idtoo.Signed-off-by Amery Hung <[email protected]>This looks like a bug fix for
parent_idtracking support. Should this include:Fixes 308c7a0ae885 ("bpf: Refactor object relationship tracking and fix dynptr UAF bug")When commit
308c7a0ae885addedparent_idtracking, it updated several safety-checking functions to compareparent_idbut missed adding theparent_idcheck inrefsafe()for theREF_TYPE_PTRcase. This caused states with different parent objects to be incorrectly treated as equivalent during state pruning.Quoted 10 lines
kernel/bpf/states.c +0
-0@@ -890,6 +890,9 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c return false; switch (old->refs[i].type) {case
REF_TYPE_PTR:kernel/bpf/states.c +2
-0+if (!check_ids (old->refs[i].parent_id, cur->refs[i].parent_id, idmap)) +return false;
Quoted 8 lines
Quoted 4 lines
kernel/bpf/states.c +1
-0+break ;case
REF_TYPE_IRQ:
break;
caseREF_TYPE_LOCK:This adds an extra
check_ids()call forparent_id. Could this make it easier to trigger theWARN_ON_ONCE()incheck_ids()viaBPF_ID_MAP_SIZEexhaustion?
I think the bot has the point here. Let's switch to reallocating idmap or failing check_ids() if there are to many ids (probably an unrealistic scenario).
Re: [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
Quoted 45 lines · Eduard Zingerman
Quoted 34 lines · On Thu, 2026-06-04 at 22:59 +0000, [email protected] wrote:
Quoted 4 lines
commit
89f2be9817e074d02702d22068104fb9fd9aa103Author: Amery Hung <[email protected]> Date: Thu Jun 4 15:09:03 2026 -0700Quoted 8 lines
bpf: Compare
parent_idinrefsafe()forREF_TYPE_PTR
refsafe()compared each reference's id and type but not itsparent_id, so two states whose PTR references differ only in the parent object they were derived from could be wrongly treated as equivalent and pruned. Fix it by checkingparent_idtoo.Signed-off-by Amery Hung <[email protected]>This looks like a bug fix for
parent_idtracking support. Should this include:Fixes 308c7a0ae885 ("bpf: Refactor object relationship tracking and fix dynptr UAF bug")When commit
308c7a0ae885addedparent_idtracking, it updated several safety-checking functions to compareparent_idbut missed adding theparent_idcheck inrefsafe()for theREF_TYPE_PTRcase. This caused states with different parent objects to be incorrectly treated as equivalent during state pruning.Quoted 10 lines
kernel/bpf/states.c +2
-0@@ -890,6 +890,9 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *creturn false;switch (old->refs[i].type) {case REF_TYPE_PTR : +if (!check_ids (old->refs[i].parent_id, cur->refs[i].parent_id, idmap)) +return false;Quoted 8 lines
kernel/bpf/states.c static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c · line 898
Quoted 4 lines
kernel/bpf/states.c +1
-0+break ;case REF_TYPE_IRQ :break ;case REF_TYPE_LOCK :This adds an extra
check_ids()call forparent_id. Could this make it easier to trigger theWARN_ON_ONCE()incheck_ids()viaBPF_ID_MAP_SIZEexhaustion?
Quoted 3 lines
I think the bot has the point here. Let's switch to reallocating idmap or failing
check_ids()if there are to many ids (probably an unrealistic scenario).
Make sense. I will switch to failing check_ids() first since it is unlikely for sane programs.
I will also change bpf_insn_access_aux::ref_id to int as pointed out by sashiko.
Re: [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
Quoted 47 lines · Amery Hung
Quoted 45 lines · Eduard Zingerman
Quoted 42 lines · On Thu, 2026-06-04 at 22:59 +0000, [email protected] wrote:
Quoted 4 lines
commit
89f2be9817e074d02702d22068104fb9fd9aa103Author: Amery Hung <[email protected]> Date: Thu Jun 4 15:09:03 2026 -0700Quoted 8 lines
bpf: Compare
parent_idinrefsafe()forREF_TYPE_PTR
refsafe()compared each reference's id and type but not itsparent_id, so two states whose PTR references differ only in the parent object they were derived from could be wrongly treated as equivalent and pruned. Fix it by checkingparent_idtoo.Signed-off-by Amery Hung <[email protected]>This looks like a bug fix for
parent_idtracking support. Should this include:Fixes 308c7a0ae885 ("bpf: Refactor object relationship tracking and fix dynptr UAF bug")When commit
308c7a0ae885addedparent_idtracking, it updated several safety-checking functions to compareparent_idbut missed adding theparent_idcheck inrefsafe()for theREF_TYPE_PTRcase. This caused states with different parent objects to be incorrectly treated as equivalent during state pruning.Quoted 5 lines
kernel/bpf/states.c +0
-0kernel/bpf/states.c static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c · line 898
Quoted 9 lines
kernel/bpf/states.c +3
-0@@ -890,6 +890,9 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *creturn false;switch (old->refs[i].type) {case REF_TYPE_PTR : +if (!check_ids (old->refs[i].parent_id, cur->refs[i].parent_id, idmap)) +return false; +break ;case REF_TYPE_IRQ :break ;case REF_TYPE_LOCK :This adds an extra
check_ids()call forparent_id. Could this make it easier to trigger theWARN_ON_ONCE()incheck_ids()viaBPF_ID_MAP_SIZEexhaustion?
Quoted 7 lines
Quoted 3 lines
I think the bot has the point here. Let's switch to reallocating idmap or failing
check_ids()if there are to many ids (probably an unrealistic scenario).Make sense. I will switch to failing
check_ids()first since it is unlikely for sane programs.
Actually, looking at it a bit more. I think I would hold on changing check_ids().
This patch should not increase idmap usage. parent_id refers to id and therefore check_ids(parent_id) will reuse an existing slot.
The id_map is indeed more likely to be triggered since there is also an intermediate reference for reference dynptr introduce during the refactor, but that should still be very unlikely under normal usage. check_ids() also already fails in this scenario by returning false. So overall, I am not sure if we need to change it.
WDYT?
Eduard Zingerman
maintainerRe: [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
On Fri, 2026-06-05 at 10:57 -0700, Amery Hung wrote:
[...]
Quoted 6 lines
Actually, looking at it a bit more. I think I would hold on changing
check_ids().This patch should not increase idmap usage.
parent_idrefers to id and thereforecheck_ids(parent_id)will reuse an existing slot.
Quoted 7 lines
The
id_mapis indeed more likely to be triggered since there is also an intermediate reference for reference dynptr introduce during the refactor, but that should still be very unlikely under normal usage.check_ids()also already fails in this scenario by returning false. So overall, I am not sure if we need to change it.WDYT?
I agree that it should be fine to just return false from check_ids() if there is no space in the idmap. However, since not all ids correspond to register/stack slots anymore, I think that WARN_ON_ONCE(1) should be removed.
Re: [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR
Quoted 17 lines · Eduard Zingerman
On Fri, 2026-06-05 at 10:57 -0700, Amery Hung wrote:
[...]
Quoted 12 lines
Actually, looking at it a bit more. I think I would hold on changing
check_ids().This patch should not increase idmap usage.
parent_idrefers to id and thereforecheck_ids(parent_id)will reuse an existing slot.The
id_mapis indeed more likely to be triggered since there is also an intermediate reference for reference dynptr introduce during the refactor, but that should still be very unlikely under normal usage.check_ids()also already fails in this scenario by returning false. So overall, I am not sure if we need to change it.
Quoted 6 lines
Quoted 1 line
WDYT?
I agree that it should be fine to just return false from
check_ids()if there is no space in the idmap. However, since not all ids correspond to register/stack slots anymore, I think thatWARN_ON_ONCE(1)should be removed.
Ack. I will drop WARN_ON_ONCE(1).
PATCH 3/3 selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test
In reply to Amery Hunguse_file_dynptr_slice_after_put_file() reads the dynptr via bpf_dynptr_data(), which always returns NULL for a read-only file dynptr, making the example confusing. Switch to bpf_dynptr_slice(), the correct read API for file dynptrs, and read (rather than write) the slice since it is read-only. The test still fails as expected.
--- tools/testing/selftests/bpf/progs/file_reader_fail.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/progs/file_reader_fail.c +4 -4
@@ -87,7 +87,8 @@ 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; +char buf[1 ]; +const char *data;if (!file)return 0 ;
@@ -95,15 +96,14 @@ int use_file_dynptr_slice_after_put_file(void *ctx)if (bpf_dynptr_from_file (file,0 , &dynptr)) goto out; - data =bpf_dynptr_data (&dynptr,0 ,1 ); + data =bpf_dynptr_slice (&dynptr,0 , buf,sizeof (buf));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 ; +return data[0 ]; out:bpf_dynptr_file_discard (&dynptr);
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH bpf-next v1 3/3] selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The negative selftest uses an uninitialized stack buffer `buf`, causing the verifier to reject…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The negative selftest uses an uninitialized stack buffer buf, causing the verifier to reject the program early and bypass the intended reference leak check. --
commit 2c90a2c3822df01ad7da448a72985505048a4374
Author: Amery Hung <[email protected]>
selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test
This commit updates the use_file_dynptr_slice_after_put_file test to use bpf_dynptr_slice instead of bpf_dynptr_data, since bpf_dynptr_data always returns NULL for read-only file dynptrs. The slice is read rather than written to, while the test is still expected to fail.
Quoted 15 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +2
-1@@ -87,7 +87,8 @@ 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; +char buf[1 ]; +const char *data;if (!file)return 0 ;
tools/testing/selftests/bpf/progs/file_reader_fail.c int use_file_dynptr_slice_after_put_file(void *ctx) · line 99
Quoted 5 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +1
-1@@ -95,15 +96,14 @@ int use_file_dynptr_slice_after_put_file(void *ctx)if (bpf_dynptr_from_file (file,0 , &dynptr)) goto out; - data =bpf_dynptr_data (&dynptr,0 ,1 ); + data =bpf_dynptr_slice (&dynptr,0 , buf,sizeof (buf));
[Severity: Medium]
Will the BPF verifier reject this program early due to the uninitialized stack buffer, masking the actual leak test?
The verifier requires memory passed to helpers like bpf_dynptr_slice() to be initialized. Since buf is uninitialized, the verifier will likely fail with an invalid read from stack error here, bypassing the intended reference leak check.
Would initializing the buffer (e.g., char buf[1] = {0};) allow the test to fail for the expected reason?
Quoted 5 lines
tools/testing/selftests/bpf/progs/file_reader_fail.c +0
-0if (!data) goto out;/* this should fail - file dynptr should be discarded first to prevent resource leak */ bpf_put_file (file);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH bpf-next v1 3/3] selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test
In reply to Amery HungQuoted 8 lines · Amery Hung
use_file_dynptr_slice_after_put_file()reads the dynptr viabpf_dynptr_data(), which always returns NULL for a read-only file dynptr, making the example confusing. Switch tobpf_dynptr_slice(), the correct read API for file dynptrs, and read (rather than write) the slice since it is read-only. The test still fails as expected.Signed-off-by Amery Hung <[email protected]>---
[...]
Kumar Kartikeya Dwivedi
maintainerQuoted 10 lines · Amery Hung
Hi,
The main patchset refactoring object relationship tracking in the verifier has landed and this is a followup that addresses the remaining feedback in v6 [0].
bpf-next makes sense, but Fixes: tag looks missing?
Quoted 9 lines · Kumar Kartikeya Dwivedi
Quoted 7 lines · Amery Hung
Hi,
The main patchset refactoring object relationship tracking in the verifier has landed and this is a followup that addresses the remaining feedback in v6 [0].
Quoted 5 lines
Quoted 3 lines
bpf-next makes sense, but Fixes: tag looks missing?
I will add fix tags to both patch 1 and 2 and respin.
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 9 lines · On Thu, 4 Jun 2026 15:09:01 -0700 you wrote:
Hi,
The main patchset refactoring object relationship tracking in the verifier has landed and this is a followup that addresses the remaining feedback in v6 [0].
[0] https://lore.kernel.org/bpf/[email protected]/
[...]
Here is the summary with links:
- [bpf-next,v1,1/3] bpf: Fix dead error check on acquire_reference() in check_kfunc_call
https://git.kernel.org/bpf/bpf-next/c/a3863aa4f55e - [bpf-next,v1,2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR https://git.kernel.org/bpf/bpf-next/c/41025f441fe6 - [bpf-next,v1,3/3] selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test https://git.kernel.org/bpf/bpf-next/c/d83d4f63cb8f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html