From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796349289; b=ytW/5Qpg/thwTOaFgPVZ1Y3xe04CKHqum3Umtvu9rHPv17PqbVmUt5+yMg2cmHkLy78T 6fE/aKj8iTct/Tdlr2HVe1o8tJh3vseb3145s+cZxKeyg4vSSsYh/yr3uY1X8ND2CNTXI g2r8O+jXrbUBtwAoolHlde+GZ52G2oYkXkbcg/wPTSyeuCtJbbXj2K4nEDdkT/nCLacJU M4PANHR3kVd9nN1rQij0XH2zGHVOoz4+UPh+J11ZyvmQOBCQaK3be6RtOUL/KpvuPN0s8 MA69MAriKOJnOIo1LcDkPEccl0IEvRJ6Vn8pFISWMyAQDYE5qekqeXzD9VfQvhyjpew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796349289; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ukepxsAkneH8rx4HEUjzwQYF8R0kclGlYvKzniZmyvo=; b=K3sWy2IGxF1EfUvVDRYYL3g12CWpCot9KQ742y8tlA6+mR3z3OV0fPyXL4v+Gv9NhYNl mGmmh7+ceHIJqoa961kwlDoYxq/xKctcxHt/46Ihc7GHxFf0LMXAT7ng7loDK4cpSl1ii JsBmaUnz6s1xhn3yVagIk4HSKWuWMsszgbu0iysEQUcLjMtoccPQSRrqJerGOzrXsZyv/ xwYCk4qtP4InR9XOdkmV6mxDONgIUxeVFQH50d8hpbp5kJksqLIpk/M1QqFpg0iHMHwWU PD9xIU0TeshM3yLLrJyMMsHjovtXKJSqJX1MhlgNpqPj79eMXRUpPYjYZkQGafxjHyw== 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=oenp6QjR; arc=none smtp.remote-ip=100.103.45.18 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 921A5606A335 for ; Fri, 4 Dec 2026 01:54:49 +0000 (UTC) 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=oenp6QjR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EEF91F00897; Fri, 4 Dec 2026 01:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796349289; bh=ukepxsAkneH8rx4HEUjzwQYF8R0kclGlYvKzniZmyvo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=oenp6QjRrrdTiMDlqoQ09uopyfnjKeclwvZmr4dcd5rxtwKIhxmuEa22i3faMbtOV NHlXFf1zKDEPpkmsOttJa1CuVzuqZR8RNvqgNbYjFESasfBRzyZtDot8oFJrCtKNQH 488CjEmK+wXG2BKkoFpsmmqORv8uUATE9m0XbZJDG39uGvMBIPwzWLzavbWxekuRJr 4Nh95a1EUvDhB9xOi+wSK35zaY47P9VNL+4jZGsdf09heK+uMxWEFAgGFkeywhAsaH aRM3FZ8FzRN2lqNsHgHfKzmTSyENj90omfZoM50Ka22Xs4FD4/d8lf/M2+p6lSJsIj 3os356HDis08A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC net v10 4/6] net: resolve uncommon partial checksums at ingress Reply-To: sashiko-reviews@lists.linux.dev To: "Showta Ishizaki" Cc: virtualization@lists.linux.dev, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261203.rfcv10.52108.4.zakinko@snowrabbit.org> References: <20261203.rfcv10.52108.0.zakinko@snowrabbit.org> <20261203.rfcv10.52108.4.zakinko@snowrabbit.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 01:54:48 +0000 X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] net: L2 header and nhoff mismatch in packet_vnet_hdr_to_skb() and l3_start() - [Medium] virtio_net: unrestored skb->protocol in virtio_net_hdr_to_skb() on mismatch - [Medium] virtio_net: sub-MSS packets with gso_type bypass mismatch rejection - [Medium] virtio_net: virtio_net_hdr_to_skb() restores stale transport_header on frags -- commit 76b1117821e72d51ddb2945bbe6b430d1606893a Author: Michael S. Tsirkin net: resolve uncommon partial checksums at ingress This commit validates virtio_net_hdr csum_start and csum_offset against parsed TCP and UDP headers on ingress, completing non-GSO checksums in software and dropping GSO packets when the checksum metadata does not match. > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h > index 3135dae031a4d..714b20acd38f0 100644 > --- a/include/linux/virtio_net.h > +++ b/include/linux/virtio_net.h > @@ -111,6 +111,12 @@ virtio_net_l3_start(struct sk_buff *skb, bool has_et= h, int *nhoff, > */ > if (skb->protocol && skb->protocol !=3D h_proto) > return false; > + /* Fill in a missing claim from the frame, so that a later > + * guess (virtio_net_hdr_set_proto()) cannot disagree > + * with what is validated here. > + */ > + if (!skb->protocol) > + skb->protocol =3D h_proto; > *nhoff =3D ETH_HLEN; > *proto =3D h_proto; > if (eth_type_vlan(*proto)) { > @@ -141,6 +147,8 @@ virtio_net_l3_start(struct sk_buff *skb, bool has_eth= , int *nhoff, > return false; > if (skb->protocol && skb->protocol !=3D *proto) > return false; > + if (!skb->protocol) > + skb->protocol =3D *proto; > } > return true; > } [Severity: Medium] Does setting skb->protocol here leave it mutated when virtio_net_csum_partial_ok() subsequently fails? virtio_net_l3_start() writes skb->protocol before VLAN, L3, and L4 header validation completes, and virtio_net_hdr_to_skb() only restores skb->transport_header before falling back to software checksum completion in __virtio_net_resolve_csum_partial_mismatch(). On an AF_PACKET socket sent with proto =3D=3D htons(ETH_P_ALL) (where packet_snd() and tpacket_fill_skb() intentionally leave skb->protocol as 0), a failed validation leaves skb->protocol polluted with an unvalidated value (such as htons(ETH_P_ALL) on SOCK_DGRAM) and causes packet_parse_headers() to skip dev_parse_header_protocol(skb) on SOCK_RAW. > @@ -190,6 +198,77 @@ virtio_net_l4_start(struct sk_buff *skb, unsigned in= t nhoff, __be16 proto, > return false; > } [ ... ] > +/* > + * Handle a packet whose checksum metadata does not match the packet: > + * GSO packets are dropped, as segmentation needs one checksum per > + * segment; others are completed in software. > + */ > +static inline int __virtio_net_resolve_csum_partial_mismatch(struct sk_b= uff *skb) > +{ > + if (skb_is_gso(skb)) > + return -EINVAL; > + > + return skb_checksum_help(skb) ?: 1; > +} [Severity: Medium] Can a packet with hdr->gso_type !=3D VIRTIO_NET_HDR_GSO_NONE bypass this GSO rejection when its payload does not exceed hdr->gso_size? In __virtio_net_hdr_to_skb(), shinfo->gso_size is only populated when skb->len - nh_off > gso_size, so skb_is_gso(skb) is false for a packet with a non-zero hdr->gso_type and a large gso_size. When virtio_net_csum_partial_ok() fails on such a packet, completing the checksum and returning 1 instead of -EINVAL allows AF_PACKET callers to bypass the !vnet_hdr.gso_type MTU check in packet_snd() and tpacket_snd(), and if skb->protocol is still 0 (for example when virtio_net_l3_start() failed before setting it), the subsequent virtio_net_hdr_set_proto() call still relabels skb->protocol from the unvalidated vnet_hdr.gso_type. > @@ -336,11 +415,38 @@ static inline int __virtio_net_hdr_to_skb(struct sk= _buff *skb, > return 0; > } > =20 > +/* > + * @has_eth: the frame starts with an Ethernet header, see > + * virtio_net_l3_start(). > + * > + * Return value: > + * 0 - success > + * >0 - checksum was completed in software (slow path) > + * <0 - failure > + */ > static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, > const struct virtio_net_hdr *hdr, > - bool little_endian) > + bool has_eth, bool little_endian) > { > - return __virtio_net_hdr_to_skb(skb, hdr, little_endian, hdr->gso_type); > + typeof(skb->transport_header) old_transport =3D skb->transport_header; > + int ret =3D __virtio_net_hdr_to_skb(skb, hdr, little_endian, > + hdr->gso_type); > + > + if (ret < 0) > + return ret; > + > + if (likely(skb->ip_summed !=3D CHECKSUM_PARTIAL || > + virtio_net_csum_partial_ok(skb, has_eth, hdr->gso_type))) > + return 0; > + > + /* > + * Here we do not trust the checksum metadata. > + * __virtio_net_hdr_to_skb set the transport header to csum_start > + * from virtio hdr, restore it to a known good value. > + */ > + skb->transport_header =3D old_transport; > + > + return __virtio_net_resolve_csum_partial_mismatch(skb); > } [Severity: Medium] Can restoring old_transport leave skb->transport_header pointing at a stale offset from a previous packet on IFF_NAPI_FRAGS TAP devices? When tun_get_user() allocates an skb via tun_napi_alloc_frags() -> napi_get_frags(), napi_reuse_skb() recycles tfile->napi.skb after a GRO merge without resetting skb->transport_header. Previously, skb_partial_csum_set() always overwrote that stale offset when VIRTIO_NET_HDR_F_NEEDS_CSUM was set. Restoring old_transport on mismatch re-exposes the previous frame's transport_header offset, which makes skb_transport_header_was_set(skb) true and causes the subsequent skb_probe_transport_header(skb) in tun_get_user() to skip probing the new frame. Unsetting skb->transport_header to ~0U on mismatch would avoid keeping the stale offset. [ ... ] > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c > index 930e85e4bf739..1362da6232abb 100644 > --- a/net/packet/af_packet.c > +++ b/net/packet/af_packet.c > @@ -2778,6 +2778,21 @@ static int tpacket_parse_header(struct packet_sock= *po, void *frame, > return tp_len; > } > =20 > +/* The device says how its frames start. dev->type alone does not: > + * TUNSETLINK can make an IFF_TUN device ARPHRD_ETHER while its frames > + * still start with the L3 header, and such a device has no link layer > + * header to create. > + */ > +static int packet_vnet_hdr_to_skb(struct sk_buff *skb, > + const struct virtio_net_hdr *vnet_hdr) > +{ > + bool has_eth =3D dev_has_header(skb->dev) && > + (skb->dev->type =3D=3D ARPHRD_ETHER || > + skb->dev->type =3D=3D ARPHRD_LOOPBACK); > + > + return virtio_net_hdr_to_skb(skb, vnet_hdr, has_eth, vio_le()); > +} [Severity: Medium] Does checking skb->dev->type here still allow TUNSETLINK on an IFF_TAP device (or any non-Ethernet device with hard_header_len > 0) to skip L2 header validation? __tun_chr_ioctl() allows TUNSETLINK on an IFF_TAP device as well, which changes dev->type while leaving dev->header_ops as ð_header_ops and dev->hard_header_len as ETH_HLEN. On such a TAP device, packet_snd() and tpacket_fill_skb() still place a 14-byte Ethernet header at the start of skb->data and set skb_network_offset(skb) to 14, but has_eth evaluates to false. Because the !has_eth branch of virtio_net_l3_start() starts at *nhoff =3D skb_network_offset(skb) without requiring *nhoff =3D=3D 0, it sk= ips the leading 14 bytes without checking eth_hdr(skb)->h_proto or VLAN tags, sets skb->protocol from the IP version nibble at offset 14 (causing packet_parse_headers() to skip dev_parse_header_protocol()), and keeps CHECKSUM_PARTIAL and GSO enabled. In addition, setting has_eth =3D true for ARPHRD_LOOPBACK allows virtio_net_l3_start() to validate VLAN-tagged frames and retain CHECKSUM_PARTIAL, whereas packet_parse_headers() only advances skb->network_header past VLAN tags when skb->dev->type =3D=3D ARPHRD_ETHER. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203.rfcv10.521= 08.0.zakinko@snowrabbit.org?part=3D4