• Yafang Shao's avatar
    selftests/bpf: Add selftest for allow_ptr_leaks · 0072e362
    Yafang Shao authored
    - Without prev commit
    
      $ tools/testing/selftests/bpf/test_progs --name=tc_bpf
      #232/1   tc_bpf/tc_bpf_root:OK
      test_tc_bpf_non_root:PASS:set_cap_bpf_cap_net_admin 0 nsec
      test_tc_bpf_non_root:PASS:disable_cap_sys_admin 0 nsec
      0: R1=ctx(off=0,imm=0) R10=fp0
      ; if ((long)(iph + 1) > (long)skb->data_end)
      0: (61) r2 = *(u32 *)(r1 +80)         ; R1=ctx(off=0,imm=0) R2_w=pkt_end(off=0,imm=0)
      ; struct iphdr *iph = (void *)(long)skb->data + sizeof(struct ethhdr);
      1: (61) r1 = *(u32 *)(r1 +76)         ; R1_w=pkt(off=0,r=0,imm=0)
      ; if ((long)(iph + 1) > (long)skb->data_end)
      2: (07) r1 += 34                      ; R1_w=pkt(off=34,r=0,imm=0)
      3: (b4) w0 = 1                        ; R0_w=1
      4: (2d) if r1 > r2 goto pc+1
      R2 pointer comparison prohibited
      processed 5 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
      test_tc_bpf_non_root:FAIL:test_tc_bpf__open_and_load unexpected error: -13
      #233/2   tc_bpf_non_root:FAIL
    
    - With prev commit
    
      $ tools/testing/selftests/bpf/test_progs --name=tc_bpf
      #232/1   tc_bpf/tc_bpf_root:OK
      #232/2   tc_bpf/tc_bpf_non_root:OK
      #232     tc_bpf:OK
      Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
    Signed-off-by: default avatarYafang Shao <laoar.shao@gmail.com>
    Link: https://lore.kernel.org/r/20230823020703.3790-3-laoar.shao@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    0072e362
tc_bpf.c 13 KB