From 6caab6f704bffb562e9a39a82678cefea6730ce0 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Thu, 24 Sep 2026 19:53:30 +0530 Subject: [PATCH] Tests: Rank the ctx-field case on a scalar field, not the packet pointer xdp_md.data is a u32 in C, but the verifier tracks it as a packet pointer and rejects 32-bit arithmetic on it: "R0 32-bit pointer arithmetic prohibited", the same for a C program, which is why C casts it through (void *)(long) first. The u32 ranking the test pins is the correct one; it just has to be pinned on a field that is a scalar to the verifier too. ingress_ifindex is. Co-Authored-By: Claude Fable 5.1 --- tests/passing_tests/vmlinux/ctx_field_rank.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/passing_tests/vmlinux/ctx_field_rank.py b/tests/passing_tests/vmlinux/ctx_field_rank.py index d8456d0..1699858 100644 --- a/tests/passing_tests/vmlinux/ctx_field_rank.py +++ b/tests/passing_tests/vmlinux/ctx_field_rank.py @@ -1,7 +1,12 @@ # A sub-register context field is loaded widened to i64, but C ranks it by -# its declared width: xdp_md.data is a u32, so data - k with a c_int32 k is -# a u32 subtraction (the result is cut to 32 bits and zero-extended), not a -# 64-bit one. +# its declared width: xdp_md.ingress_ifindex is a u32, so ifindex - k with a +# c_int32 k is a u32 subtraction (the result is cut to 32 bits and +# zero-extended), not a 64-bit one. +# +# Not xdp_md.data: it is a u32 in C too, but the verifier tracks it as a +# packet pointer and rejects 32-bit arithmetic on it ("R0 32-bit pointer +# arithmetic prohibited"), for C programs as much as for this one. That is +# why C casts it through (void *)(long) before doing anything with it. from ctypes import c_int32, c_int64 from pythonbpf import bpf, section, bpfglobal, compile from vmlinux import struct_xdp_md @@ -11,7 +16,7 @@ from vmlinux import struct_xdp_md @section("xdp") def prog(ctx: struct_xdp_md) -> c_int64: k = c_int32(1) - d = ctx.data - k + d = ctx.ingress_ifindex - k return c_int64(d)