From: sashiko-bot@kernel.org
To: "Showta Ishizaki" <zakinko@snowrabbit.org>
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress
Date: Sat, 05 Dec 2026 04:01:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-251041@kernel.org> (raw)
In-Reply-To: <20261204.rfcv11.99731.4.zakinko@snowrabbit.org>
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 <mst@redhat.com>
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_eth, int *nhoff,
> */
> if (skb->protocol && skb->protocol != 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 = h_proto;
> *nhoff = ETH_HLEN;
> *proto = 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 != *proto)
> return false;
> + if (!skb->protocol)
> + skb->protocol = *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 == 0 with VIRTIO_NET_HDR_F_NEEDS_CSUM
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 with
proto == 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 int nhoff, __be16 proto,
> return false;
> }
>
> +/* 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_type,
> + 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) != thoff)
> + return false;
> +
> + switch (ip_proto) {
> + case IPPROTO_TCP:
> + if (skb->csum_offset != offsetof(struct tcphdr, check) ||
> + !pskb_may_pull(skb, thoff + sizeof(struct tcphdr)))
> + return false;
> + break;
> + case IPPROTO_UDP:
> + if (skb->csum_offset != 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 unnecessary
__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_buff *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 every
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;
> }
>
> +/*
> + * @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 = skb->transport_header;
> + int ret = __virtio_net_hdr_to_skb(skb, hdr, little_endian,
> + hdr->gso_type);
> +
> + if (ret < 0)
> + return ret;
> +
> + if (likely(skb->ip_summed != 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 = 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;
> }
>
> +/* 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 = skb->dev;
> + bool has_eth = dev_has_header(dev) &&
> + (dev->type == ARPHRD_ETHER ||
> + dev->type == ARPHRD_LOOPBACK ||
> + dev->header_ops == ð_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=m?
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 ==
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 >= 64 (or tpacket_snd()),
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 >= 44. ipgre_xmit() then pulls those 24 bytes, encapsulates with
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 instead.
[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 without
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 = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=4
next prev parent reply other threads:[~2026-12-05 4:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot [this message]
2026-12-04 4:06 ` [PATCH RFC net v11 0/6] more virtio-net csum hardening netdev-bot+sinfo
2026-12-05 4:01 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-251041@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
--cc=zakinko@snowrabbit.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.