* [PATCH RFC net v11 0/6] more virtio-net csum hardening
@ 2026-12-04 4:01 Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
` (7 more replies)
0 siblings, 8 replies; 14+ messages in thread
From: Showta Ishizaki @ 2026-12-04 4:01 UTC (permalink / raw)
To: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc,
Showta Ishizaki
Michael's series again, now v11. Patches 1-4 and 6 are his; patch 5 is
mine. The only change since v10 is in patch 4.
Changes since v10:
- Patch 4: AF_PACKET took has_eth from dev->type, which TUNSETLINK can
also change on an IFF_TAP device that still builds Ethernet headers.
Its frames were then validated from the network header, so a non-IP
EtherType with an IPv4 header behind it kept CHECKSUM_PARTIAL and a
VLAN-tagged frame lost it. A device with eth_header_ops now counts as
Ethernet too. Sashiko found this.
The two issues Michael listed as open in v7 are still open, hence the
RFC: the inner packet of a tunnel can have a valid header at
inner_nh_offset that overlaps the real transport header, and completing
the checksum at input breaks nf/BPF programs that edit the payload and
rely on CHECKSUM_PARTIAL.
Patches 1-3, 5 and 6 are unchanged from v10 and were tested as described
there. For patch 4 I sent, through AF_PACKET with a vnet header on a tap
that TUNSETLINK made ARPHRD_NONE, a plain IPv4/UDP frame, one with
EtherType 0x88cc and an IPv4/UDP header after it, and an 802.1Q-tagged
one, and looked at the skb at __dev_queue_xmit(): v11 keeps the partial
checksum on the first and the third and completes the second. The
TUNSETLINK'd IFF_TUN case from v9 behaves as before. Based on net
e6474ead54b8, the same base as v10; it also applies to current net
(90ae4042bd9f).
Michael S. Tsirkin (5):
net: account for ingress-resolved virtio net hdr state
um: vector: trim skbs before verifying the header
virtio_net: parse tunnel csum_start little-endian
net: resolve uncommon partial checksums at ingress
net: add a sysctl to opt out of virtio net hdr checksum validation
Showta Ishizaki (1):
net: virtio: compute the outer checksum of non-GSO tunnel packets
Documentation/admin-guide/sysctl/net.rst | 19 ++
arch/um/drivers/vector_kern.c | 6 +-
arch/um/drivers/vector_transports.c | 4 +-
drivers/net/tap.c | 4 +-
drivers/net/tun.c | 44 +++-
drivers/net/tun_vnet.h | 4 +-
drivers/net/virtio_net.c | 2 +-
include/linux/virtio_net.h | 263 ++++++++++++++++++++++-
include/net/netns/core.h | 1 +
net/core/dev.c | 7 +
net/core/net_namespace.c | 1 +
net/core/sysctl_net_core.c | 50 +++++
net/packet/af_packet.c | 24 ++-
13 files changed, 405 insertions(+), 24 deletions(-)
base-commit: e6474ead54b8acecb8b0462dde2d77f46d2b7dc1
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH RFC net v11 3/6] virtio_net: parse tunnel csum_start little-endian
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
` (2 preceding siblings ...)
2026-12-04 4:01 ` [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
@ 2026-12-04 4:01 ` Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
` (3 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Showta Ishizaki @ 2026-12-04 4:01 UTC (permalink / raw)
To: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc,
Showta Ishizaki
From: Michael S. Tsirkin <mst@redhat.com>
All tunnel related virtio features are > 32, so none of this
functionality can be enabled on legacy mixed-endian device.
Accordingly, all tunnel header fields, csum_start included, are
little-endian.
The nested virtio net header import parses csum_start that way, but the
inner transport offset is parsed with the endianness specified by the
interface.
If tun is misconfigured to legacy big-endian mode while the tunnel
features are enabled, the two parses of this field disagree, and the
value stored in skb->inner_transport_header - which is only
bounds-checked from below - can point past the end of the packet, where
GSO segmentation later dereferences it.
To fix, parse the field little-endian in both places.
Fixes: a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")
Cc: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
include/linux/virtio_net.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index fc9667176f23..3135dae031a4 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -490,7 +490,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
inner_l3min = virtio_l3min(inner_isv6);
outer_l3min = ETH_HLEN + virtio_l3min(outer_isv6);
- inner_th = __virtio16_to_cpu(little_endian, hdr->csum_start);
+ inner_th = __virtio16_to_cpu(true, hdr->csum_start);
inner_nh = le16_to_cpu(vhdr->inner_nh_offset);
outer_th = le16_to_cpu(vhdr->outer_th_offset);
if (outer_th < outer_l3min ||
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
@ 2026-12-04 4:01 ` Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
` (4 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Showta Ishizaki @ 2026-12-04 4:01 UTC (permalink / raw)
To: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc,
Showta Ishizaki
From: Michael S. Tsirkin <mst@redhat.com>
As reported first by Paulos Yibelo <habte.yibelo@gmail.com> (after which
others, credited below, found more ways the bug can affect users) a
virtio net header can place CHECKSUM_PARTIAL at any in-packet offset.
If that state is retained, later checksum completion can modify the
packet after protocol processing has made decisions from it.
Let's fix that: let's validate csum_start and csum_offset and only keep
CHECKSUM_PARTIAL when csum_start and csum_offset match a parsed TCP or
UDP header, while handling VLAN headers, IPv4 options and IPv6 extension
headers. Complete other non-GSO checksums immediately, before any
protocol processing runs.
We can't easily "complete the checksum" for GSO we don't recognize - GSO
assumes knowledge of the protocol. We could segment ignoring the
checksum then do whatever csum_start and csum_offset say, but that
seems like an overkill for something that shouldn't happen.
There's some risk here:
- non-gso packets which can't be parsed get checksum calculated in
software, adding performance overhead
- gso packets which can't be parsed get dropped
Note that for zero copy, userspace can change the data after the
checksum has been calculated. This is fundamental to zero copy by
design, and the only outcome is a bad checksum and a packet drop.
To mitigate the risks, a later patch will add a sysctl knob to
bypass the resolution. This is reasonable if the setup is such that
there is no protocol processing at all.
UDP tunnel headers get the same handling on the inner header.
Packets without VIRTIO_NET_HDR_F_NEEDS_CSUM are unaffected.
Note a fundamental limitation of this approach: an nf/BPF program
that tweaks the payload of a packet in flight may rely on the
checksum being fixed up later, assuming the packet carries
CHECKSUM_PARTIAL.
For metadata that fails validation the checksum
is now completed at input, so such edits leave a stale checksum
and the packet is dropped at the receiver. Protocols whose
transport header we cannot parse (anything but TCP and UDP) are
affected even when the metadata is self-consistent.
The sysctl added later in the series is the escape hatch for these setups,
but it is a very blunt tool.
Reported-by: Paulos Yibelo <habte.yibelo@gmail.com>
Reported-by: Chris Arges <carges@cloudflare.com>
Fixes: f43798c27684 ("tun: Allow GSO using virtio_net_hdr")
Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
[showta: rebased, the parsing helpers are in the tree already; has_eth
passed to virtio_net_hdr_to_skb() instead of using the device type;
the tnl_csum_negotiated check kept ahead of the validation; a tunnel
packet with bad inner metadata is dropped here, the next patch handles
the ones too small to segment; v9: derive has_eth from dev_has_header()
so TUNSETLINK cannot desync it from the frame layout, and record
skb->protocol during validation so a later set_proto() cannot relabel
the frame; v11: also take has_eth from eth_header_ops, as TUNSETLINK
can retype an IFF_TAP device that still builds Ethernet headers]
Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
arch/um/drivers/vector_transports.c | 2 +-
drivers/net/tun_vnet.h | 4 +-
include/linux/virtio_net.h | 140 ++++++++++++++++++++++++++--
net/packet/af_packet.c | 22 ++++-
4 files changed, 156 insertions(+), 12 deletions(-)
diff --git a/arch/um/drivers/vector_transports.c b/arch/um/drivers/vector_transports.c
index 8b7548458663..2dc4cf992877 100644
--- a/arch/um/drivers/vector_transports.c
+++ b/arch/um/drivers/vector_transports.c
@@ -210,7 +210,7 @@ static int raw_verify_header(
return 1;
skb_set_network_header(skb, ETH_HLEN);
- if (virtio_net_hdr_to_skb(skb, vheader,
+ if (virtio_net_hdr_to_skb(skb, vheader, true,
virtio_legacy_is_little_endian()) < 0)
return -1;
return 0;
diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h
index 3364e08dd6e0..5411258eeef6 100644
--- a/drivers/net/tun_vnet.h
+++ b/drivers/net/tun_vnet.h
@@ -180,7 +180,9 @@ static inline int tun_vnet_hdr_put(int sz, struct iov_iter *iter,
static inline int tun_vnet_hdr_to_skb(unsigned int flags, struct sk_buff *skb,
const struct virtio_net_hdr *hdr)
{
- return virtio_net_hdr_to_skb(skb, hdr, tun_vnet_is_little_endian(flags));
+ /* Only tap.c, where a frame always starts with an Ethernet header. */
+ return virtio_net_hdr_to_skb(skb, hdr, true,
+ tun_vnet_is_little_endian(flags));
}
/*
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 3135dae031a4..714b20acd38f 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;
}
@@ -190,6 +198,77 @@ virtio_net_l4_start(struct sk_buff *skb, unsigned int nhoff, __be16 proto,
return false;
}
+/* Does checksum metadata match a known TCP or UDP header? */
+static inline bool
+virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type,
+ unsigned int nhoff, __be16 proto)
+{
+ unsigned int thoff;
+ int ip_proto;
+
+ if (!virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto))
+ return false;
+
+ if (skb_checksum_start_offset(skb) != thoff)
+ return false;
+
+ switch (ip_proto) {
+ case IPPROTO_TCP:
+ if (skb->csum_offset != offsetof(struct tcphdr, check) ||
+ !pskb_may_pull(skb, thoff + sizeof(struct tcphdr)))
+ return false;
+ break;
+ case IPPROTO_UDP:
+ if (skb->csum_offset != offsetof(struct udphdr, check) ||
+ !pskb_may_pull(skb, thoff + sizeof(struct udphdr)))
+ return false;
+ break;
+ default:
+ return false;
+ }
+
+ switch (hdr_gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
+ case VIRTIO_NET_HDR_GSO_NONE:
+ return true;
+ case VIRTIO_NET_HDR_GSO_TCPV4:
+ return proto == htons(ETH_P_IP) && ip_proto == IPPROTO_TCP;
+ case VIRTIO_NET_HDR_GSO_TCPV6:
+ return proto == htons(ETH_P_IPV6) && ip_proto == IPPROTO_TCP;
+ case VIRTIO_NET_HDR_GSO_UDP:
+ case VIRTIO_NET_HDR_GSO_UDP_L4:
+ return ip_proto == IPPROTO_UDP;
+ default:
+ return false;
+ }
+}
+
+static inline bool
+virtio_net_csum_partial_ok(struct sk_buff *skb, bool has_eth,
+ u8 hdr_gso_type)
+{
+ int nhoff;
+ __be16 proto;
+
+ if (!virtio_net_l3_start(skb, has_eth, &nhoff, &proto))
+ return false;
+
+ return virtio_net_csum_partial_ok_at_offset(skb, hdr_gso_type, nhoff,
+ proto);
+}
+
+/*
+ * 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;
+}
+
static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,
const struct virtio_net_hdr *hdr,
bool little_endian, u8 hdr_gso_type)
@@ -336,11 +415,38 @@ retry:
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);
}
/* This function must be called after virtio_net_hdr_from_skb(). */
@@ -447,6 +553,12 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool has_eth, bool outer_isv6,
return ip_proto == IPPROTO_UDP && outer_th == thoff;
}
+/*
+ * Return value:
+ * 0 - success
+ * >0 - checksum was completed in software (slow path)
+ * <0 - failure
+ */
static inline int
virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
const struct virtio_net_hdr_v1_hash_tunnel *vhdr,
@@ -459,16 +571,20 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
unsigned int inner_nh, outer_th, inner_th;
unsigned int inner_l3min, outer_l3min;
u8 gso_inner_type, gso_tunnel_type;
+ __be16 inner_proto;
bool outer_isv6, inner_isv6;
int ret;
gso_tunnel_type = hdr->gso_type & VIRTIO_NET_HDR_GSO_UDP_TUNNEL;
if (!gso_tunnel_type)
- return virtio_net_hdr_to_skb(skb, hdr, little_endian);
+ return virtio_net_hdr_to_skb(skb, hdr, has_eth, little_endian);
/* Tunnel not supported/negotiated, but the hdr asks for it. */
if (!tnl_hdr_negotiated)
return -EINVAL;
+ if (hdr->flags & VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM &&
+ !tnl_csum_negotiated)
+ return -EINVAL;
/* Either ipv4 or ipv6. */
if (gso_tunnel_type == VIRTIO_NET_HDR_GSO_UDP_TUNNEL)
@@ -521,12 +637,20 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
return -EINVAL;
}
- skb_set_inner_protocol(skb, inner_isv6 ? htons(ETH_P_IPV6) :
- htons(ETH_P_IP));
- if (hdr->flags & VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM) {
- if (!tnl_csum_negotiated)
- return -EINVAL;
+ inner_proto = inner_isv6 ? htons(ETH_P_IPV6) : htons(ETH_P_IP);
+ /* NEEDS_CSUM is set, so this is CHECKSUM_PARTIAL. A packet whose
+ * inner metadata does not match cannot be segmented, and completing
+ * the inner checksum alone would leave the outer one to the seed
+ * the sender put there.
+ */
+ if (unlikely(!virtio_net_csum_partial_ok_at_offset(skb, gso_inner_type,
+ inner_nh,
+ inner_proto)))
+ return -EINVAL;
+
+ skb_set_inner_protocol(skb, inner_proto);
+ if (hdr->flags & VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM) {
skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
} else {
skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 930e85e4bf73..7ae70ca1556e 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2778,6 +2778,24 @@ 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. It can also make an IFF_TAP device something
+ * else, while the device still builds and parses Ethernet headers.
+ */
+static int packet_vnet_hdr_to_skb(struct sk_buff *skb,
+ const struct virtio_net_hdr *vnet_hdr)
+{
+ const struct net_device *dev = skb->dev;
+ bool has_eth = dev_has_header(dev) &&
+ (dev->type == ARPHRD_ETHER ||
+ dev->type == ARPHRD_LOOPBACK ||
+ dev->header_ops == ð_header_ops);
+
+ return virtio_net_hdr_to_skb(skb, vnet_hdr, has_eth, vio_le());
+}
+
static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
{
struct sk_buff *skb = NULL;
@@ -2941,7 +2959,7 @@ tpacket_error:
}
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 +3181,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;
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
@ 2026-12-04 4:01 ` Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
` (6 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Showta Ishizaki @ 2026-12-04 4:01 UTC (permalink / raw)
To: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc,
Showta Ishizaki
From: Michael S. Tsirkin <mst@redhat.com>
The vector receive path over-allocates the skb and only trims it
to the received length after the transport header is verified.
A follow up patch will complete the packet checksum in software within
virtio_net_hdr_to_skb so we need the packet trimmed (otherwise the
checksum would be computed incorrectly over the unreceived tail of the
buffer).
Trim first, so the import sees the packet as it was received.
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
arch/um/drivers/vector_kern.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index e902e78c5ff6..828bd61995b8 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -873,6 +873,7 @@ static int vector_legacy_rx(struct vector_private *vp)
if (skb != NULL) {
if (pkt_len > vp->header_size) {
+ pskb_trim(skb, pkt_len - vp->rx_header_size);
if (vp->header_size > 0) {
header_check = vp->verify_header(
vp->header_rxbuffer, skb, vp);
@@ -887,7 +888,6 @@ static int vector_legacy_rx(struct vector_private *vp)
skb->ip_summed = CHECKSUM_UNNECESSARY;
}
}
- pskb_trim(skb, pkt_len - vp->rx_header_size);
skb->protocol = eth_type_trans(skb, skb->dev);
vp->dev->stats.rx_bytes += skb->len;
vp->dev->stats.rx_packets++;
@@ -989,6 +989,8 @@ static int vector_mmsg_rx(struct vector_private *vp, int budget)
for (i = 0; i < packet_count; i++) {
skb = (*skbuff_vector);
if (mmsg_vector->msg_len > vp->header_size) {
+ pskb_trim(skb,
+ mmsg_vector->msg_len - vp->rx_header_size);
if (vp->header_size > 0) {
header_check = vp->verify_header(
mmsg_vector->msg_hdr.msg_iov->iov_base,
@@ -1013,8 +1015,6 @@ static int vector_mmsg_rx(struct vector_private *vp, int budget)
skb->ip_summed = CHECKSUM_UNNECESSARY;
}
}
- pskb_trim(skb,
- mmsg_vector->msg_len - vp->rx_header_size);
skb->protocol = eth_type_trans(skb, skb->dev);
/*
* We do not need to lock on updating stats here
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
` (4 preceding siblings ...)
2026-12-04 4:01 ` [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
@ 2026-12-04 4:01 ` Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:06 ` [PATCH RFC net v11 0/6] more virtio-net csum hardening netdev-bot+sinfo
2026-12-05 4:01 ` sashiko-bot
7 siblings, 1 reply; 14+ messages in thread
From: Showta Ishizaki @ 2026-12-04 4:01 UTC (permalink / raw)
To: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc,
Showta Ishizaki
A packet may be tagged as UDP tunnel GSO and still be too small to
segment. Then nothing consumes the pseudo-header seed the sender left in
the outer UDP checksum. The GSO layer is not run, and transmit checksum
offload completes only the inner checksum, so the seed goes out as the
outer checksum.
Zeroing it is not an option either: IPv6 receivers drop a zero UDP
checksum unless the tunnel opted in (RFC 6935, RFC 6936).
Compute the outer checksum when VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM asks
for one: with local checksum offload while the inner checksum is still
partial, or by a full sum once the inner one was completed in software
because its metadata did not match the packet. Such packets no longer
need to be dropped.
The addresses come from the outer header in the frame and the length
from the UDP header. udp_set_csum() is not used: it is built with
CONFIG_INET, which virtio_net does not depend on.
Fixes: a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")
Suggested-by: Willem de Bruijn <willemb@google.com>
Suggested-by: Chris Arges <carges@cloudflare.com>
Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
include/linux/virtio_net.h | 113 ++++++++++++++++++++++++++++++++++---
1 file changed, 106 insertions(+), 7 deletions(-)
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 714b20acd38f..6fe0c5921717 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -8,8 +8,10 @@
#include <linux/netdevice.h>
#include <linux/udp.h>
#include <net/ip.h>
+#include <net/ip6_checksum.h>
#include <net/ipv6.h>
#include <net/tcp.h>
+#include <net/udp.h>
#include <uapi/linux/tcp.h>
#include <uapi/linux/virtio_net.h>
@@ -553,6 +555,72 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool has_eth, bool outer_isv6,
return ip_proto == IPPROTO_UDP && outer_th == thoff;
}
+/* Fill in the outer UDP checksum of a tunnel packet that is not GSO.
+ * While the inner checksum is still CHECKSUM_PARTIAL this is local
+ * checksum offload, as udp_set_csum() does for udp_tunnel_xmit_skb(),
+ * and needs the transport header at @outer_th. Once the inner
+ * checksum has been completed the datagram is summed in full.
+ *
+ * The pseudo-header comes from the frame, not from the seed the sender
+ * put in uh->check: the addresses of the outer IP header and the
+ * length of the UDP header, which skb->len exceeds when the frame is
+ * padded.
+ *
+ * udp_set_csum() itself is not used: it is built with CONFIG_INET,
+ * which virtio_net does not depend on.
+ */
+static inline int
+virtio_net_tnl_set_outer_csum(struct sk_buff *skb, bool has_eth,
+ bool outer_isv6, unsigned int outer_th)
+{
+ unsigned int thoff;
+ struct udphdr *uh;
+ int ip_proto, nhoff;
+ __be16 proto;
+ __wsum csum;
+ int len, err;
+
+ /* virtio_net_tnl_offsets_ok() has passed; this finds nhoff. */
+ if (!virtio_net_l3_start(skb, has_eth, &nhoff, &proto) ||
+ !virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto))
+ return -EINVAL;
+
+ err = skb_ensure_writable(skb, outer_th + sizeof(*uh));
+ if (err)
+ return err;
+
+ uh = (struct udphdr *)(skb->data + outer_th);
+ len = ntohs(uh->len);
+ uh->check = 0;
+ if (skb->ip_summed == CHECKSUM_PARTIAL) {
+ csum = lco_csum(skb);
+ } else {
+ /* Sum the datagram alone: uh->len, not skb->len - outer_th,
+ * which also counts non-zero Ethernet padding and so
+ * miscomputes the outer checksum. len is from the frame,
+ * so bound it before reading that many bytes.
+ */
+ if (len < sizeof(*uh) || len > skb->len - outer_th)
+ return -EINVAL;
+ csum = skb_checksum(skb, outer_th, len, 0);
+ }
+
+ if (outer_isv6) {
+ const struct ipv6hdr *ip6h = (void *)(skb->data + nhoff);
+
+ uh->check = udp_v6_check(len, &ip6h->saddr, &ip6h->daddr,
+ csum);
+ } else {
+ const struct iphdr *iph = (void *)(skb->data + nhoff);
+
+ uh->check = udp_v4_check(len, iph->saddr, iph->daddr, csum);
+ }
+ if (uh->check == 0)
+ uh->check = CSUM_MANGLED_0;
+
+ return 0;
+}
+
/*
* Return value:
* 0 - success
@@ -568,6 +636,7 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
bool little_endian)
{
const struct virtio_net_hdr *hdr = (const struct virtio_net_hdr *)vhdr;
+ typeof(skb->transport_header) old_transport = skb->transport_header;
unsigned int inner_nh, outer_th, inner_th;
unsigned int inner_l3min, outer_l3min;
u8 gso_inner_type, gso_tunnel_type;
@@ -639,15 +708,26 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
inner_proto = inner_isv6 ? htons(ETH_P_IPV6) : htons(ETH_P_IP);
- /* NEEDS_CSUM is set, so this is CHECKSUM_PARTIAL. A packet whose
- * inner metadata does not match cannot be segmented, and completing
- * the inner checksum alone would leave the outer one to the seed
- * the sender put there.
- */
+ /* NEEDS_CSUM is set, so this is CHECKSUM_PARTIAL. */
if (unlikely(!virtio_net_csum_partial_ok_at_offset(skb, gso_inner_type,
inner_nh,
- inner_proto)))
- return -EINVAL;
+ inner_proto))) {
+ /* __virtio_net_hdr_to_skb set the transport header to
+ * csum_start, restore it to a known good value.
+ */
+ skb->transport_header = old_transport;
+
+ ret = __virtio_net_resolve_csum_partial_mismatch(skb);
+ if (ret > 0 && hdr->flags & VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM) {
+ int err = virtio_net_tnl_set_outer_csum(skb, has_eth,
+ outer_isv6,
+ outer_th);
+
+ if (err)
+ return err;
+ }
+ return ret;
+ }
skb_set_inner_protocol(skb, inner_proto);
if (hdr->flags & VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM) {
@@ -661,6 +741,25 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb,
skb->inner_mac_header = inner_nh + skb_headroom(skb);
skb->transport_header = outer_th + skb_headroom(skb);
skb->encapsulation = 1;
+
+ if (!skb_is_gso(skb)) {
+ /* Too small to segment. Senders do tag small packets with
+ * GSO headers, e.g. packetdrill sets gso_type and gso_size
+ * with --mss, whatever the packet size. Nothing consumes
+ * the seed the sender left in the outer uh->check without
+ * GSO, so compute the outer checksum if one was asked for.
+ */
+ skb_shinfo(skb)->gso_type &= ~(SKB_GSO_UDP_TUNNEL_CSUM |
+ SKB_GSO_UDP_TUNNEL);
+ if (hdr->flags & VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM) {
+ ret = virtio_net_tnl_set_outer_csum(skb, has_eth,
+ outer_isv6,
+ outer_th);
+ if (ret)
+ return ret;
+ }
+ }
+
return 0;
}
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
` (3 preceding siblings ...)
2026-12-04 4:01 ` [PATCH RFC net v11 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
@ 2026-12-04 4:01 ` Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
` (2 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Showta Ishizaki @ 2026-12-04 4:01 UTC (permalink / raw)
To: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc,
Showta Ishizaki
From: Michael S. Tsirkin <mst@redhat.com>
The ingress validation as implemented earlier in this
series is stricter than what it replaced: GSO
packets whose checksum metadata matches no transport header are
dropped, and non-GSO ones get their checksum completed in place.
Such packets used to pass with the metadata unvalidated,
and with no overhead.
I judge that this should not affect any deployments, but there is still
some risk that it does. In case a deployment depends on them anyway,
provide a per-netns switch to get the old behavior back:
echo 0 > /proc/sys/net/core/virtio_net_hdr_validate
The default is validating.
Cc: Björn Töpel <bjorn@kernel.org>
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
[showta: rebased; virtio_net_tnl_offsets_ok() is not subject to the knob:
the tree checks the outer headers unconditionally]
Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
Documentation/admin-guide/sysctl/net.rst | 19 +++++++++
include/linux/virtio_net.h | 22 +++++++++++
include/net/netns/core.h | 1 +
net/core/dev.c | 7 ++++
net/core/net_namespace.c | 1 +
net/core/sysctl_net_core.c | 50 ++++++++++++++++++++++++
6 files changed, 100 insertions(+)
diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst
index fe43e8595958..3d89772cb7fe 100644
--- a/Documentation/admin-guide/sysctl/net.rst
+++ b/Documentation/admin-guide/sysctl/net.rst
@@ -246,6 +246,25 @@ processes are dropped unless socket option SOF_TIMESTAMPING_OPT_TSONLY is set.
Default: 1 (on)
+virtio_net_hdr_validate
+-----------------------
+
+When processing packets with a virtio net header (through tun, tap, a
+packet socket or a virtio network device) that request checksum offload
+(VIRTIO_NET_HDR_F_NEEDS_CSUM), validate the packet: complete the checksum
+in software, or drop the packet where the header does not match it.
+
+When disabled, the header is trusted not to corrupt the packet, and the
+checksum is offloaded to hardware (or not verified if it never reaches
+hardware). This is only safe if no protocol is processing the packets.
+
+The setting is per network namespace, but only writable by the host
+root: root inside a network namespace created by an unprivileged user
+cannot disable the validation.
+
+Default: 1 (on)
+
+
wmem_default
------------
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 6fe0c5921717..9e4b4440d062 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/ip.h>
@@ -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);
+}
+
/* Where does the L3 header start, and what protocol is it?
* With @has_eth, the frame starts with an Ethernet header, possibly
* followed by VLAN tags. Otherwise the L3 header starts at the network
@@ -208,6 +221,12 @@ virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type,
unsigned int thoff;
int ip_proto;
+ /* Failsafe: a namespace opted out of the validation,
+ * trust the checksum metadata as before.
+ */
+ if (virtio_net_hdr_validate_disabled(skb))
+ return true;
+
if (!virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto))
return false;
@@ -251,6 +270,9 @@ virtio_net_csum_partial_ok(struct sk_buff *skb, bool has_eth,
int nhoff;
__be16 proto;
+ if (virtio_net_hdr_validate_disabled(skb))
+ return true;
+
if (!virtio_net_l3_start(skb, has_eth, &nhoff, &proto))
return false;
diff --git a/include/net/netns/core.h b/include/net/netns/core.h
index 9ef3d70e5e9c..02ce232fe9a9 100644
--- a/include/net/netns/core.h
+++ b/include/net/netns/core.h
@@ -18,6 +18,7 @@ struct netns_core {
u8 sysctl_txrehash;
u8 sysctl_tstamp_allow_data;
u8 sysctl_bypass_prot_mem;
+ u8 sysctl_virtio_net_hdr_validate;
#ifdef CONFIG_PROC_FS
struct prot_inuse __percpu *prot_inuse;
diff --git a/net/core/dev.c b/net/core/dev.c
index cd0796a1dbfd..bdef4403b7e4 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -128,6 +128,7 @@
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <net/ip.h>
+#include <linux/virtio_net.h>
#include <net/mpls.h>
#include <net/route.h>
#include <linux/ipv6.h>
@@ -2429,6 +2430,12 @@ EXPORT_SYMBOL(tcf_sw_enabled_key);
DEFINE_STATIC_KEY_FALSE(netstamp_needed_key);
EXPORT_SYMBOL(netstamp_needed_key);
+
+/* Enabled while any network namespace has net.core.virtio_net_hdr_validate
+ * set to 0.
+ */
+DEFINE_STATIC_KEY_FALSE(virtio_net_hdr_validate_disabled_key);
+EXPORT_SYMBOL(virtio_net_hdr_validate_disabled_key);
#ifdef CONFIG_JUMP_LABEL
static atomic_t netstamp_needed_deferred;
static atomic_t netstamp_wanted;
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 217021eeab13..8c61892d94c6 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -401,6 +401,7 @@ static __net_init void preinit_net_sysctl(struct net *net)
net->core.sysctl_optmem_max = 128 * 1024;
net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED;
net->core.sysctl_tstamp_allow_data = 1;
+ net->core.sysctl_virtio_net_hdr_validate = 1;
net->core.sysctl_txq_reselection = msecs_to_jiffies(1000);
}
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 473c162736d6..04cd2d758ccc 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -18,6 +18,8 @@
#include <linux/slab.h>
#include <linux/sched/isolation.h>
#include <linux/hex.h>
+#include <linux/virtio_net.h>
+#include <linux/jump_label.h>
#include <net/ip.h>
#include <net/sock.h>
@@ -693,6 +695,43 @@ static struct ctl_table net_core_table[] = {
},
};
+/* Protects changes to virtio_net_hdr_validate_disabled_key and each
+ * net->core.sysctl_virtio_net_hdr_validate. The packet path reads
+ * the value without a lock.
+ */
+static DEFINE_MUTEX(virtio_net_hdr_validate_mutex);
+
+static int virtio_net_hdr_validate_sysctl(const struct ctl_table *table,
+ int write, void *buffer,
+ size_t *lenp, loff_t *ppos)
+{
+ u8 *value = table->data;
+ u8 old, new;
+ int ret;
+
+ /* Root in a user namespace must not be able to weaken the
+ * validation for the network namespace it controls.
+ */
+ if (write && !capable(CAP_NET_ADMIN))
+ return -EPERM;
+
+ mutex_lock(&virtio_net_hdr_validate_mutex);
+
+ old = READ_ONCE(*value);
+ ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
+ new = READ_ONCE(*value);
+ if (write && !ret && old != new) {
+ if (new)
+ static_branch_dec(&virtio_net_hdr_validate_disabled_key);
+ else
+ static_branch_inc(&virtio_net_hdr_validate_disabled_key);
+ }
+
+ mutex_unlock(&virtio_net_hdr_validate_mutex);
+
+ return ret;
+}
+
static const struct ctl_table netns_core_table[] = {
#if IS_ENABLED(CONFIG_RPS)
{
@@ -752,6 +791,15 @@ static const struct ctl_table netns_core_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE
},
+ {
+ .procname = "virtio_net_hdr_validate",
+ .data = &init_net.core.sysctl_virtio_net_hdr_validate,
+ .maxlen = sizeof(u8),
+ .mode = 0644,
+ .proc_handler = virtio_net_hdr_validate_sysctl,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE
+ },
/* sysctl_core_net_init() will set the values after this
* to readonly in network namespaces
*/
@@ -856,6 +904,8 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
tbl = net->core.sysctl_hdr->ctl_table_arg;
unregister_net_sysctl_table(net->core.sysctl_hdr);
BUG_ON(tbl == netns_core_table);
+ if (!net->core.sysctl_virtio_net_hdr_validate)
+ static_branch_dec(&virtio_net_hdr_validate_disabled_key);
#if IS_ENABLED(CONFIG_RPS)
kfree(net->core.rps_default_mask);
#endif
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
@ 2026-12-04 4:01 ` Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
` (5 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Showta Ishizaki @ 2026-12-04 4:01 UTC (permalink / raw)
To: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc,
Showta Ishizaki
From: Michael S. Tsirkin <mst@redhat.com>
A later patch will add ingress resolution of uncommon virtio net
hdr checksum metadata (software checksum completion at ingress) which
adds performance overhead to the packet processing.
We should make it visible, so a hypothetical workload relying on
uncommon metadata can be distinguished from none at all. This way issues
in the parsing will be reported and not quietly pay the host-CPU
checksum overhead instead of offload.
Flip every call to virtio_net_hdr_to_skb to test for negative errno
only. The um vector raw transport even ignored the return value
altogether: rejected packets went on into the stack with their
metadata unvalidated, so check it there as well.
Have tun count these events per device as rx_csum_sw, exposed via
ethtool -S.
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
[showta: rebased on the has_eth argument of virtio_net_hdr_tnl_to_skb()]
Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
arch/um/drivers/vector_transports.c | 4 ++-
drivers/net/tap.c | 4 +--
drivers/net/tun.c | 44 ++++++++++++++++++++++++++---
drivers/net/virtio_net.c | 2 +-
net/packet/af_packet.c | 4 +--
5 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/arch/um/drivers/vector_transports.c b/arch/um/drivers/vector_transports.c
index e1fb2a76fdff..8b7548458663 100644
--- a/arch/um/drivers/vector_transports.c
+++ b/arch/um/drivers/vector_transports.c
@@ -210,7 +210,9 @@ static int raw_verify_header(
return 1;
skb_set_network_header(skb, ETH_HLEN);
- virtio_net_hdr_to_skb(skb, vheader, virtio_legacy_is_little_endian());
+ if (virtio_net_hdr_to_skb(skb, vheader,
+ virtio_legacy_is_little_endian()) < 0)
+ return -1;
return 0;
}
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 2f19fb07bb2d..101994870bac 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -650,7 +650,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
if (vnet_hdr_len) {
err = tun_vnet_hdr_to_skb(q->flags, skb, &vnet_hdr);
- if (err) {
+ if (err < 0) {
rcu_read_unlock();
drop_reason = SKB_DROP_REASON_DEV_HDR;
goto err_kfree;
@@ -1090,7 +1090,7 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)
if (vnet_hdr_len) {
err = tun_vnet_hdr_to_skb(q->flags, skb, gso);
- if (err) {
+ if (err < 0) {
rcu_read_unlock();
goto err_kfree;
}
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index ae05b1e58aba..19647fa97775 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -211,6 +211,7 @@ struct tun_struct {
u32 flow_count;
u32 rx_batched;
atomic_long_t rx_frame_errors;
+ atomic64_t rx_csum_sw;
struct bpf_prog __rcu *xdp_prog;
struct tun_prog __rcu *steering_prog;
struct tun_prog __rcu *filter_prog;
@@ -1969,11 +1970,15 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
break;
}
- if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr,
- (tun->flags & TUN_TYPE_MASK) == IFF_TAP)) {
+ err = tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr,
+ (tun->flags & TUN_TYPE_MASK) == IFF_TAP);
+ if (err < 0) {
atomic_long_inc(&tun->rx_frame_errors);
err = -EINVAL;
goto free_skb;
+ } else if (err > 0) {
+ atomic64_inc(&tun->rx_csum_sw);
+ err = 0;
}
if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP)
@@ -2663,12 +2668,15 @@ build:
/* Frames always start with an Ethernet header here, as the
* eth_type_trans() call below expects.
*/
- if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr,
- true)) {
+ ret = tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr, true);
+ if (ret < 0) {
atomic_long_inc(&tun->rx_frame_errors);
kfree_skb(skb);
ret = -EINVAL;
goto out;
+ } else if (ret > 0) {
+ atomic64_inc(&tun->rx_csum_sw);
+ ret = 0;
}
skb->protocol = eth_type_trans(skb, tun->dev);
@@ -3821,7 +3829,35 @@ static void tun_get_channels(struct net_device *dev,
channels->max_combined = tun->flags & IFF_MULTI_QUEUE ? MAX_TAP_QUEUES : 1;
}
+#define TUN_STATS_LEN 1
+static const char tun_ethtool_strings[TUN_STATS_LEN][ETH_GSTRING_LEN] = {
+ "rx_csum_sw",
+};
+
+static int tun_get_sset_count(struct net_device *dev, int sset)
+{
+ return sset == ETH_SS_STATS ? TUN_STATS_LEN : -EOPNOTSUPP;
+}
+
+static void tun_get_strings(struct net_device *dev, u32 stringset, u8 *data)
+{
+ if (stringset == ETH_SS_STATS)
+ memcpy(data, tun_ethtool_strings,
+ sizeof(tun_ethtool_strings));
+}
+
+static void tun_get_ethtool_stats(struct net_device *dev,
+ struct ethtool_stats *stats, u64 *data)
+{
+ struct tun_struct *tun = netdev_priv(dev);
+
+ data[0] = atomic64_read(&tun->rx_csum_sw);
+}
+
static const struct ethtool_ops tun_ethtool_ops = {
+ .get_sset_count = tun_get_sset_count,
+ .get_strings = tun_get_strings,
+ .get_ethtool_stats = tun_get_ethtool_stats,
.supported_coalesce_params = ETHTOOL_COALESCE_RX_MAX_FRAMES,
.get_drvinfo = tun_get_drvinfo,
.get_msglevel = tun_get_msglevel,
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 1cd64f9e12e7..fb9359ef48ab 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2548,7 +2548,7 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *
skb_set_network_header(skb, ETH_HLEN);
if (virtio_net_hdr_tnl_to_skb(skb, &hdr->tnl_hdr, true, vi->rx_tnl,
vi->rx_tnl_csum,
- virtio_is_little_endian(vi->vdev))) {
+ virtio_is_little_endian(vi->vdev)) < 0) {
net_warn_ratelimited("%s: bad gso: type: %x, size: %u, flags %x tunnel %d tnl csum %d\n",
dev->name, hdr->hdr.gso_type,
hdr->hdr.gso_size, hdr->hdr.flags,
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index e0ebd0627509..930e85e4bf73 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2941,7 +2941,7 @@ tpacket_error:
}
if (has_vnet_hdr) {
- if (virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le())) {
+ if (virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le()) < 0) {
tp_len = -EINVAL;
goto tpacket_error;
}
@@ -3164,7 +3164,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
if (vnet_hdr_sz) {
err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le());
- if (err)
+ if (err < 0)
goto out_free;
len += vnet_hdr_sz;
}
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH RFC net v11 0/6] more virtio-net csum hardening
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
` (5 preceding siblings ...)
2026-12-04 4:01 ` [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
@ 2026-12-04 4:06 ` netdev-bot+sinfo
2026-12-05 4:01 ` sashiko-bot
7 siblings, 0 replies; 14+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 4:06 UTC (permalink / raw)
To: Showta Ishizaki
Cc: Michael S. Tsirkin, Willem de Bruijn, Jason Wang, netdev,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, David S. Miller,
Andrew Lunn, Simon Horman, Eugenio Pérez, Xuan Zhuo,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Chris Arges, Paulos Yibelo,
Björn Töpel, virtualization, linux-um, linux-doc
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state
2026-12-04 4:01 ` [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
@ 2026-12-05 4:01 ` sashiko-bot
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-05 4:01 UTC (permalink / raw)
To: Showta Ishizaki; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tun: device-wide atomic64_t rx_csum_sw causes false sharing
in tun_struct
--
commit 565eda5d8ee04fb6c73d9fb10982bd2d4103c120
Author: Michael S. Tsirkin <mst@redhat.com>
net: account for ingress-resolved virtio net hdr state
This commit updates callers of virtio_net_hdr_to_skb() and
virtio_net_hdr_tnl_to_skb() to treat only negative return values as errors,
and adds a per-device rx_csum_sw counter in tun exposed via ethtool -S.
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index ae05b1e58abaa..19647fa977757 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -211,6 +211,7 @@ struct tun_struct {
> u32 flow_count;
> u32 rx_batched;
> atomic_long_t rx_frame_errors;
> + atomic64_t rx_csum_sw;
> struct bpf_prog __rcu *xdp_prog;
> struct tun_prog __rcu *steering_prog;
> struct tun_prog __rcu *filter_prog;
[Severity: Medium]
Can placing atomic64_t rx_csum_sw here cause false sharing on
struct tun_struct?
rx_csum_sw sits directly between rx_batched and the read-mostly RCU pointers
(xdp_prog, steering_prog, and filter_prog) with no cacheline separation, so
it shares a 64-byte cacheline with fields read on every RX and TX packet.
On a multi-queue device, accepted packets completing checksums in software
(such as non-TCP/UDP packets with VIRTIO_NET_HDR_F_NEEDS_CSUM) run
atomic64_inc(&tun->rx_csum_sw) in tun_get_user() and tun_xdp_one(). That
dirties the shared cacheline across other CPUs running fast-path RX/TX queues.
Using a per-CPU counter summed in tun_get_ethtool_stats() would avoid both
the false sharing and cross-CPU atomic contention across queues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header
2026-12-04 4:01 ` [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
@ 2026-12-05 4:01 ` sashiko-bot
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-05 4:01 UTC (permalink / raw)
To: Showta Ishizaki; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] um: vector: NULL skb dereference in vector_mmsg_rx() on
allocation failure
--
commit e31f8cf054920da38ad1454a853c93da403fdef4
Author: Michael S. Tsirkin <mst@redhat.com>
um: vector: trim skbs before verifying the header
This commit moves pskb_trim() ahead of vp->verify_header() in
vector_legacy_rx() and vector_mmsg_rx() so that received skbs are trimmed
before header verification.
> diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
> index e902e78c5ff67..828bd61995b86 100644
> --- a/arch/um/drivers/vector_kern.c
> +++ b/arch/um/drivers/vector_kern.c
[ ... ]
> @@ -989,6 +989,8 @@ static int vector_mmsg_rx(struct vector_private *vp, int budget)
> for (i = 0; i < packet_count; i++) {
> skb = (*skbuff_vector);
> if (mmsg_vector->msg_len > vp->header_size) {
> + pskb_trim(skb,
> + mmsg_vector->msg_len - vp->rx_header_size);
> if (vp->header_size > 0) {
> header_check = vp->verify_header(
> mmsg_vector->msg_hdr.msg_iov->iov_base,
[Severity: High]
Can pskb_trim() dereference a NULL skb here when allocation fails?
When prep_skb() fails its GFP_ATOMIC allocation with vp->header_size > 0,
it stores NULL in *skbuff_vector while leaving iov[0] sized to
vp->rx_header_size.
For IPv4 GRE, build_gre_transport_data() adds sizeof(struct iphdr) to
vp->rx_header_size, so an incoming packet into that slot can satisfy
mmsg_vector->msg_len > vp->header_size while skb is NULL.
Before this patch, packets rejected by vp->verify_header() went straight
to NULL-safe dev_kfree_skb_irq(skb) and skipped pskb_trim(). Moving
pskb_trim() first causes a NULL pointer dereference in NAPI softirq even
for invalid or unauthenticated packets.
Checking skb != NULL (and mmsg_vector->msg_len > vp->rx_header_size)
before calling pskb_trim() would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=2
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress
2026-12-04 4:01 ` [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
@ 2026-12-05 4:01 ` sashiko-bot
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-05 4:01 UTC (permalink / raw)
To: Showta Ishizaki; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] net/packet: unexported eth_header_ops in
packet_vnet_hdr_to_skb()
- [High] net: non-Ethernet link-header devices bypass
virtio_net_l3_start() check
- [Medium] net: virtio_net_csum_partial_ok_at_offset() pulls unread
tcphdr bytes on non-GSO
- [Medium] net: virtio_net_csum_partial_ok_at_offset() drops NSH GSO and
breaks nsh_gso.sh
- [Medium] virtio_net: virtio_net_l3_start() mutates skb->protocol on
failed validation
- [Medium] virtio_net: virtio_net_hdr_to_skb() restores stale
transport_header
- [Medium] tun: shared atomic64_t rx_csum_sw false-shares hot cacheline
in tun_struct
- [Medium] packet: unlocked dev->header_ops/type reads in
packet_vnet_hdr_to_skb()
--
commit bbc09c06c4fccf93de5eb92627de4a572115b649
Author: Michael S. Tsirkin <mst@redhat.com>
net: resolve uncommon partial checksums at ingress
This commit validates virtio_net_hdr CHECKSUM_PARTIAL metadata against the
parsed TCP or UDP header at ingress, dropping unrecognized GSO packets and
completing unmatched non-GSO checksums in software.
> 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]
Can virtio_net_l3_start() leave skb->protocol mutated when checksum
validation fails?
virtio_net_l3_start() sets skb->protocol before VLAN, L3, and L4 validation
succeed, and virtio_net_hdr_to_skb() only restores skb->transport_header on
mismatch before completing the checksum in software. On an IFF_TUN device in
PI mode, if userspace sends pi.proto == 0 with VIRTIO_NET_HDR_F_NEEDS_CSUM
and a short non-IP frame starting with 0x60, virtio_net_l3_start() sets
skb->protocol to htons(ETH_P_IPV6) from the first byte before
virtio_net_l4_start() fails. tun_get_user() then injects the frame into
ipv6_rcv() instead of leaving skb->protocol as 0. On AF_PACKET SOCK_RAW with
proto == 0 or ETH_P_ALL, the mutated skb->protocol also causes
packet_parse_headers() to skip dev_parse_header_protocol().
Saving and restoring skb->protocol on mismatch in virtio_net_hdr_to_skb(), or
only writing skb->protocol after validation succeeds, would avoid this.
> @@ -190,6 +198,77 @@ virtio_net_l4_start(struct sk_buff *skb, unsigned int nhoff, __be16 proto,
> return false;
> }
>
> +/* Does checksum metadata match a known TCP or UDP header? */
> +static inline bool
> +virtio_net_csum_partial_ok_at_offset(struct sk_buff *skb, u8 hdr_gso_type,
> + unsigned int nhoff, __be16 proto)
> +{
> + unsigned int thoff;
> + int ip_proto;
> +
> + if (!virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto))
> + return false;
[Severity: Medium]
Does this drop valid NSH-encapsulated GSO packets and break the in-tree
tools/testing/selftests/net/nsh_gso.sh selftest?
nsh_gso.c sends ETH_P_NSH frames with VIRTIO_NET_HDR_F_NEEDS_CSUM and
VIRTIO_NET_HDR_GSO_TCPV4 over AF_PACKET PACKET_VNET_HDR. Because
virtio_net_l4_start() only handles ETH_P_IP and ETH_P_IPV6,
virtio_net_csum_partial_ok_at_offset() returns false and
__virtio_net_resolve_csum_partial_mismatch() drops the GSO packet with
-EINVAL, so nsh_gso.sh transmits 0 packets instead of 4 under the default
configuration.
> + if (skb_checksum_start_offset(skb) != thoff)
> + return false;
> +
> + switch (ip_proto) {
> + case IPPROTO_TCP:
> + if (skb->csum_offset != offsetof(struct tcphdr, check) ||
> + !pskb_may_pull(skb, thoff + sizeof(struct tcphdr)))
> + return false;
> + break;
> + case IPPROTO_UDP:
> + if (skb->csum_offset != offsetof(struct udphdr, check) ||
> + !pskb_may_pull(skb, thoff + sizeof(struct udphdr)))
> + return false;
> + break;
[Severity: Medium]
Does pskb_may_pull(skb, thoff + sizeof(struct tcphdr)) trigger an unnecessary
__pskb_pull_tail() on every non-GSO TCP packet on tun/tap zerocopy TX?
When hdr->hdr_len is 0 (the default from virtio_net_hdr_from_skb()),
__tun_vnet_hdr_get() computes hdr_len as csum_start + csum_offset + 2, which
stops right after tcphdr->check and leaves skb_headlen(skb) 2 bytes short of
thoff + sizeof(struct tcphdr) in tun_get_user() and tap_get_user(). Neither
this helper nor virtio_net_hdr_to_skb() dereferences struct tcphdr, so
checking skb->len < thoff + sizeof(struct tcphdr) (and sizeof(struct udphdr))
would enforce the same length check without pulling unread fragment data.
[ ... ]
> +/*
> + * 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]
Returning 1 here makes atomic64_inc(&tun->rx_csum_sw) in tun_get_user() and
tun_xdp_one() reachable for the first time, which can cause cacheline false
sharing on multiqueue tun devices.
In struct tun_struct (added in commit "net: account for ingress-resolved
virtio net hdr state"), rx_csum_sw sits in a contiguous 44-byte span with
rx_batched, xdp_prog, steering_prog, and filter_prog, which are read on every
RX and TX packet across all queues. Unmatched non-GSO CHECKSUM_PARTIAL
traffic on one queue will bounce that cacheline across CPUs handling healthy
queues. Using a per-CPU counter summed in tun_get_ethtool_stats() would
avoid the contention and false sharing.
> @@ -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 re-expose a stale transport_header offset on
recycled skbs?
On an IFF_TAP | IFF_NAPI | IFF_NAPI_FRAGS device with gro_flush_timeout and
napi_defer_hard_irqs configured (where busy_poll_stop() or tun_napi_poll()
keeps packets held in tfile->napi.gro across tun_get_user() calls),
napi_reuse_skb() recycles GRO-merged skbs into tfile->napi.skb without
unsetting transport_header, and tun_napi_alloc_frags() only clears
skb->protocol. Restoring that stale offset on mismatch leaves
skb_transport_header_was_set(skb) true, so skb_probe_transport_header() in
tun_get_user() returns immediately and passes a wrong or out-of-bounds
transport_header downstream.
Calling skb_unset_transport_header(skb) on mismatch (here and in
virtio_net_hdr_tnl_to_skb() in commit "net: virtio: compute the outer
checksum of non-GSO tunnel packets") would avoid preserving stale offsets.
[ ... ]
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 930e85e4bf739..7ae70ca1556e4 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -2778,6 +2778,24 @@ 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. It can also make an IFF_TAP device something
> + * else, while the device still builds and parses Ethernet headers.
> + */
> +static int packet_vnet_hdr_to_skb(struct sk_buff *skb,
> + const struct virtio_net_hdr *vnet_hdr)
> +{
> + const struct net_device *dev = skb->dev;
> + bool has_eth = dev_has_header(dev) &&
> + (dev->type == ARPHRD_ETHER ||
> + dev->type == ARPHRD_LOOPBACK ||
> + dev->header_ops == ð_header_ops);
> +
> + return virtio_net_hdr_to_skb(skb, vnet_hdr, has_eth, vio_le());
> +}
[Severity: High]
Does referencing eth_header_ops break the build when CONFIG_PACKET=m?
eth_header_ops in net/ethernet/eth.c is not exported with EXPORT_SYMBOL(), so
modpost fails with an undefined symbol for af_packet.ko.
[Severity: High]
Can non-Ethernet devices that still have link-layer headers (such as ipgre or
ipoib) bypass the ingress CHECKSUM_PARTIAL validation here?
On an NBMA ipgre device (ARPHRD_IPGRE, ipgre_header_ops, hard_header_len ==
24), has_eth evaluates to false, routing the skb into the raw-L3 branch of
virtio_net_l3_start(). For SOCK_RAW frames with len >= 64 (or tpacket_snd()),
skb_network_offset(skb) is 24, so virtio_net_l3_start() skips the leading
24-byte tnl_params unvalidated and validates an inner IP/UDP/TCP header with
csum_start >= 44. ipgre_xmit() then pulls those 24 bytes, encapsulates with
attacker-controlled tnl_params->protocol, and forwards across veth into the
host stack with CHECKSUM_PARTIAL still misaligned into the outer payload.
(For short SOCK_RAW packets where packet_snd() resets network_header to 0,
virtio_net_l3_start() validates the GRE pseudo-header itself as an IPv4
header with options.)
Non-Ethernet devices with dev_has_header(dev) should not fall through to the
raw-L3 validation branch and should resolve the checksum in software instead.
[Severity: Medium]
Can these unlocked reads of dev->header_ops and dev->type race with
concurrent netdevice type changes and cause a NULL pointer dereference in
dev_has_header()?
packet_snd() and tpacket_snd() hold neither rtnl_lock() nor rcu_read_lock().
When a non-Ethernet port with NULL header_ops (such as nlmon or bareudp) is
added to an IFF_UP team device, team_port_add() -> team_setup_by_port()
clears dev->header_ops and updates dev->type concurrently. Because
dev_has_header() evaluates dev->header_ops && dev->header_ops->create without
READ_ONCE(), a compiler reload between the check and dereference can oops:
CPU0 CPU1
packet_snd()
packet_vnet_hdr_to_skb()
dev_has_header(dev)
if (dev->header_ops)
team_port_add()
...
team_setup_by_port()
dev->header_ops = NULL
dev->header_ops->create <-- NULL pointer dereference
Even without a reload, the multiple plain reads of dev->header_ops and
dev->type are data races that can compute an inconsistent has_eth.
Snapshotting READ_ONCE(dev->header_ops) and READ_ONCE(dev->type) once into
locals (paired with WRITE_ONCE() on the writers) would prevent this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=4
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets
2026-12-04 4:01 ` [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
@ 2026-12-05 4:01 ` sashiko-bot
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-05 4:01 UTC (permalink / raw)
To: Showta Ishizaki; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] net: virtio: unchecked uh->len and LCO padding mismatch in
outer csum
- [Low] net: virtio: IPv6 outer UDP csum ignores active Routing Header
daddr
- [Low] net: virtio: lco_csum() miscomputes outer csum on odd inner_th -
outer_th
- [Low] net: virtio: redundant outer header parsing in
virtio_net_tnl_set_outer_csum()
--
commit 3a617a73c8dde395774db7194e8a070983df80c7
Author: Showta Ishizaki <zakinko@snowrabbit.org>
net: virtio: compute the outer checksum of non-GSO tunnel packets
This commit adds virtio_net_tnl_set_outer_csum() to compute the outer
UDP checksum for non-GSO tunnel packets with
VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM, either via local checksum offload
while CHECKSUM_PARTIAL or by summing the datagram in full after software
inner checksum completion.
> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index 714b20acd38f0..6fe0c59217175 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
[ ... ]
> @@ -553,6 +555,72 @@ virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool has_eth, bool outer_isv6,
> return ip_proto == IPPROTO_UDP && outer_th == thoff;
> }
[ ... ]
> +static inline int
> +virtio_net_tnl_set_outer_csum(struct sk_buff *skb, bool has_eth,
> + bool outer_isv6, unsigned int outer_th)
> +{
> + unsigned int thoff;
> + struct udphdr *uh;
> + int ip_proto, nhoff;
> + __be16 proto;
> + __wsum csum;
> + int len, err;
> +
> + /* virtio_net_tnl_offsets_ok() has passed; this finds nhoff. */
> + if (!virtio_net_l3_start(skb, has_eth, &nhoff, &proto) ||
> + !virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto))
> + return -EINVAL;
[Severity: Low]
This isn't a bug, but virtio_net_tnl_offsets_ok() has already run both
virtio_net_l3_start() and virtio_net_l4_start() for this packet, and
thoff and ip_proto are unused here. Returning nhoff from
virtio_net_tnl_offsets_ok() and passing it in would avoid repeating the
outer header walk.
Similarly, virtio_net_hdr_tnl_to_skb() sets SKB_GSO_UDP_TUNNEL_CSUM or
SKB_GSO_UDP_TUNNEL in gso_type unconditionally and then immediately
clears them when !skb_is_gso(skb).
> +
> + err = skb_ensure_writable(skb, outer_th + sizeof(*uh));
> + if (err)
> + return err;
> +
> + uh = (struct udphdr *)(skb->data + outer_th);
> + len = ntohs(uh->len);
> + uh->check = 0;
> + if (skb->ip_summed == CHECKSUM_PARTIAL) {
> + csum = lco_csum(skb);
[Severity: Low]
Can lco_csum() miscompute the outer checksum when inner_th - outer_th is
odd?
virtio_net_hdr_tnl_to_skb() allows an odd inner_nh_offset, which makes
skb_checksum_start(skb) - skb_transport_header(skb) odd. lco_csum()
passes that length to csum_partial(), which requires even lengths for
non-final chunks and otherwise folds the inner checksum complement at
the wrong byte parity.
> + } else {
> + /* Sum the datagram alone: uh->len, not skb->len - outer_th,
> + * which also counts non-zero Ethernet padding and so
> + * miscomputes the outer checksum. len is from the frame,
> + * so bound it before reading that many bytes.
> + */
> + if (len < sizeof(*uh) || len > skb->len - outer_th)
> + return -EINVAL;
> + csum = skb_checksum(skb, outer_th, len, 0);
> + }
[Severity: Medium]
Should the uh->len bounds check also run on the CHECKSUM_PARTIAL path,
before uh->check is cleared? An untrusted frame with an invalid uh->len
currently bypasses the check and gets a bogus outer UDP checksum instead
of -EINVAL.
Also, when a small tunnel packet has non-zero Ethernet padding
(skb->len > outer_th + len), does lco_csum() produce the wrong outer
checksum? skb_checksum_help() and TX offload sum through skb->len, so
the padding breaks LCO cancellation and causes receiver drops.
Validating uh->len before mutating uh->check and either requiring
outer_th + len == skb->len for LCO or falling back to completing the
inner checksum and summing [outer_th, outer_th + len) would handle both
cases.
> +
> + if (outer_isv6) {
> + const struct ipv6hdr *ip6h = (void *)(skb->data + nhoff);
> +
> + uh->check = udp_v6_check(len, &ip6h->saddr, &ip6h->daddr,
> + csum);
> + } else {
[Severity: Low]
Does udp_v6_check() use the wrong destination address when the outer
IPv6 packet carries an active Routing Header (segments_left > 0)?
virtio_net_l4_start() calls ipv6_find_hdr() with target -1, which walks
past NEXTHDR_ROUTING regardless of segments_left. Using ip6h->daddr
instead of the final destination address from the Routing Header
violates RFC 8200 Section 8.1 and causes drops at the final destination.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=5
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation
2026-12-04 4:01 ` [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
@ 2026-12-05 4:01 ` sashiko-bot
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-05 4:01 UTC (permalink / raw)
To: Showta Ishizaki; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
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 <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
(default 1) guarded by a global static key so deployments can opt out of
virtio_net header checksum validation.
> 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
[ ... ]
> @@ -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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH RFC net v11 0/6] more virtio-net csum hardening
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
` (6 preceding siblings ...)
2026-12-04 4:06 ` [PATCH RFC net v11 0/6] more virtio-net csum hardening netdev-bot+sinfo
@ 2026-12-05 4:01 ` sashiko-bot
7 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-05 4:01 UTC (permalink / raw)
To: Showta Ishizaki; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Sashiko has finished reviewing this 6-patch series:
- Patch 3: no issues found.
- Patch 1 ("net: account for ingress-resolved virtio net hdr state"): 1
potential issue (1 Medium)
- Patch 2 ("um: vector: trim skbs before verifying the header"): 1
potential issue (1 High)
- Patch 4 ("net: resolve uncommon partial checksums at ingress"): 8
potential issues (2 High, 6 Medium)
- Patch 5 ("net: virtio: compute the outer checksum of non-GSO t..."): 4
potential issues (1 Medium, 3 Low)
- Patch 6 ("net: add a sysctl to opt out of virtio net hdr check..."): 1
potential issue (1 High)
Detailed reviews have been sent as separate replies to patches 1, 2, and
4-6.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-12-05 4:01 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 4:01 [PATCH RFC net v11 0/6] more virtio-net csum hardening Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 2/6] um: vector: trim skbs before verifying the header Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 4/6] net: resolve uncommon partial checksums at ingress Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 3/6] virtio_net: parse tunnel csum_start little-endian Showta Ishizaki
2026-12-04 4:01 ` [PATCH RFC net v11 6/6] net: add a sysctl to opt out of virtio net hdr checksum validation Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:01 ` [PATCH RFC net v11 5/6] net: virtio: compute the outer checksum of non-GSO tunnel packets Showta Ishizaki
2026-12-05 4:01 ` sashiko-bot
2026-12-04 4:06 ` [PATCH RFC net v11 0/6] more virtio-net csum hardening netdev-bot+sinfo
2026-12-05 4:01 ` sashiko-bot
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.