From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796211560; b=mSb2C99vliorsjBZp9ia4v+E/lZWCmar0921aBot8ThiTYMxQsQcI+eqp4+F7FjQG4ut V926qEZqzJsq7tY9qqv9m+LTdx1vxZ12IzEy0ko7O8CAyHc5+QFL58AAKzEdlYa1X+zuG g3ipiAYpbb8IvGIEdmc3uQ4/hJcIfOrbFjy+pzK1EM0H2B4Z9jcHHpXqUKdBpEe1f73ma YJCuVwMCOfT/tlJcKVv4F7b11jgr3qyvv3IalYuu8Zjc8sCTAILX3CcS5w22xMWQg0f8j Ja83PfpZ0hUA+1TNk59a6CS7/+Ez0JInnfvnL/me1Pd7cHpgL0BLNGylTL/+WoqyN0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796211560; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=r9jQOs4KhlVJ8NTYj1smXtNhlsXh0G+BY4t9QdV7RNw=; b=0VnLNDFAJye92koqrGQTRaz3Ca0miRypSK/XMLXUfDapgLlYMv5tjkJw053+BNJrv5O7 nztJx2JBaoUmvapj7GlUz64qth0LmftvVwf52NvLp7qr9786H4kyq8Vpk34RvziSKRQa+ t36A4SqfwY7Na9/HdJaUYnAtDeBhG414nBj1r2fAXt6OeJO3SlnqWkR9Cu9jxKa4ioJli GIxpWvb5udHBx7vSWaPHyJUEGagHewY5xrTJpa0dbbrFuDV52WuDVq+0czUoYM9wJz3wY xploJpt83PKsaqjpJIghvWlxbaqIb5HEL2yt6wjxkYdm5z7hcORy65KgU1pFcw3Ersw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Kc4bWivn; arc=none smtp.remote-ip=209.85.210.170 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E9D3606A31A for ; Wed, 2 Dec 2026 11:39:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0E9D3606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Kc4bWivn Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-8b600fae14dso4996073b3a.2 for ; Wed, 02 Dec 2026 03:39:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796211559; x=1796816359; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=r9jQOs4KhlVJ8NTYj1smXtNhlsXh0G+BY4t9QdV7RNw=; b=Kc4bWivnH4C12WnbXmXUI3XEDCYXQKNCZgyjklxIs/AcSSdkxNCj1ua27RF1uT/xZE a924nb2MChPnGDkt85kx2DyydxueSYHqS3XzwowKpGLWbf7RyGdNtCFo1u49Vzu/koWs Tp1qq1IYkKkCwCZogZ27RJh5HoCVezmeYRQupYpACbtApcn14faARUm8NXXfYKZf8VV8 ZvMpMHzgF1KSBpa+dHqOrsInyvBSWk0qp1iRwq4NdBbVIWfqDXldBxizHPCLYp6uvGAA nKjykhSbVna1p+HPPJVcY+AXvh9uRoqZcUVHgA5QoV8VlkdKudUOXyusPED2Jj14BSF/ 83Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796211559; x=1796816359; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=r9jQOs4KhlVJ8NTYj1smXtNhlsXh0G+BY4t9QdV7RNw=; b=HvYus1rtSXZqtu1W/ztT6d3drCrmnPu7PDf1nYfXKil4fBMRPKGA0ftFU5t0NrTFeP r1bykFsZ6J7nSFLgY9zg518crUpMwfp3mYpzyIexEN4h6rH9wbS2I446YX82R5CF/0uj f1daCNTaahfVHV0Zov60E6vGWrRFif2vBVuEpOcJD0AA8e9TrfoGkjKg5/hd87/whgJc +LGKZrqWQMCT/CvPsgqI3XBcdnyFiOcjGC38lW2udVGShBUQIcf/qt9qiz9q/T3O7zxk PDRH1my+RcGoxrt4s1DR7XYVUFZ51X7uzg5/FRVl7wY0qAThtGAcprRNZ7j6t4L2UCJE VawA== X-Forwarded-Encrypted: i=1; AL+hErGPjqDZrY474Oke6OI/IxFCaWBYCbL3tUADw9oY2rAXdC8nJSkghSxjbdrXVUydi26AYC7Dcgg=@vger.kernel.org X-Gm-Message-State: APuU4Z/0/rh/6GrleCyFIcw3Tky6SFn7rldo51ojfQdI8qu6Fr3Q0s4R 2D/87AAI4lap1Rp8l82rUmGIlEUHVJm7vaYmUOW9jKqvgwJH0Kc2QyF+ X-Gm-Gg: AZFdTZfG1ZRGGzgTls3SxobQCE4wrIgVeKZDAEQS9VW12Xbw8giXvy1zcKLEPQ+MLM0 wvVfyPhX+5xeHa07o4RDzfcWeOkDBQLkNzSbpHapF7gZDpOqcXMchVku8Stzx5XCOZGE5jb6Had DxI2HuEEi5OIr+8Czk5nBs7I00fN8DjSOwsicYIzu/7gzVrxMnKrQaSUPDmZqAD6Y/hHeKPPv2g nOdVJw1e2Ty0Z27/k0iBHcHH17IHnO2kE9mABuNmd3S4gB6yDwN9eWV002Y57tW0Ro3kIYyzpIv FVHSbAglWMqZR8U9K5j3TmdIIMLjkN3eLnNMi82cjXRdjXiiw8JEFqTi2OoyJe/fJzQYxpLdV5R V8PU8yf7+mdn68W2VaUgmw02S3ea2/FvdPKWuY2LK4+uh7VUfqbH1xPRl3h45dmN60gWFYIKz1U qaeetPN8kFL9cFFF5oP4wD+sbJk5UNB2FI69EBQzAp2ZX6FyyGo29eO+RiIXTxqcH2t4cXBSQgV 6aih45y7LKL0Q2cUN+wwDknufmQVETdAvOMWlwjsv0iIaVEQORByBz0eLz5KohGvK1msryroKm4 Z6yzUP1+LzNBA6jJWXT+jYylsnPFyMoClXrtzMNqIz+cgPgdiTuTGoADWr0= X-Received: by 2002:a05:6a00:23c6:b0:88d:8074:1a9e with SMTP id d2e1a72fcca58-8c8793b79camr37721223b3a.3.1796211559061; Wed, 02 Dec 2026 03:39:19 -0800 (PST) Received: from [192.168.255.10] ([43.132.141.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87285b60csm21822463b3a.9.2026.12.02.03.39.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 03:39:18 -0800 (PST) Message-ID: <3a9cceac-7629-4997-8486-2c106d0ba57f@gmail.com> Date: Wed, 2 Dec 2026 19:39:15 +0800 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] ipv4: reject header length beyond linear data in ip_do_fragment() 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 References: <20261126064445.57665-1-ljp1205831794@gmail.com> <179576213561.3135.12039000289688373845@kernel.org> From: Lin Jiapeng In-Reply-To: <179576213561.3135.12039000289688373845@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 >> Signed-off-by: Lin Jiapeng > > [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