Files
python-bpf/tests/failing_tests/vmlinux/ctx_data_offset_too_big.py
Pragyansh Chaturvedi 6a859ac0cd Core: Special-case packet-pointer context fields in arithmetic
xdp_md.data/data_end/data_meta and __sk_buff.data/data_end/data_meta are
u32 in C but packet pointers to the verifier, which rewrites their load
into a pointer load and prohibits 32-bit arithmetic on them. The
signedness rules ranked them as u32, so ctx.data - k lowered to a 32-bit
add (w0 += -1) and was rejected; C code avoids this with a cast through
(void *)(long).

A binary operation with a packet-pointer operand now bypasses the usual
arithmetic conversions: the pointer is used at 64 bits, an offset added
to or subtracted from it is taken as an unsigned 16-bit value (truncated,
zero-extended) because the verifier only tracks packet ranges up to
MAX_PACKET_OFF (0xffff), and the result is a 64-bit value. Pointer minus
pointer is an ordinary 64-bit length. A constant offset outside
0..65535, any other operator, and offset minus pointer are compile
errors rather than code the verifier would reject. Local inference
agrees (64-bit unsigned).

Only direct field reads are recognised; a local copied from one is an
integer again, and comparisons between packet pointers are the next site
of the same rule.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 11:58:42 +05:30

22 lines
441 B
Python

# 70000 cannot be a packet offset: the verifier tracks packet ranges only
# up to 0xffff. Rejected at compile time rather than silently wrapped.
from ctypes import c_int64
from pythonbpf import bpf, section, bpfglobal, compile
from vmlinux import struct_xdp_md
@bpf
@section("xdp")
def prog(ctx: struct_xdp_md) -> c_int64:
d = ctx.data + 70000
return c_int64(d)
@bpf
@bpfglobal
def LICENSE() -> str:
return "GPL"
compile()