All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux.dev, "Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH net v4 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Date: Thu, 22 Oct 2026 07:50:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-181141@kernel.org> (raw)
In-Reply-To: <595385b672b5411849d1defc78b68b25a908a77a.1792565282.git.mst@redhat.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: RCU violation reading dev_net() in virtio_net_hdr_validate_disabled()
--

commit 69b1f5f4a234fc132ca5965bd53c81fd86975566
Author: Michael S. Tsirkin <mst@redhat.com>

net: add a sysctl to opt out of virtio net hdr checksum validation

This commit adds a per-netns sysctl, net.core.virtio_net_hdr_validate,
guarded by a static key to allow opting out of virtio_net_hdr checksum
offset validation.

> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index ec6f47ce1c974..b3bbecbd023cb 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
[ ... ]
> @@ -78,6 +79,19 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,
>  	*thoff = nhoff + iph->ihl * sizeof(u32);
>  	return iph;
>  }
> +/* Defined in net/core/dev.c, enabled while any network namespace
> + * has net.core.virtio_net_hdr_validate set to 0.
> + */
> +DECLARE_STATIC_KEY_FALSE(virtio_net_hdr_validate_disabled_key);
> +
> +/* Failsafe: a namespace can disable the check with
> + * net.core.virtio_net_hdr_validate.
> + */
> +static inline bool virtio_net_hdr_validate_disabled(struct sk_buff *skb)
> +{
> +	return static_branch_unlikely(&virtio_net_hdr_validate_disabled_key) &&
> +	       !READ_ONCE(dev_net(skb->dev)->core.sysctl_virtio_net_hdr_validate);
> +}

[Severity: High]
Does virtio_net_hdr_validate_disabled() need RCU read-side protection when
fetching dev_net(skb->dev) and reading core.sysctl_virtio_net_hdr_validate?

When net.core.virtio_net_hdr_validate is set to 0 in any network namespace
(enabling virtio_net_hdr_validate_disabled_key), several callers of
virtio_net_hdr_to_skb() and virtio_net_hdr_tnl_to_skb() invoke
virtio_net_hdr_validate_disabled(skb) from preemptible process context while
holding only dev_hold(skb->dev) and without holding rcu_read_lock().

Specifically, tun_get_user() calls tun_vnet_hdr_tnl_to_skb() ->
virtio_net_hdr_tnl_to_skb() before acquiring rcu_read_lock():

drivers/net/tun.c:tun_get_user() {
	...
	err = tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr);
	if (err < 0) {
		atomic_long_inc(&tun->rx_frame_errors);
		err = -EINVAL;
		goto free_skb;
	}
	...
	rcu_read_lock();
	if (unlikely(!(tun->dev->flags & IFF_UP))) {
	...
}

Similarly, tpacket_snd() and packet_snd() in net/packet/af_packet.c call
virtio_net_hdr_to_skb() in process context without rcu_read_lock():

net/packet/af_packet.c:tpacket_snd() {
	...
	if (has_vnet_hdr) {
		if (virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le()) < 0) {
			tp_len = -EINVAL;
			goto tpacket_error;
		}
	}
	...
}

net/packet/af_packet.c:packet_snd() {
	...
	if (vnet_hdr_sz) {
		err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le());
		if (err < 0)
			goto out_free;
		len += vnet_hdr_sz;
	}
	...
}

Holding dev_hold(skb->dev) does not prevent __dev_change_net_namespace() from
moving skb->dev to another network namespace via dev_net_set(dev, net). If the
old network namespace then exits and is freed via cleanup_net(), a task
preempted after loading skb->dev->nd_net.net outside rcu_read_lock() could
dereference a freed struct net.

Should virtio_net_hdr_validate_disabled() use dev_net_rcu(skb->dev) inside
rcu_read_lock() and rcu_read_unlock(), similar to how commit afec62cd0a4191
("flow_dissector: use RCU protection to fetch dev_net()") fixed the same
pattern in __skb_flow_dissect()?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.v4.git.mst@redhat.com?part=5

  parent reply	other threads:[~2026-10-22  7:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  7:50 [PATCH net v4 0/7] more virtio-net csum hardening Michael S. Tsirkin
2026-10-21  7:49 ` [PATCH net v4 1/7] net: account for ingress-resolved virtio net hdr state Michael S. Tsirkin
2026-10-21  7:49   ` [PATCH net v4 2/7] um: vector: trim skbs before verifying the header Michael S. Tsirkin
2026-10-21 16:08     ` Willem de Bruijn
2026-10-22  7:50     ` sashiko-bot
2026-10-21  7:49   ` [PATCH net v4 3/7] virtio_net: parse tunnel csum_start little-endian Michael S. Tsirkin
2026-10-22  7:50     ` sashiko-bot
2026-10-21  7:50   ` [PATCH net v4 4/7] net: resolve uncommon partial checksums at ingress Michael S. Tsirkin
2026-10-21 16:13     ` Willem de Bruijn
2026-10-22  7:50     ` sashiko-bot
2026-10-21  7:50   ` [PATCH net v4 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation Michael S. Tsirkin
2026-10-21 16:14     ` Willem de Bruijn
2026-10-22  7:50     ` sashiko-bot [this message]
2026-10-21  7:50   ` [PATCH net v4 6/7] net: add ip4_parse() Michael S. Tsirkin
2026-10-21 16:18     ` Willem de Bruijn
2026-10-22  7:50     ` sashiko-bot
2026-10-21  7:50   ` [PATCH net v4 7/7] virtio_net: cleanup protocol calculation Michael S. Tsirkin
2026-10-22  7:50     ` sashiko-bot
2026-10-21 16:08   ` [PATCH net v4 1/7] net: account for ingress-resolved virtio net hdr state Willem de Bruijn
2026-10-21 16:28     ` Michael S. Tsirkin
2026-10-22  7:50   ` sashiko-bot
2026-10-21 18:49 ` [PATCH net v4 0/7] more virtio-net csum hardening Chris Arges

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-181141@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 \
    /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.