From nobody Fri Sep 25 18:51:54 2026 Received: from mail-yx2-f13.google.com (mail-yx2-f13.google.com [74.125.224.141]) (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 85DE939CCF8 for ; Tue, 22 Sep 2026 03:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790046202; cv=none; b=MF7QjQRag8k2jmpma2h668nVy9nZGeSED6AVIwI4Nf58B/4AmXSznpI7LfACN0QCNKtSm+ULz1easkL6VSNkzT/9j1LaGzr3XQuBdRFGkf/IeJtgVBbw67dP/v/k4CbOsCTCdQugS9VwFk07czpINcxDridLW0cHrn3e/So59WQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790046202; c=relaxed/simple; bh=fFie+O+TzjTwVLdyq2ldFdWdLO4af24IGkMSNUH6SYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q44Mf8M5kMniDwAMy8efyXKBtIzkY3RHT9B56mBGuTrKwXlAkgkhRssSU88hDXa9wHBZIT3znbIQBhh4m2m2ZMAc0ndAoBwiqukEnoSJ2dioMotWsveNRPRpp2TYArhFsFwWDxKfpHDF9LrwOPzJF/CkDedOzmK2p/9pFwBJSqc= 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=DCy/qzif; arc=none smtp.client-ip=74.125.224.141 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="DCy/qzif" Received: by mail-yx2-f13.google.com with SMTP id 00721157ae682-85d440939f0so28457847b3.2 for ; Mon, 21 Sep 2026 20:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790046198; x=1790650998; 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=5TgtLun0Gp+97adAPkYnXli1FB7YGXH0JDQsRFi7AIo=; b=DCy/qzifnOR5ae9v11eX0QDdsMSzKmOiRe1PxJeG6Oi/KYvTISD2VWCXXILmo93uwb rqWVdHbkhgl3FkVtWCnBb86V03VH5HX/VFI3s+cqdIqkO8wVtmR12Hkq44K6C89qsxvy UlQC9e8xmaXw+Pdf7sJIITSVBrCKy59C2+sdJYG8SfNYOcNLqUmjRNvRvRuaWO/I5zmb GfNcDJaYJyRGGeeg724DHIJnUlt8yCi+/NmTIL2fFlCQE45SCWR1cJjhUuJPdyUPKf+u ZOGlEjP2KywDhh3SJ/ZSsyg2VZEG6CKqUOn7KmID80VSi8qSgqlzwDWDNHj8nd/edYzn sDYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790046198; x=1790650998; 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=5TgtLun0Gp+97adAPkYnXli1FB7YGXH0JDQsRFi7AIo=; b=kPESjBrDBaLrAjJpaeaAeLOMEnc04Izryj1Jmc0WMgiNhx/uitcRFnneu03FzDtmvR cvcT3iapG0nwe3pRRoNFWnNuUU4ckH5giW7gcnhhWgngD2smyezu1uEcbwTDdNu8glJA 0eitA1vmGHh4FJPvQ/xn5BaSDN41Umx123AvxIrtVI11h9XoLBewu4Gzb3UP6VuoNLvD POdJzDPWAE0UAbELOrLgGGryQa6GMP+RQH7GX88O8/2880pmGIGbtdMVupkaXh9cNi4c BqzgZcb14IMB8Axsjqi+blyz+fgVzxGgKw2rsukV27WWpUuqdZCNMc9zvKGxemK8DmcW YLTg== X-Forwarded-Encrypted: i=1; AKwUvBxr7GyA/p1q0TxUp4RtK5qUcx5W7cuyUif5mkYYI9gfZaDrTLyN1uEcL/KwrOQHl3iNeKfI2OPeu5rbXoo=@vger.kernel.org X-Gm-Message-State: AFuF++kuVGkPV41fjipj/b2nF+Dq0EUKMrjc7A5A6svnuzqxanSHB9zA uGKjwyAOusr4ZFHHpmoCZGtbAnoaeIJfoHY5kVUWTfUiDmqWjH7co7Z8 X-Gm-Gg: AYBFou0eVOfhwpb51xFW/TPC/FcyiOgt3gFhgSmIjYFfi/Ks2Orp2IJ+foSbj+w5bIN vyh+q4N4D7lTFMV04lKHR8O7gv8v3RQr+hJdKSnl1z6NuN+QV2xbwEpm6BBEuP4XrOJnSMzD0td /BLoUC2Vt0XjUPN9efUfSZ5626BtUYymMPa9hDjuNG36aBRLgCScfTXlg6cv70RR2M48D6Atz0D 6CHx7uoP4RkNm67LQQi+SeakAjyDbJlRF/yUnF16L4gtfUEDgMVIYS069KHXiZAX20pXrwxTmuQ 8JwMW0B4a9UJiNtAPRiRm5rKv73ZP1JVbKKyNSKCe41t/ZceGtclqLOufCDyTsEzckmqj5Cf0RO qRrNnCmenyLk5Zq0Stdp2JEUK7RFT+YdO0vNVy1jgETpjrC/S9kaq4/KfyXygAD/NORlNucW5rA k4LLKsN/dEaC6pXEd+Dwe3oCtcbpZ95wMKMS3bXbGRVFF1bIKTCMwOtwe8MB+UUPRSv6Svx33ar /03fjR61aypsxHEcZUyylVSkSenXX6DQbB2pQMKd7KNv+/m/03k8pbx839eC9Bhy9zXuXHpPQdH AdN37VFf X-Received: by 2002:a05:690c:d87:b0:81e:29d9:791f with SMTP id 00721157ae682-89734ac835emr44205777b3.34.1790046198355; Mon, 21 Sep 2026 20:03:18 -0700 (PDT) Received: from localhost.localdomain ([2601:155:4200:2c80:2875:43a3:e345:710c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8a2c1b02abdsm1471447b3.17.2026.09.21.20.03.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 21 Sep 2026 20:03:17 -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 v6 1/2] net: validate virtio checksum start after network header Date: Mon, 21 Sep 2026 23:03:09 -0400 Message-ID: <20260922030310.8684-2-habte.yibelo@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20260922030310.8684-1-habte.yibelo@gmail.com> References: <20260922030310.8684-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() checks a minimum network-header length for CHECKSUM_PARTIAL packets. Its checksum start is relative to skb->data, but some callers have not established skb->network_header when they convert the virtio header. Pass the data-relative L3 origin explicitly. Ethernet receive paths parse the frame and nested VLAN headers without changing skb state. AF_PACKET uses the frame's actual L3 origin even when the socket protocol is ETH_P_IP and the raw frame carries VLAN tags. Non-Ethernet AF_PACKET devices retain their established skb network offset. Also pass the actual L3 protocol so IPv6 packets use the 40-byte base header minimum even without TCPv6 GSO. IFF_TUN obtains that protocol from the packet before skb->protocol is set. Name the Ethernet parser accordingly, use the same origin for tunnel validation, and propagate conversion failures in UML. The bound remains a minimum; fragmentation paths separately validate the parsed IPv4 or IPv6 header length before completing a checksum. 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 Assisted-by: LLM Signed-off-by: Paulos Yibelo --- arch/um/drivers/vector_transports.c | 13 ++++- drivers/net/tun_vnet.h | 52 ++++++++++++++++- drivers/net/virtio_net.c | 10 +++- include/linux/virtio_net.h | 87 ++++++++++++++++++++++++----- net/packet/af_packet.c | 24 +++++++- 5 files changed, 163 insertions(+), 23 deletions(-) diff --git a/arch/um/drivers/vector_transports.c b/arch/um/drivers/vector_t= ransports.c index ddd127ee9..5a9d8f49a 100644 --- a/arch/um/drivers/vector_transports.c +++ b/arch/um/drivers/vector_transports.c @@ -197,6 +197,8 @@ 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; + __be16 network_protocol; + int network_offset; =20 if ((vheader->gso_type !=3D VIRTIO_NET_HDR_GSO_NONE) && (vp->req_size !=3D 65536)) { @@ -209,8 +211,14 @@ 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_eth_get_l3_offset(skb, vheader, + &network_protocol); + if (network_offset < 0) + return network_offset; + + return virtio_net_hdr_to_skb(skb, vheader, + virtio_legacy_is_little_endian(), + network_offset, network_protocol); } =20 static bool get_uint_param( @@ -491,4 +499,3 @@ int build_transport_data(struct vector_private *vp) return build_bess_transport_data(vp); return 0; } - diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h index f4c652b1f..e004213fa 100644 --- a/drivers/net/tun_vnet.h +++ b/drivers/net/tun_vnet.h @@ -177,10 +177,49 @@ 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, + __be16 *network_protocol) +{ + if ((flags & TUN_TYPE_MASK) !=3D IFF_TAP) { + u8 version, first_byte; + const u8 *first; + + *network_protocol =3D 0; + if (!(hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM)) + return 0; + + first =3D skb_header_pointer(skb, 0, sizeof(first_byte), + &first_byte); + if (!first) + return -EINVAL; + + version =3D *first >> 4; + if (version =3D=3D 4) + *network_protocol =3D htons(ETH_P_IP); + else if (version =3D=3D 6) + *network_protocol =3D htons(ETH_P_IPV6); + return 0; + } + + return virtio_net_hdr_eth_get_l3_offset(skb, hdr, + network_protocol); +} + 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)); + __be16 network_protocol; + int network_offset =3D tun_vnet_hdr_get_l3_offset(flags, skb, hdr, + &network_protocol); + + if (network_offset < 0) + return network_offset; + + return virtio_net_hdr_to_skb(skb, hdr, + tun_vnet_is_little_endian(flags), + network_offset, network_protocol); } =20 /* @@ -199,10 +238,19 @@ 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; + __be16 network_protocol; + int network_offset =3D tun_vnet_hdr_get_l3_offset(flags, skb, vnet_hdr, + &network_protocol); + + 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, network_protocol); } =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..8e93dad28 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2502,6 +2502,8 @@ 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; + __be16 network_protocol; + int network_offset; =20 hdr =3D skb_vnet_common_hdr(skb); if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report) @@ -2515,9 +2517,13 @@ 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_eth_get_l3_offset(skb, &hdr->hdr, + &network_protocol); + 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, network_protocol)) { 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..b89d821a0 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -48,16 +48,61 @@ static inline int virtio_net_hdr_set_proto(struct sk_bu= ff *skb, return 0; } =20 +/* + * Return the L3 offset and protocol 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_eth_get_l3_offset(const struct sk_buff *skb, + const struct virtio_net_hdr *hdr, + __be16 *network_protocol) +{ + unsigned int parse_depth =3D VLAN_MAX_DEPTH; + const struct ethhdr *eth; + struct ethhdr ethbuf; + __be16 protocol; + int depth =3D ETH_HLEN; + + *network_protocol =3D 0; + 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; + } + + *network_protocol =3D protocol; + 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, + __be16 network_protocol) { - 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; unsigned int ip_proto; =20 + if (network_protocol =3D=3D htons(ETH_P_IPV6)) + nh_min_len =3D sizeof(struct ipv6hdr); + if (hdr_gso_type !=3D VIRTIO_NET_HDR_GSO_NONE) { switch (hdr_gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { case VIRTIO_NET_HDR_GSO_TCPV4: @@ -98,16 +143,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 +255,12 @@ 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, + __be16 network_protocol) { - 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, network_protocol); } =20 /* This function must be called after virtio_net_hdr_from_skb(). */ @@ -287,7 +339,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 +349,20 @@ 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, + __be16 network_protocol) { 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, network_protocol); =20 /* Tunnel not supported/negotiated, but the hdr asks for it. */ if (!tnl_hdr_negotiated) @@ -332,19 +386,24 @@ 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); + if (network_protocol =3D=3D htons(ETH_P_IPV6)) + outer_l3min =3D sizeof(struct ipv6hdr); =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, network_protocol); if (ret) return ret; =20 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 50cae32ae..0b37d5474 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2550,6 +2550,26 @@ static void tpacket_destruct_skb(struct sk_buff *skb) sock_wfree(skb); } =20 +static int packet_vnet_hdr_to_skb(struct sk_buff *skb, + const struct virtio_net_hdr *vnet_hdr) +{ + __be16 network_protocol =3D 0; + int network_offset; + + if (skb->dev->type =3D=3D ARPHRD_ETHER) { + network_offset =3D virtio_net_hdr_eth_get_l3_offset(skb, vnet_hdr, + &network_protocol); + } else { + network_offset =3D skb_network_offset(skb); + network_protocol =3D skb->protocol; + } + if (network_offset < 0) + return network_offset; + + return virtio_net_hdr_to_skb(skb, vnet_hdr, vio_le(), + network_offset, network_protocol); +} + static int __packet_snd_vnet_parse(struct virtio_net_hdr *vnet_hdr, size_t= len) { if ((vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && @@ -2901,7 +2921,7 @@ 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 (packet_vnet_hdr_to_skb(skb, &vnet_hdr)) { tp_len =3D -EINVAL; goto tpacket_error; } @@ -3103,7 +3123,7 @@ 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 packet_vnet_hdr_to_skb(skb, &vnet_hdr); if (err) goto out_free; len +=3D vnet_hdr_sz; base-commit: 1e24c4f2ee44be0eee94092b5d13cbdb4bdf0d60 --=20 2.46.0 From nobody Fri Sep 25 18:51:54 2026 Received: from mail-yx2-f13.google.com (mail-yx2-f13.google.com [74.125.224.141]) (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 6BEC93B4E9D for ; Tue, 22 Sep 2026 03:03:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790046203; cv=none; b=aEyfYJoxUAg1hwy2RF1FsMlDCIo/Cx400avaLkY/CJ+6Wn8l3oGtWEIjJ58XGCZBvp7LVJOFWnIyXQ6qxWD5CoWBTsbERc8brtAVN7iTCHE8VXgM04qeUJMNp7XeV0g9fPB197aFwLS6twDvjmuGAAwM8790Pc1H5ubh0U3HW3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790046203; c=relaxed/simple; bh=xxPCfoW71C+dY5Vk73+EVbPgQd5ga8fAuuMpvs44aSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=esBXNEBlUATUNPW0/AipyF+nuhWRm0+29y7OK2da3ONiexzoRTSsa9pBZn5dwsMLWIRWS5nYCbqkHqVDj0raMqoDh0je8yVgSX++n2/ew1sVXI3dzD9B8r2z1Hsvfx5a79u9NfGQQ8d1pDYTtUdWJ8pAGM5OsNvb0xCwa5ijT7U= 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=Qh+Elqvl; arc=none smtp.client-ip=74.125.224.141 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="Qh+Elqvl" Received: by mail-yx2-f13.google.com with SMTP id 00721157ae682-85d43db0c16so30094747b3.1 for ; Mon, 21 Sep 2026 20:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790046200; x=1790651000; 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=B5rs7+ILfA3J/8r3zuBgSBRVCSTxSnXx2oYi6bmrhLI=; b=Qh+Elqvl8Z+LZ9x6Jhh8EPOVxKwCr38xJ5hf/CvPrLrahEy8nlF+Hw+JbxmuilcEmh KBoTBLvy9b8EgOgmAe6snoUat1GLn32ck5dl3BW0l7eKvH4X8eSmM7bCLpLNHTpzv7Pq q3mCwfa/BFFAtE9GM7hMrTPfnJiTl7+LJhkkl4/FRd5MjiySuUiSVMSF6u9XAK68tHAX KP6lCmEr/KzPVnHwnNvNho93MCcyC5uMMjdgYlw2bEz2XyOLeVQgBYvjac7n0d6l4Twm 27kkfNnGymTimznSHf25G+rAWc4q4ec3gtolnEK/3eBeIYgjHewXbreBW+euyJt60qlf Y7qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790046200; x=1790651000; 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=B5rs7+ILfA3J/8r3zuBgSBRVCSTxSnXx2oYi6bmrhLI=; b=VR8B3ON+avDL+EjGtj52cEVQxsXqhoIoNYwTGeYj8X4a71H07FnvZ7JU1l5ZZ0Thho vw8sdY9GDcfdXVnyDMc6NU6/0mJQ6iRaacw5p7/9V+dO5YEA6FSonkt5rpwPbkdUBQ3t c5VLwc9gbCTMtV/1NiAgdA6l0MUpTTkN9K7O03YSwSToPg8I1nUZrBYO9Ex/HjuIcwxP 5bxGbl6+QR6LmVtaYc0k2xrxEVzYKnCsYZDR5qdR1Vaz3sGFXdP7+Ui40I3Cj7pxkVZW ePy+Fa2EcAk89Kb6xnymPUDIMy8zZePpj7s6p+PU7BVv603tF9b9rz/QcrT40lq6Ry0v x1JA== X-Forwarded-Encrypted: i=1; AKwUvBwf0FLmFaOlumzWlTa1RITfVgK/vpCDZRR0bGEC/WTasqoFRUqz3qPfdYeb/8TxryuwdIYLj3wTg/1kU9s=@vger.kernel.org X-Gm-Message-State: AFuF++kK/E0WyliNGWYFFfKAYAt72vIb6u8L4axsoPZlf/HwJja1oA2/ 26y06EMntKjaCYVYyFaNTAaVtIyaFqqOTj0YRJK7haf8giCPytRoKxjB X-Gm-Gg: AYBFou1aybZ9Mw91QJ7xF438uIYZWgXkgxPRTWuqyoreLpnyA9+4ia1DoET1Ve+ZHZL c9Ym9VtJToastyvLqPivCm3I+CpL81UPOYQ22kzRmylczySa0uM0Zavz3REETKQ+NvZ4yBzAPsE HqMvH0OK3cEfAP/h1ooPHtB70fsfgXwXLWYaxOUJC6kRH4qNR30849YSx1YK1mmS1yx5y4DMu0A zN47nq7NNhpSdehoaTfRSZh2gNTxwcPJabqBnA6NsnTLzVysfSQDTXfbv3HbQnmhDoUXkupSnug MpH1TlaU9zg8jTSpn2Hk2GdshrqPUS9o4PIupO4iadQu6kBiU6XMj3Yop2twcUny9G5AxSjNozT il+bTBP0bV1HoaX6d93DANc/8xyNcHhRbd5xDXF3g8UxWnPyCMi4L9LSnYQDSnVuzJM2nBlI1TW ABQMT7hPQBUSGZF/JR3h0ZOhlmHGCrbu+hzDXrDyLUws0rgcPFXPO2nFvXF0PCZwM7VMfofdmMp roGUPaFaV8sheEswhcw6CzNfBzTqqYkhPdhY9K7WIlFKGDSM6dCUTs8+xqZTZlkMbszKfAC X-Received: by 2002:a05:690e:138d:b0:668:1c09:aef1 with SMTP id 956f58d0204a3-6717fc7e75dmr3816179d50.6.1790046200291; Mon, 21 Sep 2026 20:03:20 -0700 (PDT) Received: from localhost.localdomain ([2601:155:4200:2c80:2875:43a3:e345:710c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8a2c1b02abdsm1471447b3.17.2026.09.21.20.03.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 21 Sep 2026 20:03:19 -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 v6 2/2] ip: reject partial checksums covering network headers Date: Mon, 21 Sep 2026 23:03:10 -0400 Message-ID: <20260922030310.8684-3-habte.yibelo@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20260922030310.8684-1-habte.yibelo@gmail.com> References: <20260922030310.8684-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 Assisted-by: LLM Signed-off-by: Paulos Yibelo --- 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