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 v8 4/6] net: resolve uncommon partial checksums at ingress
Date: Thu, 26 Nov 2026 16:07:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-235877@kernel.org> (raw)
In-Reply-To: <20261126.rfcv8.99797.4.zakinko@snowrabbit.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net/packet: framing mismatch in packet_vnet_hdr_to_skb() via
dev->type
- [Medium] net: packet: skb->protocol set after validation in
packet_vnet_hdr_to_skb()
--
commit 4a97d36173ad7a2c090af1623638b2b508d7f3b0
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 or UDP headers at ingress, retaining CHECKSUM_PARTIAL only when
they match and completing non-GSO checksums or dropping GSO packets when
they do not.
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 930e85e4bf739..c07a0196911b5 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -2778,6 +2778,16 @@ static int tpacket_parse_header(struct packet_sock *po, void *frame,
> return tp_len;
> }
>
> +/* The device says how its frames start. */
> +static int packet_vnet_hdr_to_skb(struct sk_buff *skb,
> + const struct virtio_net_hdr *vnet_hdr)
> +{
> + bool has_eth = 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]
Can deriving has_eth from skb->dev->type cause packet_vnet_hdr_to_skb() to
parse a different frame layout than packet_snd(), tpacket_fill_skb() and
packet_parse_headers()?
As noted above virtio_net_l3_start(), ioctl(TUNSETLINK) changes dev->type on
a tun or tap device without changing dev->hard_header_len or dev->header_ops.
On an IFF_TUN device whose dev->type is set to ARPHRD_ETHER via TUNSETLINK,
packet_snd() places the L3 header at offset 0, but packet_vnet_hdr_to_skb()
passes has_eth = true. virtio_net_l3_start() then treats the first 14 bytes
of the L3 header as an Ethernet header and validates csum_start and
csum_offset against a fake L3/L4 header inside the payload, retaining
CHECKSUM_PARTIAL while packet_parse_headers() leaves skb->network_header at
offset 0 and derives skb->protocol from the real L3 header via
ip_tunnel_parse_protocol().
In addition, packet_vnet_hdr_to_skb() includes ARPHRD_LOOPBACK in has_eth, so
virtio_net_l3_start() walks past VLAN tags at ETH_HLEN when validating the
headers, 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);
...
}
> @@ -2941,7 +2951,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
> }
>
> if (has_vnet_hdr) {
> - if (virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le()) < 0) {
> + if (packet_vnet_hdr_to_skb(skb, &vnet_hdr) < 0) {
> tp_len = -EINVAL;
> goto tpacket_error;
> }
> @@ -3163,7 +3173,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
> skb->no_fcs = 1;
>
> if (vnet_hdr_sz) {
> - err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le());
> + err = packet_vnet_hdr_to_skb(skb, &vnet_hdr);
> if (err < 0)
> goto out_free;
> len += vnet_hdr_sz;
[Severity: Medium]
Should packet_parse_headers() and virtio_net_hdr_set_proto() run before
packet_vnet_hdr_to_skb() in tpacket_snd() and packet_snd()?
When the caller passes proto == htons(ETH_P_ALL) or 0, skb->protocol is still
0 when packet_vnet_hdr_to_skb() runs, so virtio_net_l3_start() skips its
skb->protocol consistency check. After validation succeeds and retains
CHECKSUM_PARTIAL and GSO, packet_parse_headers() and
virtio_net_hdr_set_proto() populate skb->protocol. Whenever
packet_parse_headers() leaves skb->protocol as 0 (for example on SOCK_DGRAM
sockets, or on SOCK_RAW sockets bound to devices without
header_ops->parse_protocol), virtio_net_hdr_set_proto() unconditionally sets
skb->protocol = htons(ETH_P_IP) for VIRTIO_NET_HDR_GSO_UDP_L4 and
VIRTIO_NET_HDR_GSO_UDP even when virtio_net_csum_partial_ok() just validated
an IPv6 packet, causing downstream GSO and transmit paths to process the IPv6
packet as IPv4.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126.rfcv8.99797.0.zakinko@snowrabbit.org?part=4
next prev parent reply other threads:[~2026-11-26 16:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 16:06 [PATCH RFC net v8 0/6] more virtio-net csum hardening Showta Ishizaki
2026-11-25 16:06 ` [PATCH RFC net v8 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
2026-11-25 16:06 ` [PATCH RFC net v8 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
2026-11-25 16:06 ` [PATCH RFC net v8 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
2026-11-25 16:06 ` [PATCH RFC net v8 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
2026-11-26 16:07 ` sashiko-bot [this message]
2026-11-25 16:06 ` [PATCH RFC net v8 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
2026-11-25 16:06 ` [PATCH RFC net v8 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
2026-11-26 16:07 ` [PATCH RFC net v8 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-235877@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox