Re: [PATCH bpf] bpf: Fix verifier WARN on narrow read of bpf_tcp_sock u64 fields

From: Alexei Starovoitov

Date: Fri Oct 16 2026 - 11:15:26 EST


On Fri, Oct 16, 2026 at 07:16 PM Jiayuan Chen <jiayuan.chen@xxxxxxxxx> wrote:
> Just disallow the narrower access by matching the whole u64 range of the
> two fields, so it is turned down at check time:
>
> invalid tcp_sock access off=84 size=4

Pls add a selftest as patch 2.
progs/verifier_sock.c already has
"bpf_tcp_sock(skb->sk): tp->bytes_acked".
Copy it and do u32 load at offsetof(bytes_received) + 4 and
at offsetof(bytes_acked) + 4 with
__failure __msg("invalid tcp_sock access") __failure_unpriv.
cgroup/skb is loadable by unpriv, so both modes should be covered.
See
commit ba578b87fe2b ("selftests/bpf: Test invalid narrower ctx load")
that Paul added for the same warn in ctx fields.

I'm hesitating to apply it as-is, since all earlier fixes for this
warn came with a test.

pw-bot: cr