Article View: linux.kernel.netdev
Article #18602Re: [PATCH net] ipv4: don't let the transport header offset wrap
From: netdev-bot+sashiko
Date: Wed, 18 Nov 2026 15:25
Date: Wed, 18 Nov 2026 15:25
188 lines
14895 bytes
14895 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 1
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] The IPv4 xfrm transport-mode (ESP/AH) receive path still lets
the transport header offset wrap, and the wrapped value still reaches…
- [Medium] Sibling receive paths still compute the transport header with
the unchecked 16-bit addition this patch removes from ip_rcv_core().
- [Low] The new drop path in ip_rcv_core() (net/ipv4/ip_input.c:576)
reports SKB_DROP_REASON_PKT_TOO_BIG.
--
ipv4: don't let the transport header offset wrap
This patch replaces the unchecked 16-bit transport_header computation in
ip_rcv_core() with skb_set_transport_header_careful(). If the offset from
skb->head doesn't fit, the packet is dropped. The helper computes the
offset from skb->data, so it also catches a network_header that was
already truncated.
> diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
> index 9860178752b8c..3970438933764 100644
> --- a/net/ipv4/ip_input.c
> +++ b/net/ipv4/ip_input.c
> @@ -572,7 +572,11 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
> }
>
> iph = ip_hdr(skb);
> - skb->transport_header = skb->network_header + iph->ihl*4;
> + if (!skb_set_transport_header_careful(skb, iph->ihl * 4)) {
[Severity: High]
After this check passes, can the transport header offset still wrap on the
IPv4 xfrm transport-mode (ESP/AH) receive path?
ip_rcv_core() only validates the outer header. After that,
esp_input_done2() pulls the ESP header and IV, and then sets the transport
header relative to the new skb->data:
net/ipv4/esp4.c:esp_input_done2() {
...
skb_pull_rcsum(skb, hlen);
if (x->props.mode == XFRM_MODE_TUNNEL ||
x->props.mode == XFRM_MODE_IPTFS)
skb_reset_transport_header(skb);
else
skb_set_transport_header(skb, -ihl);
...
}
Next, xfrm4_transport_input() moves the IP header and resets the transport
header without a check:
net/xfrm/xfrm_input.c:xfrm4_transport_input() {
...
skb->network_header = skb->transport_header;
}
ip_hdr(skb)->tot_len = htons(skb->len + ihl);
skb_reset_transport_header(skb);
...
}
This stores (u16)(N + ihl + hlen), where N is the outer IP header offset
from skb->head. Suppose N + ihl <= 65534, which passes the new check, but
N + ihl + hlen >= 65536. For ihl = 20 and hlen = 16 that is N in
[65500, 65514]. Then transport_header wraps to a small value while
network_header still fits.
The skb is then re-injected without going back through ip_rcv_core():
xfrm4_transport_finish()
NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, ...)
xfrm4_rcv_encap_finish()
dst_input()
ip_local_deliver()
ip_local_deliver_finish()
__skb_pull(skb, skb_network_header_len(skb));
With the wrapped transport_header, skb_network_header_len() returns
0xFFFF0000 + ihl as a u32. __skb_pull() then raises skb->len by
65536 - ihl, so the skb->len < skb->data_len BUG() never fires. It also
moves skb->data about 4 GiB forward on 64-bit, or wraps it back toward
skb->head on 32-bit. The protocol handler then dereferences skb->data.
This needs a transport-mode SA and an ESP/AH packet that authenticates
against it. It also needs a head offset near 64 KiB, which the commit
message says nested decapsulation produces. It hasn't been reproduced at
runtime.
The subject says this wrap is fixed for IPv4. Should the series also
cover xfrm4_transport_input() and the esp4/ah4 transport-mode paths?
[Severity: Medium]
The unchecked 16-bit addition that this patch removes from ip_rcv_core()
is still present in several sibling receive paths:
net/bridge/br_netfilter_hooks.c:br_nf_pre_routing() {
...
skb->transport_header = skb->network_header + ip_hdr(skb)->ihl * 4;
...
}
net/bridge/br_netfilter_ipv6.c:br_nf_pre_routing_ipv6() {
...
skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
...
}
net/ipv6/ip6_input.c:ip6_rcv_core() {
...
skb->transport_header = skb->network_header + sizeof(*hdr);
...
}
The commit message says:
So it also catches a packet whose network_header was already
truncated, where network_header + ihl * 4 would look valid.
Does that hold only for native IPv4 input?
After VXLAN, GENEVE or gretap decapsulation, bridged traffic reaches
NF_HOOK(NF_INET_PRE_ROUTING) from br_nf_pre_routing() and never passes
through ip_rcv_core(). The outer header can pass the new check just under
the limit, and the tunnel then pulls about 50 more bytes.
br_validate_ipv4() is a copy of the ip_rcv_core() checks, but it still
validates ip_hdr(skb), which is based on network_header. If network_header
was truncated, it validates stale bytes, and the netfilter hooks see a
wrapped transport_header.
For IPv6, transport_header can wrap to 0..39, below network_header. That
looks like it would cause:
- ipv6_parse_hopopts() in net/ipv6/exthdrs.c reads
skb_transport_header(skb)[1] from stale bytes at the start of the head
buffer.
- ip6_parse_tlv() starts from a negative skb_network_header_len() offset,
so the jumbo, RA and IOAM handlers act on stale bytes.
- Local delivery drops the packet, because
pskb_pull(skb, skb_transport_offset(skb)) in ip6_protocol_deliver_rcu()
gets a huge length.
If network_header is truncated, IPv6 validation, route lookup and
PRE_ROUTING/FORWARD filtering all run on stale bytes. Forwarding still
sends the real bytes at skb->data.
Could filtering and routing decisions be made on one header while
different bytes are forwarded? Should br_nf_pre_routing(),
br_nf_pre_routing_ipv6() and ip6_rcv_core() get the same treatment in
this series?
> + drop_reason = SKB_DROP_REASON_PKT_TOO_BIG;
[Severity: Low]
This isn't a bug, but is SKB_DROP_REASON_PKT_TOO_BIG the right reason
here? include/net/dropreason-core.h documents it as:
* @SKB_DROP_REASON_PKT_TOO_BIG: packet size is too big (maybe exceed the
* MTU)
By this point the packet has been trimmed to tot_len and has passed every
length check, so it can be a minimal 20-byte datagram. The failing
condition is that skb->data - skb->head + ihl * 4 doesn't fit in the
16-bit transport_header. That is about buffer layout, not packet size.
The other in-tree users of this reason are size or MTU checks, for example
in ip6_output.c, openvswitch actions.c and xfrm_iptfs.c. As a result,
dropwatch and the kfree_skb tracepoint would report these drops as
size/MTU drops.
> + __IP_INC_STATS(net, IPSTATS_MIB_INDISCARDS);
> + goto drop;
> + }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118004850.52808-1-mason%40kernel.org
Technical Details
Message-ID:
<179501552093.3136.9815450954820570467@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366236-linux-kernel-netdev=dewy.ruReferences:
<20261118004850.52808-1-mason@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366236-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] ipv4: don't let the transport header offset wrap Date: Wed, 18 Nov 2026 15:25:20 +0000 Organization: Usenet Network Message-ID: <179501552093.3136.9815450954820570467@kernel.org> References: <20261118004850.52808-1-mason@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2628405"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:IczehvVNvgGjevRMMMVSF/ndxwc= sha256:BZAjY1XF4NpuzKgihWe9jOYB2oDQ/bH/KDS5CL580Z0= sha1:v2ReK2k/lQv6n/7eORP11g0JdNs= sha256:Krs+6xNOcQ4MWbsJLzkxKtmHDUcuBPFsl2wX9cV2uVw= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 046491152FE; Wed, 18 Nov 2026 18:25:55 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id POGYnRwFwWdv; Wed, 18 Nov 2026 18:25:42 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-366236-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 29A411152D1; Wed, 18 Nov 2026 18:25:31 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 9F8FC60D1E6; Wed, 18 Nov 2026 15:25:30 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795015523; b=AmoM6d90AiUXZZS3ZxvpETMVZJzRzYF3yDryjSTJlL3O6LZU29cubyFo4RmehMNNfDpr aRyYJqnPgftktEBY3QFyC2sSgjDckKwu+wKCFpa6P9ooDux+DsAciwGRVglWrIKpkLjjA JTMV4YzXULBi8VZJb+qyNJP5ccSuBZ11cZ1DFzHGHnv6TC4LH7M7WcV4E3JHHIb1r+r/n Brm2diL9Z6M6hP4h+uYRG8CZsV7kC6LF/19PA4gOj++xZmZ62izmjU1zP1+kBJ/HBukUx ADnre4l6ESvcd3UvxuFLorA8vqnYZR8Sx4KLjrdezfMd+1/2NrgGVJeY9TBqrLYIxGA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795015523; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=W3Mvq/V/FTM8oAlqR9lvj/DYhM4Cp9mepGfr85l/rQA=; b=2/0WNhhCXWu+HhxIQcryNjbxbAhUXOkwO+E23oVJUDNyoCn3DTQquJM7vsA2kGPXkp6e QAyqXKdqRF2ynC2e6N4F+ab7L25FGAeCTt1sonStglvocVEkats4AlKWrjLp89VMADQgb 8dZjRFnR7CXQwC0IuK6W+mJFWSXQmIQ6Og4Qu4kmDGJWYF1c+viVfQJMsroYU9vZYKCNv yxxnIigaS0c5DbDkV1KAO7G/GT0fmsPbVnNDMVOuFYK0nm4CBSdMRBCtFWEfaqzaECUlg hAtcZQEZ4gQFYEH0OaaOBREgf0W4MlQcjC/CbDvx8y4F+txxj5HlYZRFgYZcdKHFx4w== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DoBqXlMg; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33834606A32C; Wed, 18 Nov 2026 15:25:23 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DoBqXlMg X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795015522; b=veTpEaLtNCmbS6c0OOEyoOOluI8Ypim3cYf73j0oSFZB6bjAioHnpsDeYO4BPeqb7kca xo9DPMuMi9hMVR9HmBaKMkGolNER9+cWr86dDm87Yeg8WcvZETSXfhYEIBm2buWLKekhj gem5wxBXtoMKSCXAkpqMDpV+TVbU+0HODrH8MQo5owOa6ISBEL4K7xxkRr72D2T0mPagT tgcKcfIiN5SwGY7EjNucBqeidLrXjFd0H5Y1qpRT3OwQ3rnuUuhe9NNFrPbTJTqToK8BP MeoxUwxTQNF41+LVFEOFzxDTKbs/OpyOnyOPz8XBfVJqxn4mkGKt6bmRy5FB9svM5Cw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795015522; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=W3Mvq/V/FTM8oAlqR9lvj/DYhM4Cp9mepGfr85l/rQA=; b=jx7TZqW3acH70MZMUgOd0Cr8/9+zzflG5oJzN2cEdmxAiUckTvr9TYA/9+eYM6D4Tqko /SLa1UnDE8nOoJYhrBAxHOMASFxJa4zxT4RA7g8kTw8D2VJEhq4yGHuJ9VswddZ2zkwza zz8swONuoMmWU+rx9dKqZ3AT5hWkJyVFZQiw8zXWVGH/tr+X7LhCSYQEkp0a0+lGOGM71 cyJ6Tlc0kTjKqqQO6YYq4wbxh7NqiMIf/Qnmyl5bzMons8/B1pRnohojKCzqmeXkYGYRh YNDdMxoHGdJvbXhFSnkfJmYWzS3e5a0SQ5DmfehB3ZG7reGSKvSO/6cDc0AgEUlANuw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DoBqXlMg; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53CC460A261E for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 15:25:22 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A20E1F000C7; Wed, 18 Nov 2026 15:25:21 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795015522; bh=W3Mvq/V/FTM8oAlqR9lvj/DYhM4Cp9mepGfr85l/rQA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=DoBqXlMgjBTOeEf6+1v0+jRMxC7AbPhuZBJFruOd78MvouWw7tUVUuT2dkiVpdXsI +uYxy3hTtAiA3RWbYKlSSLcbi7+VjvWQABXNDp0jQLttCyCLxFP7i4/npnsrhvNaPj M61KKnv3WfGrvvsRPQTFMCqZk+PcBeGcE5UX0IcHs8pt5k2LCPQuw9vjhkJy3VhLKY HxTiQCxVI2T356KKMuCFDMIPETKP7E1E3ue4X9bQCsdz+F9+F00jp4VOH3WCP+ziFt vEhbzuQ4glcaChyizxd/ty3JYYiBpDE51GBU0P+V0n/Lgv3IIttONTDBDYklX6VK7a Cqj8joyC5MllA== X-Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, willemb@google.com, kuniyu@google.com, netdev@vger.kernel.org, josef@toxicpanda.com X-In-Reply-To: <20261118004850.52808-1-mason@kernel.org> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list