mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitrii Iakunin <zeil@nebius.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	NB-Core Team <NB-CoreTeam@nebius.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Willem de Bruijn <willemb@google.com>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH net v2] net: validate IPv4 checksum start in skb_csum_hwoffload_help()
Date: Wed, 11 Nov 2026 12:04:52 +0000	[thread overview]
Message-ID: <20261111120448.49979-1-zeil@nebius.com> (raw)

Commit 6785011f8b16 ("ipv4: validate checksum_start before completing
checksum") added checks so that malformed CHECKSUM_PARTIAL metadata
cannot make software checksum completion write the folded checksum
into the IPv4 header.

skb_csum_hwoffload_help() completes checksums in software when the
device features cannot satisfy the request (e.g. via validate_xmit_skb(),
ieee80211_tx_skb_fixup(), openvswitch queue_userspace_packet() or
ppp_bridge_xmit()). Packets built by AF_PACKET with PACKET_VNET_HDR or
by tap with VIRTIO_NET_HDR_F_NEEDS_CSUM can reach it with a csum_start
that points inside the IPv4 header, and this path was not covered by
the earlier validation.

At the sw_checksum label, for IPv4 packets, require the fixed IPv4
header to be pullable and reject csum_start values that fall before the
end of the IPv4 header. Return -EINVAL so callers drop the packet.

Unlike the sites added by that commit, this path cannot rely on
earlier validation, so:

 - Locate the IPv4 header at the depth returned by __vlan_get_protocol()
   rather than at network_header. After skb_vlan_untag() pops only the
   outer tag of a QinQ frame and the skb is redirected by tc mirred or
   bpf_redirect, network_header still points at the inner VLAN tag, and
   ihl would be read from the TCI.

 - Reject ihl < 5. ip_rcv_core() has not checked it on these paths, and
   with a sender-chosen ihl of 0..4 a csum_start inside the fixed 20-byte
   header would otherwise pass the check.

 - Skip the check when the network offset is negative. On the PPP
   channel-bridge path (L2TP or PPTP), the outer headers have been pulled
   while network_header and protocol still describe the outer IPv4
   header. The IPv4 header of the packet being checksummed cannot be
   located there, and those packets used to be forwarded.

Hardware-offloaded checksums and SCTP CRC handling are unchanged.

This change only covers the software fallback in
skb_csum_hwoffload_help(). Other places that call skb_checksum_help()
directly are not covered: drivers that fall back to software after the
core offered hardware offload (e.g. wireguard, igb, tg3), and core
callers such as xsk tx_sw_csum and netem corruption. As the earlier
commit notes, validating the metadata on input remains the complete fix.

Cc: stable@vger.kernel.org
Fixes: f43798c27684 ("tun: Allow GSO using virtio_net_hdr")
Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.")
Assisted-by: claude-opus-5.5
Signed-off-by: Dmitrii Iakunin <zeil@nebius.com>

---
v2:
- Locate the IPv4 header using the parsed VLAN depth.
- Reject IPv4 headers with ihl < 5.
- Skip validation when the network offset is negative.
- Narrow the subject and document software-fallback paths not covered.
- Update the Fixes tags to identify the original introduction points.

v1: https://lore.kernel.org/lkml/20261102140633.42564-1-zeil@nebius.com/

 net/core/dev.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index df1a840b0334..fafcb8f7ff9b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4111,6 +4111,9 @@ static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb,
 int skb_csum_hwoffload_help(struct sk_buff *skb,
 			    const netdev_features_t features)
 {
+	__be16 protocol;
+	int offset;
+
 	if (unlikely(skb_csum_is_sctp(skb)))
 		return !!(features & NETIF_F_SCTP_CRC) ? 0 :
 			skb_crc32c_csum_help(skb);
@@ -4130,6 +4133,26 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,
 	}
 
 sw_checksum:
+	offset = skb_network_offset(skb);
+	protocol = skb->protocol;
+	if (eth_type_vlan(protocol))
+		protocol = __vlan_get_protocol(skb, protocol, &offset);
+
+	/* Use the parsed VLAN depth: network_header may point at an inner
+	 * tag. If the network offset is negative, network_header refers
+	 * to bytes preceding the current packet data and cannot be used
+	 * to locate the IPv4 header being validated.
+	 */
+	if (offset >= 0 && protocol == htons(ETH_P_IP)) {
+		const struct iphdr *iph;
+
+		if (!pskb_may_pull(skb, offset + sizeof(*iph)))
+			return -EINVAL;
+		iph = (const struct iphdr *)(skb->data + offset);
+		if (iph->ihl < 5 ||
+		    skb_checksum_start_offset(skb) < offset + iph->ihl * 4)
+			return -EINVAL;
+	}
 	return skb_checksum_help(skb);
 }
 EXPORT_SYMBOL(skb_csum_hwoffload_help);
-- 
2.52.0


             reply	other threads:[~2026-11-11 12:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 12:04 Dmitrii Iakunin [this message]
2026-11-11 12:06 ` netdev-bot+sinfo

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=20261111120448.49979-1-zeil@nebius.com \
    --to=zeil@nebius.com \
    --cc=NB-CoreTeam@nebius.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.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®