Skip to content

Commit d1a358b

Browse files
author
weiyanhua
committed
fix bug: offset is outside of the packet.
1. xdp_loader: ./xdp_loader --dev lo -S --progsec xdp_packet_parser verb 2. Problem Description: libbpf: load bpf program failed: Permission denied libbpf: -- BEGIN DUMP LOG --- libbpf: 0: (bf) r6 = r1 1: (b7) r1 = 2 2: (61) r2 = *(u32 *)(r6 +0) 3: (07) r2 += 12 4: (61) r3 = *(u32 *)(r6 +4) 5: (2d) if r2 > r3 goto pc+7 R1=inv2 R2=pkt(id=0,off=12,r=12,imm=0) R3=pkt_end(id=0,off=0,imm=0) R6=ctx(id=0,off=0,imm=0) R10=fp0,call_-1 6: (71) r1 = *(u8 *)(r2 +0) invalid access to packet, off=12 size=1, R2(id=0,off=12,r=12) R2 offset is outside of the packet libbpf: -- END LOG -- libbpf: failed to load program 'xdp_packet_parser' libbpf: failed to load object 'xdp_prog_kern.o' ERR: loading BPF-OBJ file(xdp_prog_kern.o) (-22): Invalid argument Signed-off-by: weiyanhua <[email protected]>
1 parent 4bfd9df commit d1a358b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packet01-parsing/xdp_prog_kern.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static __always_inline int parse_ethhdr(struct hdr_cursor *nh,
3636
/* Byte-count bounds check; check if current pointer + size of header
3737
* is after data_end.
3838
*/
39-
if (nh->pos + 1 > data_end)
39+
if (nh->pos + hdrsize > data_end)
4040
return -1;
4141

4242
nh->pos += hdrsize;

0 commit comments

Comments
 (0)