BPF List
 help / color / mirror / Atom feed
* [PATCH 0/2] bpf: support for non_null ptr detection with JEQ/JNE with register operand
@ 2026-03-02 16:17 Cupertino Miranda
  2026-03-02 16:17 ` [PATCH 1/2] bpf: detect non null pointer with register operand in JEQ/JNE Cupertino Miranda
  2026-03-02 16:17 ` [PATCH 2/2] selftests/bpf: tests to non_null ptr detection using " Cupertino Miranda
  0 siblings, 2 replies; 7+ messages in thread
From: Cupertino Miranda @ 2026-03-02 16:17 UTC (permalink / raw)
  To: bpf; +Cc: Cupertino Miranda, David Faust, Jose Marchesi, Elena Zannoni

Hi everyone,

This patch is a small extension to allow the verifier to mark non_null
pointers as such when the condition that makes the runtime check uses a
register with the value 0 instead of the immediate 0.

The following example, is the output within bpftune when compiling BPF
code with an earlier version of GCC. The same also happens in BPF
selftests with latest master GCC.

  bpftune: libbpf: prog 'probe_cong_iter': -- BEGIN PROG LOAD LOG --
  0: R1=ctx() R10=fp0
  0: (b7) r0 = 0                        ; R0_w=0
  1: (7b) *(u64 *)(r10 -16) = r0        ; R0_w=0 R10=fp0 fp-16_w=0
  2: (7b) *(u64 *)(r10 -8) = r0         ; R0_w=0 R10=fp0 fp-8_w=0
  3: (79) r1 = *(u64 *)(r1 +8)          ; R1_w=trusted_ptr_or_null_sock_common(id=1)
  4: (1d) if r1 == r0 goto pc+9         ; R0_w=0 R1_w=trusted_ptr_or_null_sock_common(id=1)
  5: (85) call bpf_skc_to_tcp_sock#137
  R1 type=trusted_ptr_or_null_ expected=sock_common, sock, tcp_sock, xdp_sock, ptr_, trusted_ptr_
  processed 6 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  -- END PROG LOAD LOG --
  bpftune: libbpf: prog 'probe_cong_iter': failed to load: -EACCES
  bpftune: libbpf: failed to load object 'probe_bpf'

With this patch, R1 is properly marked as non_null and the call to
bpf_skc_to_tcp_sock#137 is further accepted by the verifier.

No regressions for clang.

With GCC we get the following improvements:
  Before:
    Summary: 566/5032 PASSED, 113 SKIPPED, 131 FAILED
  After
    Summary: 569/5046 PASSED, 113 SKIPPED, 128 FAILED

1480c1480
< #155     jit_probe_mem:FAIL
---
> #155     jit_probe_mem:OK
3918c3918
< #452/19  task_kfunc/task_kfunc_xchg_unreleased:FAIL
---
> #452/19  task_kfunc/task_kfunc_xchg_unreleased:OK
3934c3934
< #452     task_kfunc:FAIL
---
> #452     task_kfunc:OK
3942,3943c3942,3943
< #454/5   task_local_storage/uptr_basic:FAIL
< #454/6   task_local_storage/uptr_across_pages:FAIL
---
> #454/5   task_local_storage/uptr_basic:OK
> #454/6   task_local_storage/uptr_across_pages:OK
4011,4012c4011,4012
< #476/1   test_bpf_ma/batch_alloc_free:FAIL
< #476/2   test_bpf_ma/free_through_map_free:FAIL
---
> #476/1   test_bpf_ma/batch_alloc_free:OK
> #476/2   test_bpf_ma/free_through_map_free:OK
4015c4015
< #476     test_bpf_ma:FAIL
---
> #476     test_bpf_ma:OK

Looking forward to your comments.

Cheers,
Cupertino

Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com>
Cc: David Faust  <david.faust@oracle.com>
Cc: Jose Marchesi  <jose.marchesi@oracle.com>
Cc: Elena Zannoni  <elena.zannoni@oracle.com>

Cupertino Miranda (2):
  bpf: detect non null pointer with register operand in JEQ/JNE.
  selftests/bpf: tests to non_null ptr detection using register operand
    in JEQ/JNE

 kernel/bpf/verifier.c                         |   9 +-
 .../bpf/progs/verifier_jeq_infer_not_null.c   | 187 ++++++++++++++++++
 2 files changed, 193 insertions(+), 3 deletions(-)

-- 
2.47.3


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

end of thread, other threads:[~2026-03-03 18:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02 16:17 [PATCH 0/2] bpf: support for non_null ptr detection with JEQ/JNE with register operand Cupertino Miranda
2026-03-02 16:17 ` [PATCH 1/2] bpf: detect non null pointer with register operand in JEQ/JNE Cupertino Miranda
2026-03-02 16:58   ` bot+bpf-ci
2026-03-03 17:51   ` Eduard Zingerman
2026-03-02 16:17 ` [PATCH 2/2] selftests/bpf: tests to non_null ptr detection using " Cupertino Miranda
2026-03-03 18:12   ` Eduard Zingerman
2026-03-03 18:38     ` Cupertino Miranda

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