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=1796443313; b=R8UDPCsoHeApcUaxEY6jh3RhOamREiC0NxyHjfGV4JC+keWlhWdKh5P9303G+PLgCsdW g1arJsx28pcrqk1CqOp1EHh/6Md0xYqT6pt0i+Mqa5G+XOwh3eqd5zBWqQo0cOuDFPRXu AfdP11eA04mROP5e/4Br1vkR894p4uWciMy82iPRVHfcFFCRj0igBP3FvVZyJSMlTkHoW iefGP+t8fLlHjOiwH3fvKsP7iRht6c1uLaxV1ydP4g8yGniePAU6xjitp4Ho5oUMMeMRJ n/1n0OBE3RcASRX7Jxt1PAjBInATYIfN02LwRffnijvleB1crM+w0aa1uQBE7xe0Asw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443313; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=9BMzCF+nQMjchBsNwi8QYonlltW5WFf19Us3QaHQe0Y=; b=5KRx4CRI1yZq4mcXmWnoMhYHvi4Sp1pBmzGTaIXkyNo5uEw6CfsUD8s81nz/FDTNHrZc XqgtiBCofELMUKutMhyv3Pyg9sqgQA9y8MhM59U0RiJlWMEZsGo2Lq9ZVTdbipuvKHc+x KU6/8ax1FsPOzF43BqI/jI9M9pQhkv2N/8SouVc30GDe/ahaN4Sr4B78PFg7g/WFBLiVf cI/VHiIYjmbs+/y+4gGMkE2gVslxyie40MXWSGTYU6bubNq2qTyrLyfYLIupN9nadyLT5 L5FeoTHk/ao4TjqfQqDhSbFhFvOv2T9ijQ2cashoY4VyNJSDnhkZdmYPq9kbm8tT5Jw== 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="BQJ34f/4"; 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 7C18D606A32F for ; Sat, 5 Dec 2026 04:01:53 +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=BQJ34f/4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5F0B1F00A07; Sat, 5 Dec 2026 04:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796443313; bh=9BMzCF+nQMjchBsNwi8QYonlltW5WFf19Us3QaHQe0Y=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=BQJ34f/4e8Llv1VgqHXqjqQzUrjtqTD5kgMIevtLEZOi0R9AsvhaNq1/ByJp1E5Do O7BG+N+KQB9umZ6u40UVlj2j2WT81lEwDRaMKHu1+F798YsA8KZnDLvGO8g48cv/gw 2Bz6KeJ4I6D/YiHPYsSyBwSLcWZ2TAW9KIO9T0rtiA1ijT1gaaG9uDbImuVkQP9UgV Bcr4ipM5zqWCwlJK3MaHHzmyMoWe1VK60ygSoobdoiil62VTbvgLcVufDZZVymBRNF b0nCnuqYrLJS6OoLkeEMLzil31nQ8smpA/IvPg1RRDfsPkhbOxrovhb8sQ8hL6M9FR VubDGfzkUwESw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC net v11 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: <20261204.rfcv11.99731.4.zakinko@snowrabbit.org> References: <20261204.rfcv11.99731.0.zakinko@snowrabbit.org> <20261204.rfcv11.99731.4.zakinko@snowrabbit.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:01:52 +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 8 potential issues to consider: - [High] net/packet: unexported eth_header_ops in packet_vnet_hdr_to_skb() - [High] net: non-Ethernet link-header devices bypass virtio_net_l3_start() check - [Medium] net: virtio_net_csum_partial_ok_at_offset() pulls unread tcphdr bytes on non-GSO - [Medium] net: virtio_net_csum_partial_ok_at_offset() drops NSH GSO and breaks nsh_gso.sh - [Medium] virtio_net: virtio_net_l3_start() mutates skb->protocol on failed validation - [Medium] virtio_net: virtio_net_hdr_to_skb() restores stale transport_header - [Medium] tun: shared atomic64_t rx_csum_sw false-shares hot cacheline in tun_struct - [Medium] packet: unlocked dev->header_ops/type reads in packet_vnet_hdr_to_skb() -- commit bbc09c06c4fccf93de5eb92627de4a572115b649 Author: Michael S. Tsirkin net: resolve uncommon partial checksums at ingress This commit validates virtio_net_hdr CHECKSUM_PARTIAL metadata against the parsed TCP or UDP header at ingress, dropping unrecognized GSO packets and completing unmatched non-GSO checksums in software. > 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] Can virtio_net_l3_start() leave skb->protocol mutated when checksum validation fails? virtio_net_l3_start() sets skb->protocol before VLAN, L3, and L4 validation succeed, and virtio_net_hdr_to_skb() only restores skb->transport_header on mismatch before completing the checksum in software. On an IFF_TUN device = in PI mode, if userspace sends pi.proto =3D=3D 0 with VIRTIO_NET_HDR_F_NEEDS_C= SUM and a short non-IP frame starting with 0x60, virtio_net_l3_start() sets skb->protocol to htons(ETH_P_IPV6) from the first byte before virtio_net_l4_start() fails. tun_get_user() then injects the frame into ipv6_rcv() instead of leaving skb->protocol as 0. On AF_PACKET SOCK_RAW wi= th proto =3D=3D 0 or ETH_P_ALL, the mutated skb->protocol also causes packet_parse_headers() to skip dev_parse_header_protocol(). Saving and restoring skb->protocol on mismatch in virtio_net_hdr_to_skb(), = or only writing skb->protocol after validation succeeds, would avoid this. > @@ -190,6 +198,77 @@ virtio_net_l4_start(struct sk_buff *skb, unsigned in= t nhoff, __be16 proto, > return false; > } > =20 > +/* Does checksum metadata match a known TCP or UDP header? */ > +static inline bool > +virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_typ= e, > + unsigned int nhoff, __be16 proto) > +{ > + unsigned int thoff; > + int ip_proto; > + > + if (!virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto)) > + return false; [Severity: Medium] Does this drop valid NSH-encapsulated GSO packets and break the in-tree tools/testing/selftests/net/nsh_gso.sh selftest? nsh_gso.c sends ETH_P_NSH frames with VIRTIO_NET_HDR_F_NEEDS_CSUM and VIRTIO_NET_HDR_GSO_TCPV4 over AF_PACKET PACKET_VNET_HDR. Because virtio_net_l4_start() only handles ETH_P_IP and ETH_P_IPV6, virtio_net_csum_partial_ok_at_offset() returns false and __virtio_net_resolve_csum_partial_mismatch() drops the GSO packet with -EINVAL, so nsh_gso.sh transmits 0 packets instead of 4 under the default configuration. > + if (skb_checksum_start_offset(skb) !=3D thoff) > + return false; > + > + switch (ip_proto) { > + case IPPROTO_TCP: > + if (skb->csum_offset !=3D offsetof(struct tcphdr, check) || > + !pskb_may_pull(skb, thoff + sizeof(struct tcphdr))) > + return false; > + break; > + case IPPROTO_UDP: > + if (skb->csum_offset !=3D offsetof(struct udphdr, check) || > + !pskb_may_pull(skb, thoff + sizeof(struct udphdr))) > + return false; > + break; [Severity: Medium] Does pskb_may_pull(skb, thoff + sizeof(struct tcphdr)) trigger an unnecessa= ry __pskb_pull_tail() on every non-GSO TCP packet on tun/tap zerocopy TX? When hdr->hdr_len is 0 (the default from virtio_net_hdr_from_skb()), __tun_vnet_hdr_get() computes hdr_len as csum_start + csum_offset + 2, which stops right after tcphdr->check and leaves skb_headlen(skb) 2 bytes short of thoff + sizeof(struct tcphdr) in tun_get_user() and tap_get_user(). Neither this helper nor virtio_net_hdr_to_skb() dereferences struct tcphdr, so checking skb->len < thoff + sizeof(struct tcphdr) (and sizeof(struct udphdr= )) would enforce the same length check without pulling unread fragment data. [ ... ] > +/* > + * 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] Returning 1 here makes atomic64_inc(&tun->rx_csum_sw) in tun_get_user() and tun_xdp_one() reachable for the first time, which can cause cacheline false sharing on multiqueue tun devices. In struct tun_struct (added in commit "net: account for ingress-resolved virtio net hdr state"), rx_csum_sw sits in a contiguous 44-byte span with rx_batched, xdp_prog, steering_prog, and filter_prog, which are read on eve= ry RX and TX packet across all queues. Unmatched non-GSO CHECKSUM_PARTIAL traffic on one queue will bounce that cacheline across CPUs handling healthy queues. Using a per-CPU counter summed in tun_get_ethtool_stats() would avoid the contention and false sharing. > @@ -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 re-expose a stale transport_header offset on recycled skbs? On an IFF_TAP | IFF_NAPI | IFF_NAPI_FRAGS device with gro_flush_timeout and napi_defer_hard_irqs configured (where busy_poll_stop() or tun_napi_poll() keeps packets held in tfile->napi.gro across tun_get_user() calls), napi_reuse_skb() recycles GRO-merged skbs into tfile->napi.skb without unsetting transport_header, and tun_napi_alloc_frags() only clears skb->protocol. Restoring that stale offset on mismatch leaves skb_transport_header_was_set(skb) true, so skb_probe_transport_header() in tun_get_user() returns immediately and passes a wrong or out-of-bounds transport_header downstream. Calling skb_unset_transport_header(skb) on mismatch (here and in virtio_net_hdr_tnl_to_skb() in commit "net: virtio: compute the outer checksum of non-GSO tunnel packets") would avoid preserving stale offsets. [ ... ] > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c > index 930e85e4bf739..7ae70ca1556e4 100644 > --- a/net/packet/af_packet.c > +++ b/net/packet/af_packet.c > @@ -2778,6 +2778,24 @@ 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. It can also make an IFF_TAP device something > + * else, while the device still builds and parses Ethernet headers. > + */ > +static int packet_vnet_hdr_to_skb(struct sk_buff *skb, > + const struct virtio_net_hdr *vnet_hdr) > +{ > + const struct net_device *dev =3D skb->dev; > + bool has_eth =3D dev_has_header(dev) && > + (dev->type =3D=3D ARPHRD_ETHER || > + dev->type =3D=3D ARPHRD_LOOPBACK || > + dev->header_ops =3D=3D ð_header_ops); > + > + return virtio_net_hdr_to_skb(skb, vnet_hdr, has_eth, vio_le()); > +} [Severity: High] Does referencing eth_header_ops break the build when CONFIG_PACKET=3Dm? eth_header_ops in net/ethernet/eth.c is not exported with EXPORT_SYMBOL(), = so modpost fails with an undefined symbol for af_packet.ko. [Severity: High] Can non-Ethernet devices that still have link-layer headers (such as ipgre = or ipoib) bypass the ingress CHECKSUM_PARTIAL validation here? On an NBMA ipgre device (ARPHRD_IPGRE, ipgre_header_ops, hard_header_len = =3D=3D 24), has_eth evaluates to false, routing the skb into the raw-L3 branch of virtio_net_l3_start(). For SOCK_RAW frames with len >=3D 64 (or tpacket_sn= d()), skb_network_offset(skb) is 24, so virtio_net_l3_start() skips the leading 24-byte tnl_params unvalidated and validates an inner IP/UDP/TCP header with csum_start >=3D 44. ipgre_xmit() then pulls those 24 bytes, encapsulates w= ith attacker-controlled tnl_params->protocol, and forwards across veth into the host stack with CHECKSUM_PARTIAL still misaligned into the outer payload. (For short SOCK_RAW packets where packet_snd() resets network_header to 0, virtio_net_l3_start() validates the GRE pseudo-header itself as an IPv4 header with options.) Non-Ethernet devices with dev_has_header(dev) should not fall through to the raw-L3 validation branch and should resolve the checksum in software instea= d. [Severity: Medium] Can these unlocked reads of dev->header_ops and dev->type race with concurrent netdevice type changes and cause a NULL pointer dereference in dev_has_header()? packet_snd() and tpacket_snd() hold neither rtnl_lock() nor rcu_read_lock(). When a non-Ethernet port with NULL header_ops (such as nlmon or bareudp) is added to an IFF_UP team device, team_port_add() -> team_setup_by_port() clears dev->header_ops and updates dev->type concurrently. Because dev_has_header() evaluates dev->header_ops && dev->header_ops->create witho= ut READ_ONCE(), a compiler reload between the check and dereference can oops: CPU0 CPU1 packet_snd() packet_vnet_hdr_to_skb() dev_has_header(dev) if (dev->header_ops) team_port_add() ... team_setup_by_port() dev->header_ops =3D NULL dev->header_ops->create <-- NULL pointer dereference Even without a reload, the multiple plain reads of dev->header_ops and dev->type are data races that can compute an inconsistent has_eth. Snapshotting READ_ONCE(dev->header_ops) and READ_ONCE(dev->type) once into locals (paired with WRITE_ONCE() on the writers) would prevent this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204.rfcv11.997= 31.0.zakinko@snowrabbit.org?part=3D4