Skip to content

Commit cdf7022

Browse files
ameryhunggregkh
authored andcommitted
selftests: drv-net: Reload pkt pointer after calling filter_udphdr
commit 11ae737efea10a8cc1c48b6288bde93180946b8c upstream. Fix a verification failure. filter_udphdr() calls bpf_xdp_pull_data(), which will invalidate all pkt pointers. Therefore, all ctx->data loaded before filter_udphdr() cannot be used. Reload it to prevent verification errors. The error may not appear on some compiler versions if they decide to load ctx->data after filter_udphdr() when it is first used. Fixes: efec2e55bdef ("selftests: drv-net: Pull data before parsing headers") Signed-off-by: Amery Hung <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c42338b commit cdf7022

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

tools/testing/selftests/net/lib/xdp_native.bpf.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ static int xdp_adjst_tail_grow_data(struct xdp_md *ctx, __u16 offset)
420420

421421
static int xdp_adjst_tail(struct xdp_md *ctx, __u16 port)
422422
{
423-
void *data = (void *)(long)ctx->data;
424423
struct udphdr *udph = NULL;
425424
__s32 *adjust_offset, *val;
426425
__u32 key, hdr_len;
@@ -432,7 +431,8 @@ static int xdp_adjst_tail(struct xdp_md *ctx, __u16 port)
432431
if (!udph)
433432
return XDP_PASS;
434433

435-
hdr_len = (void *)udph - data + sizeof(struct udphdr);
434+
hdr_len = (void *)udph - (void *)(long)ctx->data +
435+
sizeof(struct udphdr);
436436
key = XDP_ADJST_OFFSET;
437437
adjust_offset = bpf_map_lookup_elem(&map_xdp_setup, &key);
438438
if (!adjust_offset)
@@ -572,8 +572,6 @@ static int xdp_adjst_head_grow_data(struct xdp_md *ctx, __u64 hdr_len,
572572

573573
static int xdp_head_adjst(struct xdp_md *ctx, __u16 port)
574574
{
575-
void *data_end = (void *)(long)ctx->data_end;
576-
void *data = (void *)(long)ctx->data;
577575
struct udphdr *udph_ptr = NULL;
578576
__u32 key, size, hdr_len;
579577
__s32 *val;
@@ -584,7 +582,8 @@ static int xdp_head_adjst(struct xdp_md *ctx, __u16 port)
584582
if (!udph_ptr)
585583
return XDP_PASS;
586584

587-
hdr_len = (void *)udph_ptr - data + sizeof(struct udphdr);
585+
hdr_len = (void *)udph_ptr - (void *)(long)ctx->data +
586+
sizeof(struct udphdr);
588587

589588
key = XDP_ADJST_OFFSET;
590589
val = bpf_map_lookup_elem(&map_xdp_setup, &key);

0 commit comments

Comments
 (0)