bpf: Emit verbose message when prog-specific btf_struct_access rejects a write
PATCH 1/1 bpf: Emit verbose message when prog-specific btf_struct_access rejects a write
From: Alexei Starovoitov <[email protected]>
When BPF_WRITE goes through a PTR_TO_BTF_ID register, check_ptr_to_btf_access() delegates to env->ops->btf_struct_access(). Most implementations (bpf_scx_btf_struct_access, tc_cls_act_btf_struct_access, etc.) return -EACCES for disallowed fields without logging anything, so the verifier rejects the program with an empty message. For example a scx program doing
1: R1=trusted_ptr_task_struct()
...
4: (7b) *(u64 *)(r1 +0) = r2
verification time 83 usec
the program is rejected
leaves the user guessing which field is off-limits. Emit verbose message.
--- kernel/bpf/verifier.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/bpf/verifier.c +4 -0
@@ -5786,6 +5786,10 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,return -EFAULT ; } ret = env->ops->btf_struct_access (&env->log, reg, off, size); +if (ret <0 ) +verbose (env, +"%s cannot write into ptr_%s at off=%d size=%d\n" , +reg_arg_name (env, argno), tname, off, size); }else {/* Writes are permitted with default btf_struct_access for * program allocated objects (which always have id > 0),
Signature · 1 line
2.53.0-Meta
Quoted 14 lines · Alexei Starovoitov
From: Alexei Starovoitov <[email protected]>
When
BPF_WRITEgoes through aPTR_TO_BTF_IDregister,check_ptr_to_btf_access()delegates toenv->ops->btf_struct_access(). Most implementations (bpf_scx_btf_struct_access,tc_cls_act_btf_struct_access, etc.) return-EACCESfor disallowed fields without logging anything, so the verifier rejects the program with an empty message. For example a scx program doing1: R1=trusted_ptr_task_struct()
...
4: (7b) *(u64 *)(r1 +0) = r2
verification time 83 usec
the program is rejected
Quoted 4 lines
leaves the user guessing which field is off-limits. Emit verbose message.
Signed-off-by Alexei Starovoitov <[email protected]>
Quoted 19 lines
--- kernel/bpf/verifier.c | 4 ++++ 1 file changed, 4 insertions(+)kernel/bpf/verifier.c +4
-0@@ -5786,6 +5786,10 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,return -EFAULT ; } ret = env->ops->btf_struct_access (&env->log, reg, off, size); +if (ret <0 ) +verbose (env, +"%s cannot write into ptr_%s at off=%d size=%d\n" , +reg_arg_name (env, argno), tname, off, size); }else {/* Writes are permitted with default btf_struct_access for * program allocated objects (which always have id > 0),
Quoted 14 lines · Alexei Starovoitov
From: Alexei Starovoitov <[email protected]>
When
BPF_WRITEgoes through aPTR_TO_BTF_IDregister,check_ptr_to_btf_access()delegates toenv->ops->btf_struct_access(). Most implementations (bpf_scx_btf_struct_access,tc_cls_act_btf_struct_access, etc.) return-EACCESfor disallowed fields without logging anything, so the verifier rejects the program with an empty message. For example a scx program doing1: R1=trusted_ptr_task_struct() ... 4: (7b) *(u64 *)(r1 +0) = r2 verification time 83 usec the program is rejected
Quoted 4 lines
leaves the user guessing which field is off-limits. Emit verbose message.
Signed-off-by Alexei Starovoitov <[email protected]>
Indeed, e.g. bpf_scx_btf_struct_access() does not emit any verifier log for failure. So it makes sense to have a generic verifier log after env->ops->btf_struct_access().
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Mon, 15 Jun 2026 16:21:46 -0700 you wrote:
From: Alexei Starovoitov <[email protected]>
When
BPF_WRITEgoes through aPTR_TO_BTF_IDregister,check_ptr_to_btf_access()delegates toenv->ops->btf_struct_access(). Most implementations (bpf_scx_btf_struct_access,tc_cls_act_btf_struct_access, etc.) return-EACCESfor disallowed fields without logging anything, so the verifier rejects the program with an empty message. For example a scx program doing[...]
Here is the summary with links:
- [bpf-next] bpf: Emit verbose message when prog-specific btf_struct_access rejects a write
https://git.kernel.org/bpf/bpf/c/a933bade82b9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html