From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Paulos Yibelo <habte.yibelo@gmail.com>,
netdev@vger.kernel.org
Cc: richard@nod.at, anton.ivanov@cambridgegreys.com,
johannes@sipsolutions.net, willemdebruijn.kernel@gmail.com,
jasowangio@gmail.com, mst@redhat.com, eperezma@redhat.com,
xuanzhuo@linux.alibaba.com, andrew+netdev@lunn.ch,
pablo@netfilter.org, fw@strlen.de, phil@nwl.cc,
razor@blackwall.org, idosch@nvidia.com, dsahern@kernel.org,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org,
linux-um@lists.infradead.org, virtualization@lists.linux.dev,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
bridge@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v6 1/2] net: validate virtio checksum start after network header
Date: Tue, 22 Sep 2026 21:27:26 -0400 [thread overview]
Message-ID: <willemdebruijn.kernel.2cdfef118aa1d@gmail.com> (raw)
In-Reply-To: <willemdebruijn.kernel.259bc7096258d@gmail.com>
Willem de Bruijn wrote:
> Paulos Yibelo wrote:
> > __virtio_net_hdr_to_skb() checks a minimum network-header length for
> > CHECKSUM_PARTIAL packets. Its checksum start is relative to skb->data,
> > but some callers have not established skb->network_header when they
> > convert the virtio header.
> >
> > Pass the data-relative L3 origin explicitly. Ethernet receive paths
> > parse the frame and nested VLAN headers without changing skb state.
> > AF_PACKET uses the frame's actual L3 origin even when the socket
> > protocol is ETH_P_IP and the raw frame carries VLAN tags. Non-Ethernet
> > AF_PACKET devices retain their established skb network offset.
> >
> > Also pass the actual L3 protocol so IPv6 packets use the 40-byte base
> > header minimum even without TCPv6 GSO. IFF_TUN obtains that protocol
> > from the packet before skb->protocol is set. Name the Ethernet parser
> > accordingly, use the same origin for tunnel validation, and propagate
> > conversion failures in UML.
> >
> > The bound remains a minimum; fragmentation paths separately validate
> > the parsed IPv4 or IPv6 header length before completing a checksum.
> >
> > Fixes: 49d14b54a527 ("net: test for not too small csum_start in virtio_net_hdr_to_skb()")
> > Fixes: a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")
> > Reported-by: Paulos Yibelo <habte.yibelo@gmail.com>
> > Link: https://lore.kernel.org/netdev/20260920004733.6473-2-habte.yibelo@gmail.com/
> > Cc: stable@vger.kernel.org
> > Assisted-by: LLM
> > Signed-off-by: Paulos Yibelo <habte.yibelo@gmail.com>
> > ---
> > arch/um/drivers/vector_transports.c | 13 ++++-
> > drivers/net/tun_vnet.h | 52 ++++++++++++++++-
> > drivers/net/virtio_net.c | 10 +++-
> > include/linux/virtio_net.h | 87 ++++++++++++++++++++++++-----
> > net/packet/af_packet.c | 24 +++++++-
> > 5 files changed, 163 insertions(+), 23 deletions(-)
>
> The fix may still miss the case IPv4 packets have options.
>
> This version is a very large patch.
>
> Untested shorter first suggestion by bot, which looks plausible as a
> starting point for discussion.
Cleaned up some more:
diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h
index f4c652b1fa44..c24607af2aad 100644
--- a/drivers/net/tun_vnet.h
+++ b/drivers/net/tun_vnet.h
@@ -180,6 +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)
{
+ if ((flags & TUN_TYPE_MASK) == IFF_TUN)
+ skb_reset_network_header(skb);
+
return virtio_net_hdr_to_skb(skb, hdr, tun_vnet_is_little_endian(flags));
}
@@ -199,6 +202,9 @@ tun_vnet_hdr_tnl_to_skb(unsigned int flags, netdev_features_t features,
struct sk_buff *skb,
const struct virtio_net_hdr_v1_hash_tunnel *hdr)
{
+ if ((flags & TUN_TYPE_MASK) == IFF_TUN)
+ skb_reset_network_header(skb);
+
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index c381b916c1b5..02c448de0802 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -48,6 +48,42 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,
return 0;
}
+static inline int virtio_net_hdr_nh_min_len(const struct sk_buff *skb,
+ unsigned int nh_min_len)
+{
+ int thoff = skb_transport_offset(skb);
+ __be16 proto;
+ int nhoff;
+
+ if (skb_network_header_was_set(skb)) {
+ nhoff = skb_network_offset(skb);
+ proto = skb->protocol;
+ } else {
+ if (unlikely(thoff < ETH_HLEN))
+ return -EINVAL;
+ nhoff = ETH_HLEN;
+ proto = eth_hdr(skb)->h_proto;
+ }
+
+ if (eth_type_vlan(proto)) {
+ proto = __vlan_get_protocol(skb, proto, &nhoff);
+ if (!proto)
+ return -EINVAL;
+ }
+
+ if (proto == htons(ETH_P_IP)) {
+ const struct iphdr *iph = (void *)(skb->data + nhoff);
+
+ if (unlikely(thoff < nhoff + sizeof(*iph)))
+ return -EINVAL;
+ nh_min_len = max_t(u32, iph->ihl * 4, sizeof(*iph));
+ } else if (proto == htons(ETH_P_IPV6)) {
+ nh_min_len = sizeof(struct ipv6hdr);
+ }
+
+ return nhoff + nh_min_len;
+}
+
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)
@@ -98,13 +134,15 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,
u32 start = __virtio16_to_cpu(little_endian, hdr->csum_start);
u32 off = __virtio16_to_cpu(little_endian, hdr->csum_offset);
u32 needed = start + max_t(u32, thlen, off + sizeof(__sum16));
+ int min_thoff;
if (!pskb_may_pull(skb, needed))
return -EINVAL;
if (!skb_partial_csum_set(skb, start, off))
return -EINVAL;
- if (skb_transport_offset(skb) < nh_min_len)
+ min_thoff = virtio_net_hdr_nh_min_len(skb, nh_min_len);
+ if (min_thoff < 0 || skb_transport_offset(skb) < min_thoff)
return -EINVAL;
next prev parent reply other threads:[~2026-09-23 1:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 3:03 [PATCH net v6 0/2] net: prevent partial checksums from modifying network headers Paulos Yibelo
2026-09-22 3:03 ` [PATCH net v6 1/2] net: validate virtio checksum start after network header Paulos Yibelo
2026-09-22 5:14 ` Michael S. Tsirkin
[not found] ` <CAHv8Y_4OKdVkigToBmXXhhUxu+EL2iWVADZJ=LS4CGqBATgU5g@mail.gmail.com>
2026-09-22 5:55 ` Johannes Berg
2026-09-22 5:56 ` Johannes Berg
2026-09-22 8:46 ` Michael S. Tsirkin
2026-09-22 22:29 ` Willem de Bruijn
2026-09-23 1:27 ` Willem de Bruijn [this message]
2026-09-23 10:21 ` Michael S. Tsirkin
2026-09-23 10:46 ` Eric Dumazet
2026-09-22 3:03 ` [PATCH net v6 2/2] ip: reject partial checksums covering network headers Paulos Yibelo
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=willemdebruijn.kernel.2cdfef118aa1d@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=anton.ivanov@cambridgegreys.com \
--cc=bridge@lists.linux.dev \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=fw@strlen.de \
--cc=habte.yibelo@gmail.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jasowangio@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=razor@blackwall.org \
--cc=richard@nod.at \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/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
all inboxes | Powered by JetHome®