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 v10 4/6] net: resolve uncommon partial checksums at ingress
Date: Fri, 04 Dec 2026 01:54:48 +0000 [thread overview]
Message-ID: <sashiko-outbox-248923@kernel.org> (raw)
In-Reply-To: <20261203.rfcv10.52108.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 76b1117821e72d51ddb2945bbe6b430d1606893a
Author: Michael S. Tsirkin <mst@redhat.com>
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_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 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 == 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 int 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_buff *skb)
> +{
> + if (skb_is_gso(skb))
> + return -EINVAL;
> +
> + return skb_checksum_help(skb) ?: 1;
> +}
[Severity: Medium]
Can a packet with hdr->gso_type != 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;
> }
>
> +/*
> + * @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 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;
> }
>
> +/* 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 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 = skb_network_offset(skb) without requiring *nhoff == 0, it skips
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 = 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 == ARPHRD_ETHER.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203.rfcv10.52108.0.zakinko@snowrabbit.org?part=4
next prev parent reply other threads:[~2026-12-04 1:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 1:53 [PATCH RFC net v10 0/6] more virtio-net csum hardening Showta Ishizaki
2026-12-03 1:53 ` [PATCH RFC net v10 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
2026-12-03 1:53 ` [PATCH RFC net v10 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
2026-12-04 1:54 ` sashiko-bot [this message]
2026-12-04 4:01 ` Showta Ishizaki
2026-12-03 1:53 ` [PATCH RFC net v10 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
2026-12-03 1:53 ` [PATCH RFC net v10 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
2026-12-03 1:53 ` [PATCH RFC net v10 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
2026-12-03 1:53 ` [PATCH RFC net v10 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
2026-12-03 1:59 ` [PATCH RFC net v10 0/6] more virtio-net csum hardening netdev-bot+sinfo
2026-12-03 2:39 ` Showta Ishizaki
2026-12-03 7:02 ` Michael S. Tsirkin
2026-12-04 1:54 ` 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-248923@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.