From: Lin Jiapeng <ljp1205831794@gmail.com>
To: netdev-bot+sashiko@kernel.org
Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, netdev@vger.kernel.org, jiapenglin@tencent.com,
corvus@tencent.com
Subject: Re: [PATCH net] ipv4: reject header length beyond linear data in ip_do_fragment()
Date: Wed, 2 Dec 2026 19:39:15 +0800 [thread overview]
Message-ID: <3a9cceac-7629-4997-8486-2c106d0ba57f@gmail.com> (raw)
In-Reply-To: <179576213561.3135.12039000289688373845@kernel.org>
On 2026-11-27 2:48 p.m., netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 4 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 1 · Low: 2
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] ipv4: ip_do_fragment() uses iph->ihl before validating
> skb_headlen() and hlen
> - [Medium] The new guard in ip_do_fragment()
> (net/ipv4/ip_output.c:787-791) measures against the wrong base.
> - [Low] The commit message understates the impact.
> - [Low] The trailers misuse tags and drop attribution.
>
> --
>
> ipv4: reject header length beyond linear data in ip_do_fragment()
>
> This commit moves the hlen computation in ip_do_fragment() earlier. It
> adds a check that rejects the packet with -EINVAL when the IPv4 header
> length is below 20 bytes or larger than skb_headlen(). The goal is to stop
> the BUG() in ip_frag_next(), which the Open vSwitch fragmentation path can
> reach with PUSH_MPLS + TRUNC + MRU.
>
> Closes: https://lore.kernel.org/netdev/20260922030310.8684-3-habte.yibelo@gmail.com/
>
>> request (user+network namespace, PUSH_MPLS x4 + TRUNC + MRU) into a
>> deterministic kernel panic under a KASAN build:
>
> [Severity: Low]
> Is "under a KASAN build" accurate? The BUG() in ip_frag_next() does not
> depend on any condition:
>
> if (skb_copy_bits(skb, state->ptr, skb_transport_header(skb2), len))
> BUG();
>
> The quoted trace ends with "Fatal exception in interrupt", so it fires
> with BH disabled. That means it would panic on any kernel config, not only
> on KASAN builds.
>
> The message also leaves out an earlier step. Before that BUG(),
> skb_copy_from_linear_data(skb, ..., hlen) in ip_frag_next() reads hlen
> bytes from a linear area that is shorter than hlen, so it reads past
> skb->tail.
>
> Could the description be updated to reflect both points?
>
>> Closes: https://lore.kernel.org/netdev/20260922030310.8684-3-habte.yibelo@gmail.com/
>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>> Reported-by: TencentOS Corvus AI <corvus@tencent.com>
>> Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
>
> [Severity: Low]
> The Closes: link points at Paulos Yibelo's pending [PATCH net v6 2/2],
> not at a bug report. Reported-by: should also be followed by a Closes:
> link to that report, but here it is followed directly by Signed-off-by:.
>
> This patch resubmits the hlen half of that series. The overlap is only
> mentioned in the note below the --- line, and that note is dropped when
> the patch is applied, so git history will not credit Paulos Yibelo.
>
> For comparison, the companion commit 6785011f8b16 has
> "Reported-by: Paulos Yibelo" and a Closes: link to his posting.
>
> Should this patch credit Paulos Yibelo with Reported-by:, Suggested-by:
> or Co-developed-by:? Or should it be coordinated with the pending series
> instead?
>
>> diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
>> index d42d776af273e..d5ea596724d7b 100644
>> --- a/net/ipv4/ip_output.c
>> +++ b/net/ipv4/ip_output.c
>> @@ -784,6 +784,11 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
>> */
>>
>> iph = ip_hdr(skb);
>> + hlen = iph->ihl * 4;
>> + if (unlikely(hlen < sizeof(*iph) || hlen > skb_headlen(skb))) {
>
> [Severity: High]
> The commit message says the header length is validated before any use
> of hlen, but the CHECKSUM_PARTIAL block above still runs first.
> ip_check_csum_start() uses ip_hdrlen(skb), which is the same value as
> iph->ihl * 4. skb_checksum_help() then runs on a header that has not
> been validated yet.
>
> In the OVS TRUNC + prepare_frag() case from the changelog, a
> CHECKSUM_PARTIAL skb keeps its original csum_start, because
> pskb_trim() does not touch ip_summed. If csum_start was at or past
> network_header + hlen, ip_check_csum_start() returns 0, and
> skb_checksum_help() is reached with skb_checksum_start_offset(skb) >=
> skb_headlen(skb). That path calls skb_dump() and WARN_ONCE("offset
> (%d) >= skb_headlen() (%u)"). With panic_on_warn, the same reproducer
> still takes the machine down before the new check can reject the
> packet.
>
> The opposite case is also open. With iph->ihl < 5, ip_hdrlen() can be
> 0, so a csum_start equal to the network header passes
> ip_check_csum_start(). skb_checksum_help() then stores the folded
> checksum inside the IPv4 header itself, possibly over version/ihl,
> before hlen < sizeof(*iph) is ever checked.
>
> Separately, iph->ihl is dereferenced before anything checks
> skb_headlen(skb) >= sizeof(*iph). If TRUNC leaves only the 30 bytes of
> Ethernet + MPLS and prepare_frag() pulls all of them, skb_headlen() is
> 0 and ip_hdr(skb) points at skb->tail. The new check still rejects the
> packet, but only after reading a stale or uninitialized byte past the
> tail, which KMSAN would flag.
>
> Would it make sense to do the validation ahead of the CHECKSUM_PARTIAL
> block and to check skb_headlen(skb) >= sizeof(*iph) before reading
> ihl? iph = ip_hdr(skb) would then need to be re-read after
> skb_checksum_help(), since that call can reallocate skb->head.
>
> [Severity: Medium]
> Is skb_headlen() the right bound here? iph comes from
> skb_network_header(), but skb_headlen() counts from skb->data. The check
> only holds when skb_network_offset(skb) is zero, and nothing here enforces
> that.
>
> The Open vSwitch caller named in the commit message does not seem to
> guarantee a zero offset. In do_output(), TRUNC only trims down to the MAC
> header length (ETH_HLEN). The MPLS labels are not included in that floor:
>
> net/openvswitch/actions.c:do_output() {
> ...
> if (unlikely(cutlen < skb->len))
> pskb_trim(skb, max(cutlen, ovs_mac_header_len(key)));
> ...
> }
>
> ovs_fragment() then moves the network header to the inner network header.
> With four MPLS labels it ends up at offset 30, which the MAX_L2_LEN check
> still allows:
>
> if (eth_p_mpls(skb->protocol)) {
> orig_network_offset = skb_network_offset(skb);
> skb->network_header = skb->inner_network_header;
> }
>
> prepare_frag() then ignores the return value of skb_pull():
>
> memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
> skb_pull(skb, hlen);
>
> Take skb->len == 29. skb_pull(skb, 30) returns NULL and leaves skb->data
> where it was. ip_hdr(skb) then points 30 bytes past skb->data, which is
> past skb->tail.
>
> Now add an MRU of 28 and an output vport with hard_header_len 0. A
> TUN-mode tun device qualifies, since tun_net_initialize() sets
> dev->hard_header_len = 0. do_output() still calls ovs_fragment() because
> 29 > 28 + 0.
>
> If the stale byte after the tail holds ihl == 5, then hlen = 20, which is
> not above skb_headlen() = 29. The new check passes, and so does the
> mtu < hlen + 8 check. A longer original packet sent before TRUNC can
> control that stale byte.
>
>>From there, ip_frag_init() reads iph->frag_off from beyond the tail.
> ip_frag_next() copies the header from skb->data rather than from the
> network header:
>
> skb_copy_from_linear_data(skb, skb_network_header(skb2), state->hlen);
>
> As a result, every emitted fragment carries Ethernet/MPLS bytes as its
> IPv4 header, and the stale frag_off bits end up in its frag_off field.
>
> The BUG() in ip_frag_next() no longer looks reachable, because
> hlen <= skb_headlen() keeps state->left and skb_copy_bits() in range.
> However, in this case the network offset plus hlen is 50 against a
> headlen of 29, and the packet is still not rejected.
>
> Would checking skb_network_offset(skb) + hlen against skb_headlen(skb),
> or requiring a zero network offset, cover this case? Another option would
> be for prepare_frag() to handle the skb_pull() failure.
>
>> + err = -EINVAL;
>> + goto fail;
>> + }
>>
>> mtu = ip_skb_dst_mtu(sk, skb);
>> if (IPCB(skb)->frag_max_size && IPCB(skb)->frag_max_size < mtu)
>
> [ ... ]
>
v2 addresses the four findings as follows.
- High: ip_do_fragment() now validates the fixed IPv4 header, IHL and
zero network offset before any IHL dereference or CHECKSUM_PARTIAL
handling. iph is reacquired after skb_checksum_help().
- Medium: the fragment helpers now get the required data == network_header
invariant. OVS also rejects negative or unpullable L2 offsets before
prepare_frag(), preventing the earlier memcpy and failed skb_pull()
from bypassing the IPv4 guard.
- Low (impact): the commit message now states that KASAN is not required
for the BUG, documents the pre-BUG logical linear over-read, and
includes the actual panic/oops call trace.
- Low (trailers): the related public patch is now cited with Link, and
Paulos Yibelo is credited with Suggested-by. The previous Closes usage
was removed. The v1 link is included below the --- separator.
pw-bot: cr
prev parent reply other threads:[~2026-12-02 11:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 6:43 [PATCH net] ipv4: reject header length beyond linear data in ip_do_fragment() Lin Jiapeng
2026-11-27 6:48 ` netdev-bot+sashiko
2026-12-02 11:39 ` Lin Jiapeng [this message]
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=3a9cceac-7629-4997-8486-2c106d0ba57f@gmail.com \
--to=ljp1205831794@gmail.com \
--cc=corvus@tencent.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jiapenglin@tencent.com \
--cc=kuba@kernel.org \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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