selftests: drv-net: Reload pkt pointer after calling filter_udphdr
Subsystems (4)
PATCH 1/1 selftests: drv-net: Reload pkt pointer after calling filter_udphdr
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.
--- tools/testing/selftests/net/lib/xdp_native.bpf.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
tools/testing/selftests/net/lib/xdp_native.bpf.c +4 -5
@@ -420,7 +420,6 @@ static int xdp_adjst_tail_grow_data(struct xdp_md *ctx, __u16 offset)static int xdp_adjst_tail (struct xdp_md *ctx,__u16 port) { -void *data = (void *)(long )ctx->data;struct udphdr *udph =NULL ;__s32 *adjust_offset, *val;__u32 key, hdr_len;
@@ -432,7 +431,8 @@ static int xdp_adjst_tail(struct xdp_md *ctx, __u16 port)if (!udph)return XDP_PASS ; - hdr_len = (void *)udph - data +sizeof (struct udphdr ); + hdr_len = (void *)udph - (void *)(long )ctx->data + +sizeof (struct udphdr ); key =XDP_ADJST_OFFSET ; adjust_offset =bpf_map_lookup_elem (&map_xdp_setup, &key);if (!adjust_offset)
@@ -572,8 +572,6 @@ static int xdp_adjst_head_grow_data(struct xdp_md *ctx, __u64 hdr_len,static int xdp_head_adjst (struct xdp_md *ctx,__u16 port) { -void *data_end = (void *)(long )ctx->data_end; -void *data = (void *)(long )ctx->data;struct udphdr *udph_ptr =NULL ;__u32 key, size, hdr_len;__s32 *val;
@@ -584,7 +582,8 @@ static int xdp_head_adjst(struct xdp_md *ctx, __u16 port)if (!udph_ptr)return XDP_PASS ; - hdr_len = (void *)udph_ptr - data +sizeof (struct udphdr ); + hdr_len = (void *)udph_ptr - (void *)(long )ctx->data + +sizeof (struct udphdr ); key =XDP_ADJST_OFFSET ; val =bpf_map_lookup_elem (&map_xdp_setup, &key);
Signature · 1 line
2.47.3
Quoted 7 lines · Amery Hung
Fix a verification failure.
filter_udphdr()callsbpf_xdp_pull_data(), which will invalidate all pkt pointers. Therefore, allctx->dataloaded beforefilter_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->dataafterfilter_udphdr()when it is first used.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Thu, 25 Sep 2025 09:14:52 -0700 you wrote:
Fix a verification failure.
filter_udphdr()callsbpf_xdp_pull_data(), which will invalidate all pkt pointers. Therefore, allctx->dataloaded beforefilter_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->dataafterfilter_udphdr()when it is first used.[...]
Here is the summary with links:
- [net-next,1/1] selftests: drv-net: Reload pkt pointer after calling filter_udphdr
https://git.kernel.org/netdev/net-next/c/11ae737efea1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html