From: sashiko-bot@kernel.org
To: "Chris Mason" <mason@kernel.org>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 1/2] bpf: Don't use an unset inner transport header
Date: Sat, 05 Dec 2026 13:30:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-251568@kernel.org> (raw)
In-Reply-To: <20261205012513.15379-2-mason@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] bpf: s16 cast in bpf_skb_net_hdr_pop() truncates inner
transport offset
- [Medium] bpf: bpf_skb_net_hdr_pop() misplaces inner_transport_header
and masks GRO bug
--
commit 1a1076a6002794e99517c8507268d7aa9c97eab5
Author: Chris Mason <mason@kernel.org>
bpf: Don't use an unset inner transport header
This commit casts skb_inner_transport_offset(skb) to s16 in
bpf_skb_net_hdr_pop() so that an unset inner_transport_header whose u16
offset wrapped after a headroom reduction is still reset to off.
> diff --git a/net/core/filter.c b/net/core/filter.c
> index ea20fd2be65c0..892e20291283d 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -3456,9 +3456,12 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len)
> /* It was in the removed bytes or before skb->data. */
> skb_set_transport_header(skb, off);
> }
> - /* Do not leave the inner transport header in front of @off. */
> + /*
> + * Do not leave the inner transport header in front of @off. If
> + * nobody has set it, its offset can have wrapped.
> + */
> if (skb->encapsulation &&
> - skb_inner_transport_offset(skb) < (int)off)
> + (s16)skb_inner_transport_offset(skb) < (int)off)
> skb_set_inner_transport_header(skb, off);
> }
[Severity: Medium]
Can casting skb_inner_transport_offset(skb) to s16 clobber valid offsets
>= 32768 and fail to reset offsets < -32768?
virtio_net_hdr_tnl_to_skb() can set inner_transport_header from csum_start
up to U16_MAX - 1 via skb_partial_csum_set(). Under the s16 cast, offsets
>= 32768 sign-extend negative and are overwritten with off.
If skb->encapsulation stays set (for example in bpf_skb_proto_6_to_4()),
that places inner_transport_header behind the outer transport_header,
underflowing thlen in skb_gso_transport_seglen().
In the other direction, RX allows headroom up to SKB_MAX_RX_HEADROOM
(32767) and bpf_skb_generic_pop() pulls up to 4095 bytes before this
check. An unset inner_transport_header at 0 then has an offset below
-32768, which wraps positive under s16 and skips the reset.
[Severity: Medium]
Does resetting a wrapped inner_transport_header to off misplace it when
skb->encapsulation stays set, while leaving the GRO bug unfixed?
When bpf_skb_net_hdr_pop() is not followed by bpf_skb_clear_encap() (for
instance in bpf_skb_adjust_room() without decap flags, or when decapping
only the outer layer of a nested tunnel), off points to the network header
in BPF_ADJ_ROOM_MAC mode.
qdisc_pkt_len_segs_init() then reads the IP header as a TCP header at
skb_inner_transport_offset(skb), dropping packets with
SKB_DROP_REASON_SKB_BAD_GSO or miscomputing gso_segs and pkt_len.
This also leaves the root cause in place: the fraglist early return in
tcp{4,6}_gro_complete() and udp{4,6}_gro_complete() omits setting
inner_transport_header, so non-BPF forwarded encapsulated fraglist-GRO
packets are still dropped in qdisc_pkt_len_segs_init().
Fixing fraglist GRO completion to set inner_transport_header and avoiding
u16 underflow of unset inner headers in skb_headers_offset_update() would
handle both BPF and non-BPF paths without the s16 heuristic.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205012513.15379-1-mason@kernel.org?part=1
next prev parent reply other threads:[~2026-12-05 13:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 12:56 [PATCH bpf 0/2] bpf: fix skb->transport_header after a decap Chris Mason
2026-12-05 12:57 ` [PATCH bpf 1/2] bpf: Don't use an unset inner transport header Chris Mason
2026-12-05 13:30 ` sashiko-bot [this message]
2026-12-05 12:58 ` [PATCH bpf 2/2] bpf: Keep skb->transport_header for ESP offload Chris Mason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-251568@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=mason@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox