From nobody Thu Sep 24 20:36:54 2026 Received: from mail-qk2-f13.google.com (mail-qk2-f13.google.com [74.125.230.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97A06146D5A for ; Mon, 21 Sep 2026 02:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.230.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789959234; cv=none; b=lOHLMajD72WCLQRGYfdjZ+LrOq6AoTdCHknYV8/8oN8AqtM0vXgVqJtnFW5zExo266UO1YWk8O6Za4GLE2Bu2VyVgY7lykPG4E2lYxfsxuWBfsmQCL66GhYI6U/CTA9z4Pse89f51yN6j7xQuvHDtuu7OFbwntS/0XMOJNgYqQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789959234; c=relaxed/simple; bh=rF+0orxhGM2+72iiMlOGhSqGFV1AnZmnKlaVomftXAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y7l08Vo0PO3/57ZpM+eaBeqB2574tbeCtwjxVv6tD0MaiAp2BKZ98JzKrVt9yfgEw0WMK1see6cgTVRUaymxbeKGTIg+OBHmSnNdoYCucTxPmzEokl5RDkSUYqpK04fJgZ9c1l6mhxG0u8g8YTyLcQf0F9+/IDHK4RghegLCMjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nRL8AotU; arc=none smtp.client-ip=74.125.230.205 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.b="nRL8AotU" Received: by mail-qk2-f13.google.com with SMTP id af79cd13be357-93910ad2273so322775985a.0 for ; Sun, 20 Sep 2026 19:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789959230; x=1790564030; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fkhGS8LwLr9AchoqrwEQvfmCs6eRJO1/8RM9quRrKBU=; b=nRL8AotUrjiNPJmv49FVw9DDtBCIsLkeMWH7tkVVD2dC5APnMIBDNqPA48qqZm/8bx QosEUNDxdYj0dlSYTNQrUAywGuJ+7lU/38klEqbIzjKeW0wt/+67sTmaArIdCZTU4+Zu Mom4+/pLhKg4KGVTxxuqDtgQR08YW9CXTSb0bo5umw5FkTXKb17aMrFv4Ajyglo1mDl6 YC0PZGomLisVKhi5jpiY60cnkW+sKK4oRvCaRwr9foIbgI4rdVynTDUhC2IrdjL9uslm 9UEe4exPaaWV87bop1VQURtEGRn5cUrK39sQyNALoBpErvLIPqp173Km97iCtJDPyBoY gXAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789959230; x=1790564030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fkhGS8LwLr9AchoqrwEQvfmCs6eRJO1/8RM9quRrKBU=; b=wgRYNVM/iytycwBCUmo8mbmPR/vrEALfG9rektZyH06Ko9X0Wll1ZpPBCmMBxu8kNI uEEVr/Ikrp10Vw8ova5Mk7noU8nE7CmmEZs98RYTSr3XZPMyqHt9dMi7Qh0q6OzduYUu szFn+rsCyu4buxEhPba3mGBSGNXy3leIKi+gyDiE+CMuSPWcVDNU+XmW6EkVR0pL20MQ V+gRx2+H+gFeiX4c7tXRU45kl+baahcVZPBsid+gaJ25XoB2LqiLGOPyZ+k7Ee4c6o7B B6m1xH72DaapK5A4lQf3uVw4KxGfRR791II0EDqv/bjGm4h7Bmv8IDfrJPhE94Ni10K6 cdMg== X-Forwarded-Encrypted: i=1; AKwUvBzNBqeRecSpYVEZkpc6/wuA6BDCdRRfS9Vv9y2s2XtqK701JbG61YvBHh049nPLtTmZ+yUQuZMP02MtSyg=@vger.kernel.org X-Gm-Message-State: AFuF++nDwkOD5flA7fAncAmnS820yioYXumu7o4HpmeqAzpgzdyPGf/b RCpO2WItu6qUzcAfA5k1t6pFTpjqDqQksus47B8aMnwGxDeN8phcJLT2 X-Gm-Gg: AYBFou06lrKMbavP0Vjs5BhNaQqt93Z2JLjchCLKCNhKAuTu3yQg3sA6ecZ8766aGjp mEno9fEBksR+2KK6FyJ4L9L46ihYYSqNSnmSEx55e0g+sNORnuPA3OlaFK1hwjSSoIELubsN4RX ITB9w/HUhTCq48uiqLubjvDlPilA2G/08cE3CrSasuQFMq2rY/X0eMT+QwsxEVfjIZNYihvGJ5+ zxurjKaWZ5oOBXiijv9iTVPqW9fnAf2tnW1DjfGUVdj4i8sA38dK6yUbPqNjbrOFivS2WJsHB7L MThIaqCXRykg+X3Pm7ANTWBkKg5w4ltGc4iUrlTMIy/zL9a5AL4kIvqjyY/m13rW6uK6ClPQTVp NOM4gsEcul1TikX4zmuYFZvzwMkarm7agGypC5mmaZybrbODCI1ni6TU7z4LZe4JSK7Fz54FUih rdF5mQ5yiHWUrueOhqKBFtVVPCHTldPd3ZvzAKdIqTLmSVFxBCiR0tSl/rHMwtju5PBkStWO/XK gAuvvp3P4v8mJRyc3SKegyJ8NIzqV84u9NILzXGduT9g9a7MSQwkDW8qzltnwl0uZFGiVJY X-Received: by 2002:a05:620a:298c:b0:93b:d7a1:ba0b with SMTP id af79cd13be357-93bf5742f73mr878321485a.54.1789959230321; Sun, 20 Sep 2026 19:53:50 -0700 (PDT) Received: from localhost.localdomain ([2601:155:4200:2c80:64b9:5e22:f77c:324e]) by smtp.gmail.com with ESMTPSA id af79cd13be357-93bedb3de58sm528732785a.37.2026.09.20.19.53.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 20 Sep 2026 19:53:49 -0700 (PDT) From: Paulos Yibelo To: netdev@vger.kernel.org Cc: richard@nod.at, anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net, willemdebruijn.kernel@gmail.com, jasowangio@gmail.com, mst@redhat.com, eperezma@redhat.com, xuanzhuo@linux.alibaba.com, andrew+netdev@lunn.ch, pablo@netfilter.org, fw@strlen.de, phil@nwl.cc, razor@blackwall.org, idosch@nvidia.com, dsahern@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-um@lists.infradead.org, virtualization@lists.linux.dev, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH net v5 1/2] net: validate virtio checksum start after network header Date: Sun, 20 Sep 2026 22:53:40 -0400 Message-ID: <20260921025341.44846-2-habte.yibelo@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20260921025341.44846-1-habte.yibelo@gmail.com> References: <20260920004733.6473-1-habte.yibelo@gmail.com> <20260921025341.44846-1-habte.yibelo@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __virtio_net_hdr_to_skb() rejects a CHECKSUM_PARTIAL start smaller than an estimated minimum network-header length. Its input offsets are relative to skb->data. Using skb_network_offset() here is unsafe. TUN/TAP, virtio-net, and UML parse a received virtio header before skb->network_header is established. On an skb with headroom, the resulting negative offset enlarges the apparent distance to the transport header and can admit a checksum start inside the network header. Pass the data-relative L3 offset to the converter explicitly. IFF_TUN uses zero, AF_PACKET supplies its established network offset, and Ethernet receive paths parse Ethernet and nested VLAN headers with skb_header_pointer(), without changing skb state. Use the same origin for tunnel-offset validation, and make UML propagate conversion failures. This does not require a virtual-machine guest. A TUN or TAP device with virtio-net header support is sufficient to reach these paths. Fixes: 49d14b54a527 ("net: test for not too small csum_start in virtio_net_= hdr_to_skb()") Fixes: a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunne= ling.") Reported-by: Paulos Yibelo Link: https://lore.kernel.org/netdev/20260920004733.6473-2-habte.yibelo@gma= il.com/ Cc: stable@vger.kernel.org Signed-off-by: Paulos Yibelo --- Changes in v5: - Replace the not-yet-established skb network-header offset with an explicit data-relative L3 origin. - Cover all in-tree callers, including Ethernet/VLAN receive paths, tunnel metadata, and UML error propagation. - Drop the prior Acked-by and Reviewed-by tags because the code changed. Changes in v4: - State that a TUN device is sufficient and no guest is required, as noted by Michael S. Tsirkin. Changes in v3: - Keep the network-relative comparison on one line for readability, as requested by David Ahern. Changes in v2: - Make nh_min_len an int and remove the casts, as suggested by Michael S. Tsirkin. arch/um/drivers/vector_transports.c | 10 +++- drivers/net/tun_vnet.h | 28 ++++++++++- drivers/net/virtio_net.c | 8 ++- include/linux/virtio_net.h | 76 +++++++++++++++++++++++------ net/packet/af_packet.c | 6 ++- 5 files changed, 106 insertions(+), 22 deletions(-) diff --git a/arch/um/drivers/vector_transports.c b/arch/um/drivers/vector_t= ransports.c index ddd127ee9..79bc05fc6 100644 --- a/arch/um/drivers/vector_transports.c +++ b/arch/um/drivers/vector_transports.c @@ -197,6 +197,7 @@ static int raw_verify_header( uint8_t *header, struct sk_buff *skb, struct vector_private *vp) { struct virtio_net_hdr *vheader =3D (struct virtio_net_hdr *) header; + int network_offset; =20 if ((vheader->gso_type !=3D VIRTIO_NET_HDR_GSO_NONE) && (vp->req_size !=3D 65536)) { @@ -209,8 +210,13 @@ static int raw_verify_header( if ((vheader->flags & VIRTIO_NET_HDR_F_DATA_VALID) > 0) return 1; =20 - virtio_net_hdr_to_skb(skb, vheader, virtio_legacy_is_little_endian()); - return 0; + network_offset =3D virtio_net_hdr_get_l3_offset(skb, vheader); + if (network_offset < 0) + return network_offset; + + return virtio_net_hdr_to_skb(skb, vheader, + virtio_legacy_is_little_endian(), + network_offset); } =20 static bool get_uint_param( diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h index f4c652b1f..1c83c359d 100644 --- a/drivers/net/tun_vnet.h +++ b/drivers/net/tun_vnet.h @@ -177,10 +177,27 @@ static inline int tun_vnet_hdr_put(int sz, struct iov= _iter *iter, return __tun_vnet_hdr_put(sz, 0, iter, hdr); } =20 +static inline int +tun_vnet_hdr_get_l3_offset(unsigned int flags, const struct sk_buff *skb, + const struct virtio_net_hdr *hdr) +{ + if ((flags & TUN_TYPE_MASK) !=3D IFF_TAP) + return 0; + + return virtio_net_hdr_get_l3_offset(skb, hdr); +} + static inline int tun_vnet_hdr_to_skb(unsigned int flags, struct sk_buff *= skb, const struct virtio_net_hdr *hdr) { - return virtio_net_hdr_to_skb(skb, hdr, tun_vnet_is_little_endian(flags)); + int network_offset =3D tun_vnet_hdr_get_l3_offset(flags, skb, hdr); + + if (network_offset < 0) + return network_offset; + + return virtio_net_hdr_to_skb(skb, hdr, + tun_vnet_is_little_endian(flags), + network_offset); } =20 /* @@ -199,10 +216,17 @@ tun_vnet_hdr_tnl_to_skb(unsigned int flags, netdev_fe= atures_t features, struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *hdr) { + const struct virtio_net_hdr *vnet_hdr =3D (const struct virtio_net_hdr *)= hdr; + int network_offset =3D tun_vnet_hdr_get_l3_offset(flags, skb, vnet_hdr); + + if (network_offset < 0) + return network_offset; + return virtio_net_hdr_tnl_to_skb(skb, hdr, features & NETIF_F_GSO_UDP_TUNNEL, features & NETIF_F_GSO_UDP_TUNNEL_CSUM, - tun_vnet_is_little_endian(flags)); + tun_vnet_is_little_endian(flags), + network_offset); } =20 static inline int tun_vnet_hdr_from_skb(unsigned int flags, diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index e34c52d05..059eeb18e 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2502,6 +2502,7 @@ static void virtnet_receive_done(struct virtnet_info = *vi, struct receive_queue * { struct virtio_net_common_hdr *hdr; struct net_device *dev =3D vi->dev; + int network_offset; =20 hdr =3D skb_vnet_common_hdr(skb); if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report) @@ -2515,9 +2516,12 @@ static void virtnet_receive_done(struct virtnet_info= *vi, struct receive_queue * goto frame_err; } =20 - if (virtio_net_hdr_tnl_to_skb(skb, &hdr->tnl_hdr, vi->rx_tnl, + network_offset =3D virtio_net_hdr_get_l3_offset(skb, &hdr->hdr); + if (network_offset < 0 || + virtio_net_hdr_tnl_to_skb(skb, &hdr->tnl_hdr, vi->rx_tnl, vi->rx_tnl_csum, - virtio_is_little_endian(vi->vdev))) { + virtio_is_little_endian(vi->vdev), + network_offset)) { net_warn_ratelimited("%s: bad gso: type: %x, size: %u, flags %x tunnel %= d tnl csum %d\n", dev->name, hdr->hdr.gso_type, hdr->hdr.gso_size, hdr->hdr.flags, diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index c381b916c..a4c005796 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -48,11 +48,49 @@ static inline int virtio_net_hdr_set_proto(struct sk_bu= ff *skb, return 0; } =20 +/* + * Return the L3 offset of an Ethernet frame starting at skb->data. + * The offset is unused without NEEDS_CSUM, so avoid parsing and return ze= ro. + */ +static inline int +virtio_net_hdr_get_l3_offset(const struct sk_buff *skb, + const struct virtio_net_hdr *hdr) +{ + unsigned int parse_depth =3D VLAN_MAX_DEPTH; + const struct ethhdr *eth; + struct ethhdr ethbuf; + __be16 protocol; + int depth =3D ETH_HLEN; + + if (!(hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM)) + return 0; + + eth =3D skb_header_pointer(skb, 0, sizeof(ethbuf), ðbuf); + if (!eth) + return -EINVAL; + + protocol =3D eth->h_proto; + while (eth_type_vlan(protocol)) { + const struct vlan_hdr *vh; + struct vlan_hdr vhdr; + + vh =3D skb_header_pointer(skb, depth, sizeof(vhdr), &vhdr); + if (!vh || !--parse_depth) + return -EINVAL; + + protocol =3D vh->h_vlan_encapsulated_proto; + depth +=3D VLAN_HLEN; + } + + return depth; +} + static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb, const struct virtio_net_hdr *hdr, - bool little_endian, u8 hdr_gso_type) + bool little_endian, u8 hdr_gso_type, + int network_offset) { - unsigned int nh_min_len =3D sizeof(struct iphdr); + int nh_min_len =3D sizeof(struct iphdr); unsigned int gso_type =3D 0; unsigned int thlen =3D 0; unsigned int p_off =3D 0; @@ -98,16 +136,20 @@ static inline int __virtio_net_hdr_to_skb(struct sk_bu= ff *skb, u32 start =3D __virtio16_to_cpu(little_endian, hdr->csum_start); u32 off =3D __virtio16_to_cpu(little_endian, hdr->csum_offset); u32 needed =3D start + max_t(u32, thlen, off + sizeof(__sum16)); + int transport_offset; =20 if (!pskb_may_pull(skb, needed)) return -EINVAL; =20 if (!skb_partial_csum_set(skb, start, off)) return -EINVAL; - if (skb_transport_offset(skb) < nh_min_len) + + transport_offset =3D skb_transport_offset(skb); + if (transport_offset < nh_min_len || network_offset < 0 || + network_offset > transport_offset - nh_min_len) return -EINVAL; =20 - nh_min_len =3D skb_transport_offset(skb); + nh_min_len =3D transport_offset; p_off =3D nh_min_len + thlen; if (!pskb_may_pull(skb, p_off)) return -EINVAL; @@ -206,9 +248,11 @@ static inline int __virtio_net_hdr_to_skb(struct sk_bu= ff *skb, =20 static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, const struct virtio_net_hdr *hdr, - bool little_endian) + bool little_endian, + int network_offset) { - return __virtio_net_hdr_to_skb(skb, hdr, little_endian, hdr->gso_type); + return __virtio_net_hdr_to_skb(skb, hdr, little_endian, hdr->gso_type, + network_offset); } =20 /* This function must be called after virtio_net_hdr_from_skb(). */ @@ -287,7 +331,7 @@ static inline int virtio_net_hdr_from_skb(const struct = sk_buff *skb, return 0; } =20 -static inline unsigned int virtio_l3min(bool is_ipv6) +static inline int virtio_l3min(bool is_ipv6) { return is_ipv6 ? sizeof(struct ipv6hdr) : sizeof(struct iphdr); } @@ -297,18 +341,19 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr, bool tnl_hdr_negotiated, bool tnl_csum_negotiated, - bool little_endian) + bool little_endian, int network_offset) { const struct virtio_net_hdr *hdr =3D (const struct virtio_net_hdr *)vhdr; - unsigned int inner_nh, outer_th, inner_th; - unsigned int inner_l3min, outer_l3min; u8 gso_inner_type, gso_tunnel_type; bool outer_isv6, inner_isv6; + int inner_nh, outer_th, inner_th; + int inner_l3min, outer_l3min; int ret; =20 gso_tunnel_type =3D hdr->gso_type & VIRTIO_NET_HDR_GSO_UDP_TUNNEL; if (!gso_tunnel_type) - return virtio_net_hdr_to_skb(skb, hdr, little_endian); + return virtio_net_hdr_to_skb(skb, hdr, little_endian, + network_offset); =20 /* Tunnel not supported/negotiated, but the hdr asks for it. */ if (!tnl_hdr_negotiated) @@ -332,19 +377,22 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, outer_isv6 =3D gso_tunnel_type & VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6; inner_isv6 =3D gso_inner_type =3D=3D VIRTIO_NET_HDR_GSO_TCPV6; inner_l3min =3D virtio_l3min(inner_isv6); - outer_l3min =3D ETH_HLEN + virtio_l3min(outer_isv6); + outer_l3min =3D virtio_l3min(outer_isv6); =20 inner_th =3D __virtio16_to_cpu(little_endian, hdr->csum_start); inner_nh =3D le16_to_cpu(vhdr->inner_nh_offset); outer_th =3D le16_to_cpu(vhdr->outer_th_offset); - if (outer_th < outer_l3min || + if (network_offset < 0 || + outer_th < outer_l3min || + network_offset > outer_th - outer_l3min || inner_nh < outer_th + sizeof(struct udphdr) || inner_th < inner_nh + inner_l3min) return -EINVAL; =20 /* Let the basic parsing deal with plain GSO features. */ ret =3D __virtio_net_hdr_to_skb(skb, hdr, true, - hdr->gso_type & ~gso_tunnel_type); + hdr->gso_type & ~gso_tunnel_type, + network_offset); if (ret) return ret; =20 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 50cae32ae..04c80e23d 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2901,7 +2901,8 @@ static int tpacket_snd(struct packet_sock *po, struct= msghdr *msg) } =20 if (has_vnet_hdr) { - if (virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le())) { + if (virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le(), + skb_network_offset(skb))) { tp_len =3D -EINVAL; goto tpacket_error; } @@ -3103,7 +3104,8 @@ static int packet_snd(struct socket *sock, struct msg= hdr *msg, size_t len) packet_parse_headers(skb, sock); =20 if (vnet_hdr_sz) { - err =3D virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le()); + err =3D virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le(), + skb_network_offset(skb)); if (err) goto out_free; len +=3D vnet_hdr_sz; --=20 2.46.0 From nobody Thu Sep 24 20:36:54 2026 Received: from mail-qk2-f43.google.com (mail-qk2-f43.google.com [74.125.230.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AE6E336885 for ; Mon, 21 Sep 2026 02:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.230.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789959236; cv=none; b=ghBtX7Z4QjCpViHo/TfOVP1wb87TSiWHM3txE2ajG8saXQeXVgmeWaSguGg49WYTKCdkj3cWyOwt2RWYAF/vVtEt748cSG/Oaf9stTUEBobGNvHZw6fjl2aHsvJo1S9M2pZSyMbSZvDBGrWf5501ZvXequPhT4fGP84F6Y0jXCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789959236; c=relaxed/simple; bh=o7u+Ilnkg+4xjG93z/0C0NZxlAlBcA2mnfdP5ehaM74=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uUbVJe0XD60Khsp9Z5mQIOqvLplY+XSlOo1wcd4yCYfOYo0Lg1nZbkh6PbjDt8w/jQMP06nJMqE9cDLScHMkawpvtg1zLxB6b5egB9EGJQJjfk29wt7UJPFe1aPMuHqyr1vdaF2nc7KeY0jMusYfLCY5NGkOzhEUkL85TpT9Qus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=et+W8caU; arc=none smtp.client-ip=74.125.230.235 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.b="et+W8caU" Received: by mail-qk2-f43.google.com with SMTP id af79cd13be357-93910cc46c4so240878285a.2 for ; Sun, 20 Sep 2026 19:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789959233; x=1790564033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=u8Ct4yW9W4ymcEv428o4m/ZX/KrAWtAnJ7CKPNzyvYY=; b=et+W8caUeJia6mcj+wTgoqX2bCsCLBK/WVaX/C/smL2cFB37iXQulDUhLvBfJ2MX2n XEDtaQ1MZ5fV71ktQtakXlkp7WHuxUYf0RrjxU2tvxFQunVd1G00ZS4Ir7OYKRMLawZR sN9lXfmtWKxkJnXP74qbhdDxqAW6PASB+IjujdVpRsnGidWJ7BBZVSiYopVO7BdacymA BqcYoM5UxmFn7xygMTlbZYAOlCNaDJRrFleZxjhsRKdxf8Y+1iuq/Q2CPE1n0KRCBQdm dMjSfjLEjKrYiz/a7Qq5u/cSrOaesRTqIACJZM0LQPBXVeWfU4e7mt00ygMwRV8fl+qB c5XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789959233; x=1790564033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=u8Ct4yW9W4ymcEv428o4m/ZX/KrAWtAnJ7CKPNzyvYY=; b=M1HqG73oLI1pTve+ei3AR4W9XQ+KH5FU9iN44jHQlc0cvzs5+VWVQJZDtcCSCAiXu0 QOjZ/BLeDe5xMWmvWOybbf6fu7XIFoo7W7/FAZ0R+j7L2DJ1ovRRZ/hxyclh1rSlSU1E PBdin6R4j/KGHPf1SPH8kxYIqagE/zwZHFXRYIen0lHbKX7tGJWGGSSR1OCCk/XmkebX g2ylf20+G45vPaiJD9kv8g3WMxFTZ/uaDPRR609mUzFHPYU9wwzMHv/BEzyf1joIoNHc E3H/XyfrjaA4Jw5DuwS9zK+pA4mKe3JRHvbMwX3fy8rEx/uPN4sYshCAsfRmDq05A/H1 mOUA== X-Forwarded-Encrypted: i=1; AKwUvByVo0GxSOMwsr8hXDSD2XcNMLSIXhEt1NLqjjO+oG8GkyoePVRnm7E3uDIE63dhFZw7q5spCgnWs/N7Oss=@vger.kernel.org X-Gm-Message-State: AFuF++kGttpoSVBPPd8CXoJwYwrvskBHerbQbxntgyxgHpeqCsZtzpx5 8l14+jj2tGWAiX3eDcLnzrtZcP5lFKsYsr/3pTkVP1NwqVEkpCkytMtJ X-Gm-Gg: AYBFou24OieY2E1PZLA4l0hlg584VdBykoI9P3O9U241UdedAk+4okBLrIalywysOeG GNVooB3WZ+8Ajszyrh5tYqEZWkTtnQZGy6eDPnelPg7fvyIYlPpD0LW4DqecwWifAsIuaL22s4S Y9cnN0xrb5swSuJ12ukb3SHL0PpRmipIyG9StX2BR6oSH+zWSlolqjPeqM9E+41o32e6NdfUxPL sk/4zHSf7m+zq+h5lpLc5nY8ROBT23TQsBur4RgNiRjqUl9YzDqqZKNQ29t79IDCa4JMcd3alIb kP4rOXCHeH64YUd5Dv5T1gA/FpirrRAPWEHcddeduFdt7MznUU8Vk8sg2vyQTCTFz6t2Ghgd80Q skqn5RsPK4vGQG9me3gud81Rk3XU0f9+0QNxU2y7G07B3c+juzXknJpRn18ZBVKOo41R13Freyo XnYruK+FL5dK4O1+IuUK1PavUbp9WH1qIX8YeWWSwroKF3ym/3ZeCsGkBYpsrLrBU9en57x1+nR DecBpwzOkSBgrwrBpuCRoNriks02pEaWAbIJTU50hLGfuTwSPzAAqF9ftHDiFbY24AM9htA X-Received: by 2002:a05:620a:1724:b0:93b:d7a0:d9f0 with SMTP id af79cd13be357-93bf57eea2emr869731285a.74.1789959232559; Sun, 20 Sep 2026 19:53:52 -0700 (PDT) Received: from localhost.localdomain ([2601:155:4200:2c80:64b9:5e22:f77c:324e]) by smtp.gmail.com with ESMTPSA id af79cd13be357-93bedb3de58sm528732785a.37.2026.09.20.19.53.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 20 Sep 2026 19:53:51 -0700 (PDT) From: Paulos Yibelo To: netdev@vger.kernel.org Cc: richard@nod.at, anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net, willemdebruijn.kernel@gmail.com, jasowangio@gmail.com, mst@redhat.com, eperezma@redhat.com, xuanzhuo@linux.alibaba.com, andrew+netdev@lunn.ch, pablo@netfilter.org, fw@strlen.de, phil@nwl.cc, razor@blackwall.org, idosch@nvidia.com, dsahern@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-um@lists.infradead.org, virtualization@lists.linux.dev, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH net v5 2/2] ip: reject partial checksums covering network headers Date: Sun, 20 Sep 2026 22:53:41 -0400 Message-ID: <20260921025341.44846-3-habte.yibelo@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20260921025341.44846-1-habte.yibelo@gmail.com> References: <20260920004733.6473-1-habte.yibelo@gmail.com> <20260921025341.44846-1-habte.yibelo@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ip_do_fragment() and nf_br_ip_fragment() complete a CHECKSUM_PARTIAL skb before reading the IPv4 header length. ip6_fragment() and br_ip6_fragment() complete one after parsing the IPv6 header chain. A virtualization interface can supply a checksum start which, after link-layer removal, still points inside that parsed network header. skb_checksum_help() then writes the completed checksum into header bytes the stack has already consumed. For IPv4, changing iph->ihl after routing and validation can make fragmentation copy beyond the skb's logical linear head into transmitted options. A negative checksum-start offset is rejected by skb_checksum_help(), but only after a WARN_ONCE which can panic a panic_on_warn system. Validate the checksum start against the parsed header length before completing it. For IPv4, read and validate IHL first, retain it, and reacquire iph after skb_checksum_help() in both implementations. For IPv6, use the length returned by ip6_find_1stfragopt() in both implementations. Compare the signed checksum-start offset with the bounded signed header length so integer promotion cannot bypass either boundary. Fixes: dbd3393c56a8 ("ipv4: add defensive check for CHECKSUM_PARTIAL skbs i= n ip_fragment") Fixes: 405c92f7a541 ("ipv6: add defensive check for CHECKSUM_PARTIAL skbs i= n ip_fragment") Fixes: 3c171f496ef5 ("netfilter: bridge: add connection tracking system") Fixes: 764dd163ac92 ("netfilter: nf_conntrack_bridge: add support for IPv6") Reported-by: Paulos Yibelo Link: https://lore.kernel.org/netdev/20260920004733.6473-3-habte.yibelo@gma= il.com/ Cc: stable@vger.kernel.org Signed-off-by: Paulos Yibelo --- Changes in v5: - Compare the checksum-start offset and IPv4 header length as signed values. - Add parsed-header checks to the IPv4/IPv6 output and bridge-netfilter fragmentation paths. - Drop the prior Acked-by and Reviewed-by tags because the code changed. Changes in v4: - State that a TUN device is sufficient and no guest is required, as noted by Michael S. Tsirkin. Changes in v3: - No code changes. Changes in v2: - No code changes. net/bridge/netfilter/nf_conntrack_bridge.c | 21 +++++++++++++++----- net/ipv4/ip_output.c | 23 ++++++++++++++++------ net/ipv6/ip6_output.c | 12 ++++++++--- net/ipv6/netfilter.c | 12 ++++++++--- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfil= ter/nf_conntrack_bridge.c index 7ecb8a26b..d81ed8692 100644 --- a/net/bridge/netfilter/nf_conntrack_bridge.c +++ b/net/bridge/netfilter/nf_conntrack_bridge.c @@ -38,18 +38,29 @@ static int nf_br_ip_fragment(struct net *net, struct so= ck *sk, struct iphdr *iph; int err =3D 0; =20 - /* for offloaded checksums cleanup checksum before fragmentation */ - if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL && - (err =3D skb_checksum_help(skb))) + iph =3D ip_hdr(skb); + hlen =3D iph->ihl * 4; + if (unlikely(hlen < sizeof(*iph) || hlen > skb_headlen(skb))) { + err =3D -EINVAL; goto blackhole; + } =20 - iph =3D ip_hdr(skb); + /* Complete offloaded checksums only after the validated IP header. */ + if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL) { + if (unlikely(skb_checksum_start_offset(skb) < (int)hlen)) { + err =3D -EINVAL; + goto blackhole; + } + err =3D skb_checksum_help(skb); + if (err) + goto blackhole; + iph =3D ip_hdr(skb); + } =20 /* * Setup starting values */ =20 - hlen =3D iph->ihl * 4; frag_max_size -=3D hlen; ll_rs =3D LL_RESERVED_SPACE(skb->dev); mtu =3D skb->dev->mtu; diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index a24cc8ee1..fa6a74d20 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -770,16 +770,28 @@ int ip_do_fragment(struct net *net, struct sock *sk, = struct sk_buff *skb, struct ip_frag_state state; int err =3D 0; =20 - /* for offloaded checksums cleanup checksum before fragmentation */ - if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL && - (err =3D skb_checksum_help(skb))) - goto fail; - /* * Point into the IP datagram header. */ =20 iph =3D ip_hdr(skb); + hlen =3D iph->ihl * 4; + if (unlikely(hlen < sizeof(*iph) || hlen > skb_headlen(skb))) { + err =3D -EINVAL; + goto fail; + } + + /* Complete offloaded checksums only after the validated IP header. */ + if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL) { + if (unlikely(skb_checksum_start_offset(skb) < (int)hlen)) { + err =3D -EINVAL; + goto fail; + } + err =3D skb_checksum_help(skb); + if (err) + goto fail; + iph =3D ip_hdr(skb); + } =20 mtu =3D ip_skb_dst_mtu(sk, skb); if (IPCB(skb)->frag_max_size && IPCB(skb)->frag_max_size < mtu) @@ -789,7 +801,6 @@ int ip_do_fragment(struct net *net, struct sock *sk, st= ruct sk_buff *skb, * Setup starting values. */ =20 - hlen =3D iph->ihl * 4; if (mtu < hlen + 8) { err =3D -EMSGSIZE; goto fail; diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 550965058..d157b6ade 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -942,9 +942,15 @@ int ip6_fragment(struct net *net, struct sock *sk, str= uct sk_buff *skb, frag_id =3D ipv6_select_ident(net, &ipv6_hdr(skb)->daddr, &ipv6_hdr(skb)->saddr); =20 - if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL && - (err =3D skb_checksum_help(skb))) - goto fail; + if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL) { + if (unlikely(skb_checksum_start_offset(skb) < (int)hlen)) { + err =3D -EINVAL; + goto fail; + } + err =3D skb_checksum_help(skb); + if (err) + goto fail; + } =20 prevhdr =3D skb_network_header(skb) + nexthdr_offset; hroom =3D LL_RESERVED_SPACE(rt->dst.dev); diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c index a7025ec87..da7ada12f 100644 --- a/net/ipv6/netfilter.c +++ b/net/ipv6/netfilter.c @@ -144,9 +144,15 @@ int br_ip6_fragment(struct net *net, struct sock *sk, = struct sk_buff *skb, frag_id =3D ipv6_select_ident(net, &ipv6_hdr(skb)->daddr, &ipv6_hdr(skb)->saddr); =20 - if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL && - (err =3D skb_checksum_help(skb))) - goto blackhole; + if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL) { + if (unlikely(skb_checksum_start_offset(skb) < (int)hlen)) { + err =3D -EINVAL; + goto blackhole; + } + err =3D skb_checksum_help(skb); + if (err) + goto blackhole; + } =20 prevhdr =3D skb_network_header(skb) + nexthdr_offset; hroom =3D LL_RESERVED_SPACE(skb->dev); --=20 2.46.0