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 v5 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation
Date: Fri, 23 Oct 2026 12:59:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-182806@kernel.org> (raw)
In-Reply-To: <2beba4c8b84c811120b6100bcccd8b90e7458787.1792668082.git.mst@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: use-after-free in virtio_net_hdr_validate_disabled() due to missing RCU
--
commit 50d6e871df0af42e23190bbc8209691b9cfd76e4
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 network namespaces to opt out of virtio
net header checksum validation on ingress.
> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index 52852a33a2db7..cea70ccf0ed4b 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
> @@ -5,6 +5,7 @@
> #include <linux/if_vlan.h>
> #include <linux/ip.h>
> #include <linux/ipv6.h>
> +#include <linux/jump_label.h>
> #include <linux/netdevice.h>
> #include <linux/udp.h>
> #include <net/gso.h>
> @@ -78,6 +79,20 @@ 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.
> + * The caller must keep the netns of skb->dev alive.
> + */
> +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]
Can dereferencing dev_net(skb->dev) here without rcu_read_lock() and
dev_net_rcu() cause a use-after-free on struct net when
virtio_net_hdr_validate_disabled_key is enabled?
Callers such as tun_get_user() in drivers/net/tun.c, as well as
tpacket_snd() and packet_snd() in net/packet/af_packet.c, invoke
virtio_net_hdr_tnl_to_skb() or virtio_net_hdr_to_skb() from preemptible
process context without holding rcu_read_lock() or rtnl_lock():
drivers/net/tun.c:tun_get_user() {
...
err = tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr);
...
}
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;
}
...
}
In these paths, the caller only holds dev_hold(skb->dev) and a reference
to the socket's netns via sock_net(sk). However, struct net_device does
not hold a reference to its struct net, and skb->dev may reside in a
different network namespace from sock_net(sk) (for instance, when a tun
device or target net_device has been moved to another namespace).
Because __dev_change_net_namespace() in net/core/dev.c switches
dev->nd_net via dev_net_set(dev, net) without waiting for existing
dev_hold(dev) references to drop (synchronizing only via
synchronize_net() and rcu_barrier()), a preempted task in tun_get_user(),
tpacket_snd(), or packet_snd() can load dev_net(skb->dev) just before the
device is moved out and that network namespace is destroyed via
cleanup_net() -> net_complete_free(), and then dereference the freed
struct net upon resuming.
For comparison, __skb_flow_dissect() in net/core/flow_dissector.c (which
is called from __virtio_net_hdr_to_skb() in the same paths) takes
rcu_read_lock() and uses dev_net_rcu(skb->dev) (since commit afec62cd0a41).
Should virtio_net_hdr_validate_disabled() likewise guard the lookup with
rcu_read_lock() / rcu_read_unlock() (or scoped_guard(rcu)) and use
dev_net_rcu(skb->dev)?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.v5.git.mst@redhat.com?part=5
next prev parent reply other threads:[~2026-10-23 12:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 12:57 [PATCH net v5 0/7] more virtio-net csum hardening Michael S. Tsirkin
2026-10-22 12:57 ` [PATCH net v5 1/7] net: account for ingress-resolved virtio net hdr state Michael S. Tsirkin
2026-10-22 14:37 ` Willem de Bruijn
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:30 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 2/7] um: vector: trim skbs before verifying the header Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 3/7] virtio_net: parse tunnel csum_start little-endian Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-22 12:58 ` [PATCH net v5 4/7] net: resolve uncommon partial checksums at ingress Michael S. Tsirkin
2026-10-22 14:52 ` Willem de Bruijn
2026-10-22 15:49 ` Michael S. Tsirkin
2026-10-22 17:52 ` Chris Arges
2026-10-22 23:38 ` Michael S. Tsirkin
2026-10-23 1:38 ` Chris Arges
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot [this message]
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 6/7] net: add ip4_parse() Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 7/7] virtio_net: cleanup protocol calculation Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 17:54 ` [PATCH net v5 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-182806@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox