From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 2/4] bpf: Add check iph->ihl < 5 in lwt
Date: Fri, 29 May 2026 16:06:10 +0000 [thread overview]
Message-ID: <20260529160610.E9DDD1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260529151351.69911-3-leon.hwang@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] bpf_lwt_push_ip_encap updates skb->csum incorrectly for CHECKSUM_COMPLETE packets by calling skb_postpush_rcsum() before calculating the IP header checksum.
- [High] handle_gso_encap() hardcodes the inner IPv4 header length to 20 bytes, ignoring IP options, which leads to reading garbage data as transport headers.
--
commit f2ce106c7be32fdcff1b6d3eb89a4fe4496a86d1
Author: Leon Hwang <leon.hwang@linux.dev>
Subject: bpf: Add check iph->ihl < 5 in lwt
This commit adds a validation check for the IP header length (ihl) in the BPF
lightweight tunnel IP encapsulation path. It ensures that the header length is
at least 5 (20 bytes) to prevent an infinite loop in ip_fast_csum() on certain
architectures like MIPS.
Link: https://lore.kernel.org/bpf/20260525150010.CDEBA1F000E9@smtp.kernel.org/
> diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
> index 8009e427851f1..c306120e11d29 100644
> --- a/net/core/lwt_bpf.c
> +++ b/net/core/lwt_bpf.c
> @@ -613,7 +613,7 @@ int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress)
> iph = (struct iphdr *)buff;
> if (iph->version == 4) {
> ipv4 = true;
> - if (unlikely(len < iph->ihl * 4))
> + if (unlikely(iph->ihl < 5 || len < iph->ihl * 4))
[Severity: High]
This isn't a bug introduced by this patch, but since we are validating the IP
header here, could this lead to an incorrect skb->csum for CHECKSUM_COMPLETE
packets later in this function?
When a BPF program leaves iph->check = 0, skb_postpush_rcsum() is called:
if (ingress)
skb_postpush_rcsum(skb, iph, len);
This calculates the partial checksum of the IP header and adds it to
skb->csum. Later, the correct checksum is calculated and overwrites
iph->check:
if (!iph->check)
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
However, skb->csum is not updated to reflect this modification. Because a
valid IP header's checksum zeroes out its 16-bit one's complement sum, does
the addition in skb_postpush_rcsum() incorrectly add the header's
unchecksummed sum to skb->csum, causing packets to fail CHECKSUM_COMPLETE
validation and drop?
[Severity: High]
This is a pre-existing issue, but since this patch explicitly permits IP
headers with options (where iph->ihl > 5), does handle_gso_encap() handle
them correctly at the end of this function?
If the packet requires GSO, handle_gso_encap() hardcodes the IPv4 header
length to 20 bytes:
net/core/lwt_bpf.c:handle_gso_encap() {
...
next_hdr_offset = sizeof(struct iphdr);
...
}
If IP options are present, won't handle_gso_encap() mistakenly read the IP
options as the transport header's protocol flags (e.g., GRE flags or UDP
checksum)?
Will this misconfigure GSO and result in corrupted segmented packets or
hardware drops?
> return -EINVAL;
> } else if (iph->version == 6) {
> ipv4 = false;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260529151351.69911-1-leon.hwang@linux.dev?part=2
next prev parent reply other threads:[~2026-05-29 16:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 15:13 [PATCH bpf v2 0/4] bpf: Update transport_header when encapsulating UDP tunnel in lwt Leon Hwang
2026-05-29 15:13 ` [PATCH bpf v2 1/4] bpf: Fix TOCTOU issue " Leon Hwang
2026-05-29 15:49 ` sashiko-bot
2026-06-01 0:44 ` Alexei Starovoitov
2026-06-01 13:34 ` Leon Hwang
2026-05-29 15:13 ` [PATCH bpf v2 2/4] bpf: Add check iph->ihl < 5 " Leon Hwang
2026-05-29 16:06 ` sashiko-bot [this message]
2026-05-29 15:13 ` [PATCH bpf v2 3/4] bpf: Update transport_header when encapsulating UDP tunnel " Leon Hwang
2026-05-29 16:31 ` sashiko-bot
2026-05-29 15:13 ` [PATCH bpf v2 4/4] selftests/bpf: Add tests to verify the fix of encapsulating VxLAN " Leon Hwang
2026-05-29 16:48 ` sashiko-bot
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=20260529160610.E9DDD1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=leon.hwang@linux.dev \
--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