Core: Let a packet pointer be narrowed on a store, as C does

convert() refused to narrow a packet pointer below 64 bits, on the
premise that the verifier only accepts one at 64 bits. That is true of
arithmetic, not of stores: upstream's cgroup_skb_direct_packet_access
stores skb->data_end into a __u32 global, and CI's verifier level
accepted exactly that on #105. Merging master brought that selftest in
and the refusal rejected it. Narrowing now truncates, and the result is
an ordinary integer. ctx_data_narrow_store.py moves to the passing
tests. Keeping the pointer when a local is declared narrower belongs to
allocation (widest type ever stored), noted for later.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pragyansh Chaturvedi
2026-09-25 23:21:12 +05:30
parent 4cb5f01374
commit aa612a4151
4 changed files with 14 additions and 15 deletions

View File

@ -17,8 +17,14 @@ The field read gives its value a PktPtrTy descriptor (a 64-bit unsigned
IntTy tagged with the verifier's kind), and the rules key on that descriptor,
so they follow the pointer through locals (`d = ctx.data`), through
`d + 14`, and into comparisons (`ctx.data + 34 > ctx.data_end` is a 64-bit
unsigned compare). packet-end pointers take no offset at all, and nothing
narrows a packet pointer below 64 bits.
unsigned compare). packet-end pointers take no offset at all.
Storing a packet pointer into a narrower slot truncates it, as C does, and the
result is an ordinary integer: the verifier forbids 32-bit *arithmetic* on a
packet pointer, not a 32-bit store of one (upstream's
cgroup_skb_direct_packet_access stores data_end into a __u32 global). Keeping
the pointer when a local is declared narrower is a job for allocation, which
could give such a slot the widest type ever stored into it.
"""
import ast