[bug report] selftests/bpf: Add C tests for reference tracking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Joe Stringer,

Commit de375f4e91e3 ("selftests/bpf: Add C tests for reference
tracking") from Oct 2, 2018 (linux-next), leads to the following
Smatch static checker warning:

	./tools/testing/selftests/bpf/progs/test_sk_lookup_kern.c:70 sk_lookup_success()
	warn: potential pointer math issue ('tuple' is a 288 bit pointer)

./tools/testing/selftests/bpf/progs/test_sk_lookup_kern.c
    55 SEC("?tc")
    56 int sk_lookup_success(struct __sk_buff *skb)
    57 {
    58         void *data_end = (void *)(long)skb->data_end;
    59         void *data = (void *)(long)skb->data;
    60         struct ethhdr *eth = (struct ethhdr *)(data);
    61         struct bpf_sock_tuple *tuple;
    62         struct bpf_sock *sk;
    63         size_t tuple_len;
    64         bool ipv4;
    65 
    66         if (eth + 1 > data_end)
    67                 return TC_ACT_SHOT;
    68 
    69         tuple = get_tuple(data, sizeof(*eth), data_end, eth->h_proto, &ipv4);
--> 70         if (!tuple || tuple + sizeof *tuple > data_end)
                             ^^^^^^^^^^^^^^^^^^^^^
This is pointer math.  It should be "tuple + 1" or (u8 *)tuple + sizeof(*tuple).

    71                 return TC_ACT_SHOT;
    72 
    73         tuple_len = ipv4 ? sizeof(tuple->ipv4) : sizeof(tuple->ipv6);
    74         sk = bpf_sk_lookup_tcp(skb, tuple, tuple_len, BPF_F_CURRENT_NETNS, 0);
    75         bpf_printk("sk=%d\n", sk ? 1 : 0);
    76         if (sk)
    77                 bpf_sk_release(sk);
    78         return sk ? TC_ACT_OK : TC_ACT_UNSPEC;
    79 }

regards,
dan carpenter




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux