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=1796269836; b=T4LRwsXwtfGQcO8/hHEujJkhplEH+994qlewtZ1sCpKHHQA/6xZlyhdKHUbo8Lw5qCP/ 6D1+oq/8Biyqh8LGVqkPsbJ2NiZ+hvCf7tZahWXerpfWzL6sbypyXUlhjgezJ6KjrpcJD IM8im7OjGwUBA2wPUw++PUyuyENmZP0itbiYZs+sRrvKBtx0EV5Kv8PkhLq0XnU3l4lhV F56yJlhG+7fU1zIXrfDDgASHaoNDnEeK7I691+ensT9ceRP7Fi+YcMeF8SUqANH4KwrW1 PVAQzG/CiGYyRJfejtKKgSHg7CwNkJEhDMvD08vG9bAptVAPWdsUeB9iLhP4/nT4PEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796269836; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=QWHpTH4XOM9Rdx8RCYc9JS213wjBxIkVBAuaP/c/h8w=; b=UV2aqWQ6wkLeN0+0nEoxEvzNKm5RlKAP4F1NdG8fauVccHcu8NCa0hQcMHCUKsL5c9QO roPxU+UsVXNxSd9E/lKOCBx5+OL3GnClJJ4gv99h9+O6Bh6lMjJZtl8MjZKy71nQvhKfm U3YFEJSKUlIjjMAX0sPiRp7OOac8G6SFNQdB5UREcQiXhn24x0ZQU57SfMSAJ+OMbn+51 toqtioC2IVh65pIwOERKg3eVqUb/C8SPo3/j20wHjBUlaysIhDAWjsc66Z7ngMnNUm0QV bPvUySMZTyLdmyZLjp+266L+Ne8hmfqJUiw+GzEyNQd66XOKJ6/woS5v/lmGlyh+rqg== 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=l9HKX7Oe; 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 2F871606A333 for ; Thu, 3 Dec 2026 03:50:36 +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=l9HKX7Oe Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFB601F00896; Thu, 3 Dec 2026 03:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796269836; bh=QWHpTH4XOM9Rdx8RCYc9JS213wjBxIkVBAuaP/c/h8w=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=l9HKX7OeFVhDiNZw5gndrwuakQlUtPOYEo1fP0rUIbPqMqXcF9uiIrhgcTp2xHPOb q8iBpw5MtUUwG0tAvD30Zl63tXaV+IDMYYkHkrdQKdLpEUHQBcihNTP9zZii8zK3Bh JWitf6Qum20fty3Jb1slSB6RLKsI7AwsoZ7kT895lenFimOOT20ioEx8tdBYkV8mly UJXWGe4nj5+lO9dj/pz9vjxq3Iq4FAPUI0YQt+uEBflxVbtyge/SnoQv2WBIlFicr3 TVuXiFtCT0fBe4jg1azHaDFl+QcOmWVmSw815R4DvuLgv8kJKjMxL16a+5IyTu4ZXX EVhzrkhpvv6CA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC net v9 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: <20261202.rfcv9.41657.4.zakinko@snowrabbit.org> References: <20261202.rfcv9.41657.0.zakinko@snowrabbit.org> <20261202.rfcv9.41657.4.zakinko@snowrabbit.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 03:50:35 +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 1189b78d6e449bf88c220fd19b87c9ad4b15891d Author: Michael S. Tsirkin net: resolve uncommon partial checksums at ingress This commit validates VIRTIO_NET_HDR_F_NEEDS_CSUM checksum offsets against parsed L2, L3, and TCP/UDP headers at ingress, completing non-GSO checksums in software and dropping GSO packets when validation fails. > 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 in virtio_net_l3_start() before header validation finishes leave skb->protocol polluted when virtio_net_csum_partial_ok() subsequently fails? In the has_eth branch, skb->protocol is assigned before __vlan_get_protocol= () and virtio_net_l4_start() validate the packet; in the !has_eth branch, it is assigned after checking only the 4-bit version nibble. When validation fai= ls and virtio_net_hdr_to_skb() falls back to software checksum completion via __virtio_net_resolve_csum_partial_mismatch(), skb->transport_header is restored, but skb->protocol is not. As a regression on AF_PACKET sockets sent with proto =3D=3D htons(ETH_P_ALL) (where packet_snd() and tpacket_fill_skb() intentionally leave skb->protocol as 0), a SOCK_DGRAM packet whose Ethernet header carries htons(ETH_P_ALL) fails L3 validation but continues through __virtio_net_resolve_csum_partial= _mismatch() with skb->protocol set to the wildcard htons(ETH_P_ALL), and a SOCK_RAW packet with a truncated VLAN tag or a non-IP payload starting with nibble 4 or 6 keeps the unvalidated skb->protocol so packet_parse_headers() skips dev_parse_header_protocol(). > @@ -190,6 +198,77 @@ virtio_net_l4_start(struct sk_buff *skb, unsigned in= t nhoff, __be16 proto, [ ... ] > +/* > + * 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 VIRTIO_NET_HDR_F_NEEDS_CSUM and a non-zero hdr->gso_type bypass mismatch rejection when its payload does not exceed hdr->gso_size? In __virtio_net_hdr_to_skb(), when VIRTIO_NET_HDR_F_NEEDS_CSUM is set, the flow dissector check is skipped and shinfo->gso_size is only populated when skb->len - nh_off > gso_size. If hdr->gso_type is set (for example, VIRTIO_NET_HDR_GSO_TCPV4) with gso_size >=3D skb->len - nh_off on a frame t= hat does not match hdr->gso_type, virtio_net_csum_partial_ok() returns false, b= ut skb_is_gso(skb) is false, so __virtio_net_resolve_csum_partial_mismatch() completes the checksum and returns 1 instead of -EINVAL. In packet_snd() and tpacket_snd(), any non-zero vnet_hdr.gso_type bypasses = the dev->mtu check, and if virtio_net_l3_start() fails before setting skb->protocol (for instance, when !has_eth and the first nibble is neither 4 nor 6, or when eth_hdr(skb)->h_proto is 0), virtio_net_hdr_set_proto() 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 reinstate a stale transport_header offset on sk= bs recycled via napi_get_frags()? No caller of virtio_net_hdr_to_skb() sets skb->transport_header for the current frame beforehand, and on IFF_NAPI_FRAGS TAP devices, tun_napi_alloc_frags() obtains tfile->napi.skb from napi_get_frags(), where napi_reuse_skb() preserves skb->transport_header from the previous GRO-merged packet. When virtio_net_csum_partial_ok() fails, restoring old_transport puts back that stale (and potentially out-of-bounds) offset, which makes skb_transport_header_was_set(skb) true and causes the subsequent skb_probe_transport_header() in tun_get_user() to return without probing the new frame. Would unsetting skb->transport_header (~0U) on mismatch avoid exposing 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 deriving has_eth from dev->type here desynchronize validation from the actual frame layout on TUNSETLINK-modified IFF_TAP devices, non-Ethernet devices with a link-layer header, and VLAN-tagged frames on ARPHRD_LOOPBACK? On an IFF_TAP device, __tun_chr_ioctl() also permits TUNSETLINK to change dev->type away from ARPHRD_ETHER while leaving dev->header_ops as ð_header_ops and dev->hard_header_len as ETH_HLEN. For such a TAP device (and for non-Ethernet devices with hard_header_len > 0), packet_snd() and tpacket_fill_skb() place a link-layer header at skb->data and set skb_network_offset(skb) to hard_header_len, while packet_vnet_hdr_to_skb() passes has_eth =3D false. Because the !has_eth branch of virtio_net_l3_sta= rt() starts at *nhoff =3D skb_network_offset(skb) without requiring *nhoff =3D= =3D 0, it skips the leading link-layer bytes without checking eth_hdr(skb)->h_proto or VLAN tags, sets skb->protocol from the nibble at *nhoff (causing packet_parse_headers() to skip dev_parse_header_protocol()), and keeps CHECKSUM_PARTIAL active. Conversely, on ARPHRD_LOOPBACK devices, packet_vnet_hdr_to_skb() passes has_eth =3D true and virtio_net_l3_start() walks past VLAN tags to validate= the checksum and retain CHECKSUM_PARTIAL, whereas packet_parse_headers() only advances skb->network_header past VLAN tags when skb->dev->type =3D=3D ARPHRD_ETHER: net/packet/af_packet.c:packet_parse_headers() { ... if (likely(skb->dev->type =3D=3D ARPHRD_ETHER) && eth_type_vlan(skb->protocol) && vlan_get_protocol_and_depth(skb, skb->protocol, &depth) !=3D 0) skb_set_network_header(skb, depth); ... } That leaves skb->network_header pointing at the VLAN tag on ARPHRD_LOOPBACK while CHECKSUM_PARTIAL remains set for the inner L4 header. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202.rfcv9.4165= 7.0.zakinko@snowrabbit.org?part=3D4