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 v9 4/6] net: resolve uncommon partial checksums at ingress
Date: Thu, 03 Dec 2026 03:50:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-247120@kernel.org> (raw)
In-Reply-To: <20261202.rfcv9.41657.4.zakinko@snowrabbit.org>
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 <mst@redhat.com>
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_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]
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 fails
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 == 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 int 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_buff *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 >= skb->len - nh_off on a frame that
does not match hdr->gso_type, virtio_net_csum_partial_ok() returns false, but
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;
> }
>
> +/*
> + * @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 reinstate a stale transport_header offset on skbs
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;
> }
>
> +/* 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 = dev_has_header(skb->dev) &&
> + (skb->dev->type == ARPHRD_ETHER ||
> + skb->dev->type == 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 = false. Because the !has_eth branch of virtio_net_l3_start()
starts at *nhoff = skb_network_offset(skb) without requiring *nhoff == 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 = 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 ==
ARPHRD_ETHER:
net/packet/af_packet.c:packet_parse_headers() {
...
if (likely(skb->dev->type == ARPHRD_ETHER) &&
eth_type_vlan(skb->protocol) &&
vlan_get_protocol_and_depth(skb, skb->protocol, &depth) != 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202.rfcv9.41657.0.zakinko@snowrabbit.org?part=4
next prev parent reply other threads:[~2026-12-03 3:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 4:00 [PATCH RFC net v9 0/6] more virtio-net csum hardening Showta Ishizaki
2026-12-02 4:00 ` [PATCH RFC net v9 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
2026-12-02 4:00 ` [PATCH RFC net v9 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
2026-12-02 4:00 ` [PATCH RFC net v9 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
2026-12-03 3:50 ` sashiko-bot [this message]
2026-12-02 4:00 ` [PATCH RFC net v9 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
2026-12-02 21:06 ` Chris Arges
2026-12-03 1:39 ` Showta Ishizaki
2026-12-02 4:00 ` [PATCH RFC net v9 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
2026-12-02 4:00 ` [PATCH RFC net v9 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
2026-12-03 3:50 ` [PATCH RFC net v9 0/6] more virtio-net csum hardening 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-247120@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.