Re: [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation

From
sashiko-bot@kernel.org
Date
2026-12-05 04:01:54
Reply to
Showta Ishizaki, 2026-12-04
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] net: missing RCU in virtio_net_hdr_validate_disabled() causes
  netns UAF
--

commit 0b89c5d558deb20303dfa4d099fe2c3a761554eb
Author: Michael S. Tsirkin [off-list ref]

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
(default 1) guarded by a global static key so deployments can opt out of
virtio_net header checksum validation.
quoted hunk ↗ jump to hunk
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 6fe0c59217175..9e4b4440d062a 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
[ ... ]
quoted hunk ↗ jump to hunk
@@ -88,6 +89,18 @@ static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb,
 	return (struct iphdr *)(skb->data + nhoff);
 }
 
+/* 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);
+
+/* 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 cause a use-after-free of the
network namespace?

The comment assumes callers keep the netns alive, but sleepable callers
such as tun_get_user() hold only dev_hold(dev), with no rcu_read_lock()
or netdev_lock().  __dev_change_net_namespace() swaps dev->nd_net and
synchronizes only with RCU readers, not dev_hold() references.

Once any namespace sets net.core.virtio_net_hdr_validate to 0 and
enables virtio_net_hdr_validate_disabled_key:

CPU0                                  CPU1
tun_get_user()  /* holds dev_hold() */
  ...
    virtio_net_hdr_validate_disabled()
      net = dev_net(skb->dev)
      /* preempted */
                                      __dev_change_net_namespace()
                                        dev_net_set(dev, new_net)
                                        synchronize_net()
                                      cleanup_net(net)
                                        net_complete_free(net)
      READ_ONCE(net->core.sysctl_...)  <-- use-after-free

This causes a use-after-free read of struct net, which can crash the
kernel or bypass validation if the slab memory is reused.  Even callers
holding rcu_read_lock() race with dev_net_set() because dev_net() omits
RCU dereference semantics compared to dev_net_rcu().

Guarding a dev_net_rcu(skb->dev) lookup with rcu_read_lock() and
rcu_read_unlock() after the static_branch_unlikely() check would fix
both issues without adding overhead when validation is enabled.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=6
Thread (14 messages) 14 messages, 3 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help