On Tue Dec 1, 2026 at 9:17 AM UTC, Björn Töpel wrote:
> Each call to bpf_tcp_gen_syncookie(), bpf_tcp_raw_gen_syncookie_ipv4() > or bpf_tcp_raw_gen_syncookie_ipv6() reads th->doff twice. The helper > first checks that th->doff matches th_len, the header length that the > verifier allowed. tcp_parse_mss_option(), called directly or through > tcp_get_syncookie_mss(), then reads th->doff again to find the end of > the options. > > The header can change between the two reads when userspace can write > the memory it lives in. That is the case for packets in the UMEM of an > AF_XDP zero-copy socket, and for values of a BPF_F_MMAPABLE array map. > If th->doff grows from 5 to 15 in between, the option walk reads 40 > bytes past the header that the verifier allowed, and faults when the > header ends a mapping. > > Pass the checked length to tcp_parse_mss_option(), so that each call > reads th->doff once. > > A header that changes during the call can still give another MSS or > cookie, as any rewritten packet would, but the walk stays within > th_len. The helpers that check cookies read no length from the header > and stay as they are. The functions that take the new argument have no > other callers. > > Overhead; This costs nothing measurable. A BPF_PROG_TEST_RUN loop that > calls bpf_tcp_raw_gen_syncookie_ipv4() on a 40-byte header takes 136 > ns per run with and without this patch. > > Found by an AI code review agent, and reproduced in QEMU without > kernel changes. An XDP program on an igb zero-copy queue calls the raw > IPv4 helper on a header in the last 20 bytes of the UMEM, while a > userspace thread flips th->doff between 5 and 15. The kernel oopses in > tcp_parse_mss_option() on the guard page after the UMEM within > seconds. A BPF_PROG_TEST_RUN program with the header at the end of an > mmap()ed array map value oopses the same way. With this patch, neither > oopses, and the test_progs tests xdp_synproxy, btf_skc_cls_ingress, > tcp_custom_syncookie and cls_redirect pass. > > Fixes: 70d66244317e ("bpf: add bpf_tcp_gen_syncookie helper") > Fixes: 33bf9885040c ("bpf: Add helpers to issue and check SYN cookies in XDP") > Signed-off-by: Björn Töpel <bjo…@kernel.org> > --- > include/net/tcp.h | 8 ++++---- > net/core/filter.c | 8 ++++---- > net/ipv4/tcp_input.c | 8 ++++---- > net/ipv4/tcp_ipv4.c | 4 ++-- > net/ipv6/tcp_ipv6.c | 4 ++-- > 5 files changed, 16 insertions(+), 16 deletions(-)
This is more net tree material. If so Ack. Or we can wait for netdev folks to ack it.