Skip to content

Commit 26d25c0

Browse files
committed
experiment01-tailgrow: try recommentation but it fails
This shows the code after Daniel's idea for change in PR #123 The code can now pass the verifier checks, but it will drop all packets, because the offset is the packet lenght and doing +1 will put us over the packet lenght. Thus, the if-check against data_end will cause a XDP_DROP. The +1 is needed to pass the verifier checks. Using XDP_DROP for this case, to make it easier to identify the problem via using xdpdump[1] ./xdpdump -v -i mlx5p1 --rx-capture entry,exit -x [1] https://github.com/xdp-project/xdp-tools/tree/master/xdp-dump Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
1 parent 0bbd18c commit 26d25c0

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

experiment01-tailgrow/xdp_prog_kern3.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
#include <bpf/bpf_helpers.h>
44

55
/*
6-
* This BPF-prog will FAIL, due to verifier rejecting it.
6+
* This BPF-prog will drop all packets, but pass verifier checks.
77
*
8-
* General idea: Use packet length to find and access last byte in
9-
* packet. The verifier cannot see this is safe, as it cannot deduce
10-
* the packet length at verification time.
8+
* General idea: Use packet length to find and access last byte.
119
*/
1210

1311
SEC("xdp_fail1")
@@ -18,29 +16,22 @@ int _xdp_fail1(struct xdp_md *ctx)
1816
unsigned char *ptr;
1917
void *pos;
2018

21-
/* (Correct me if I'm wrong)
22-
*
23-
* The verifier cannot use this packet length calculation as
24-
* part of its static analysis. It chooses to use zero as the
25-
* offset value static value.
26-
*/
2719
unsigned int offset = data_end - data;
2820

2921
pos = data;
22+
offset &= 0x7FFF; /* Bound/limit max value to help verifier */
3023

31-
if (pos + offset > data_end)
32-
goto out;
24+
pos += offset;
3325

34-
/* Fails at this line with:
35-
* "invalid access to packet, off=-1 size=1, R1(id=2,off=0,r=0)"
36-
* "R1 offset is outside of the packet"
37-
*
38-
* Because verifer used offset==0 it thinks that we are trying
39-
* to access (data - 1), which is not within [data,data_end)
26+
/* Below +1 will cause all packet to be dropped, as it will be
27+
* longer than packet length (just calc as offset).
4028
*/
41-
ptr = pos + (offset - sizeof(*ptr));
29+
if (pos + 1 > data_end)
30+
return XDP_DROP;
31+
32+
ptr = pos;
4233
if (*ptr == 0xFF)
4334
return XDP_ABORTED;
44-
out:
35+
4536
return XDP_PASS;
4637
}

0 commit comments

Comments
 (0)