🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #6347

[PATCH net v2] octeontx2-pf: fix skb use-after-free with ipsec crypto offload

#6347
From: Nicolai Buchwitz
Date: Thu, 22 Oct 2026 09:12
85 lines
11856 bytes
otx2_dma_map_skb_frag() calls skb_unshare() on its own copy of the skb
pointer. For a cloned skb, for example with tcpdump running on the
interface, this frees the skb and the new copy is lost on return. The
transmit path then uses the freed skb and the copy leaks.

Make the skb writable in place in otx2_sq_append_skb() instead, so the
pointer stays valid. Also do this for skbs with shared frags, as the
hardware writes the encrypted data back into them.

Fixes: 195c3d463181 ("octeontx2-pf: map skb data as device writeable")
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
This was flagged in the clashiko review of my skb_unshare() rename patch [1].

Compile-tested only, I have no octeontx2 hardware.

[1] https://lore.kernel.org/all/20261015-nb-skb-unclone-full-v1-1-0dfbf01f60f2@tipi-net.de/
---
Changes in v2:
- Also handle skbs with shared frags (Jakub)
- Note: conflicts with "net: rename skb_unshare() to skb_unclone_full()"
  in net-next, the resolution is to drop the skb_unclone_full() line
- Link to v1: https://patch.msgid.link/20261019-nb-otx2-xfrm-unshare-net-v1-1-ee9b24f9e673@tipi-net.de

To: Sunil Goutham <sgoutham@marvell.com>
To: Geetha sowjanya <gakula@marvell.com>
To: Ratheesh Kannoth <rkannoth@marvell.com>
To: Subbaraya Sundeep <sbhatta@marvell.com>
To: Bharat Bhushan <bbhushan2@marvell.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>
To: "David S. Miller" <davem@davemloft.net>
To: Eric Dumazet <edumazet@kernel.org>
To: Jakub Kicinski <kuba@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 4 +---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c   | 8 ++++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
index b11389a841d15..91ebf247f5f90 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
@@ -2121,10 +2121,8 @@ dma_addr_t otx2_dma_map_skb_frag(struct otx2_nic *pfvf,
 	int offset;
 
 	/* Crypto hardware need write permission for ipsec crypto offload */
-	if (unlikely(xfrm_offload(skb))) {
+	if (unlikely(xfrm_offload(skb)))
 		dir = DMA_BIDIRECTIONAL;
-		skb = skb_unshare(skb, GFP_ATOMIC);
-	}
 
 	/* First segment is always skb->data */
 	if (!seg) {
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
index 8d2d607bc92f9..b98842c7e40e0 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
@@ -1205,6 +1205,14 @@ bool otx2_sq_append_skb(void *dev, struct netdev_queue *txq,
 	if (free_desc < otx2_get_sqe_count(pfvf, skb))
 		return false;
 
+	/* Crypto hardware need write permission for ipsec crypto offload */
+	if (unlikely(xfrm_offload(skb)) &&
+	    (skb_cloned(skb) || skb_has_shared_frag(skb)) &&
+	    skb_ensure_writable(skb, skb->len)) {
+		dev_kfree_skb_any(skb);
+		return true;
+	}
+
 	num_segs = skb_shinfo(skb)->nr_frags + 1;
 
 	/* If SKB doesn't fit in a single SQE, linearize it.

---
base-commit: 82e31923c0553fdbfcddcd910ca07952880ca9b9
change-id: 20261019-nb-otx2-xfrm-unshare-net-6b74a96a8d9e

Best regards,
--  
Nicolai Buchwitz <nb@tipi-net.de>
Technical Details
Message-ID: <20261022-nb-otx2-xfrm-unshare-net-v2-1-5590c9325bcd@tipi-net.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350451-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350451-linux-kernel-netdev=dewy.ru
From: nb@tipi-net.de (Nicolai Buchwitz)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] octeontx2-pf: fix skb use-after-free with ipsec
 crypto offload
Date: Thu, 22 Oct 2026 11:12:41 +0200
Organization: Usenet Network
Message-ID: <20261022-nb-otx2-xfrm-unshare-net-v2-1-5590c9325bcd@tipi-net.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="171964"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:2dqlzyJUcIyOxAIoaUQNOzqj6nM= sha256:75yeiN6xkNrGfN0fYDdLJTm5wWjsR10g2ahlHh6pVVM=
	sha1:WrejzFJl7Rn8Tkh63udreeo/JTY= sha256:y+8NkcVCwNCcFbOpphkOVLoHZNkpwuKpjJ8DekWNPKE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 1B0DF1111F6; Thu, 22 Oct 2026 12:16:49 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=tipi-net.de
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id dKdhGWFsP7p7;
	Thu, 22 Oct 2026 12:16:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-350451-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=tipi-net.de
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 904B11111D8; Thu, 22 Oct 2026 12:16:35 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 468B324FE2; Thu, 22 Oct 2026 09:12:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792660372;
	b=pasocpolJcEp9pVmhp0L01rcjlYuwzqdHF/wAp68YVuS1Mi59Z6dzJU5zP9sb5UZZifn
	 vToIBaF8oswGuufmT+oSnYLmeERlGfGFtQNR0hfJCsN8woeTfee5AFFDHlQFTG/9WUI1x
	 CWIvWg7OSdw+mGMbafJvLnoDh3Au4gBMLyuPF6RosL3py/bxXFc9dffN8O2e3VBNcEYBr
	 I6ORygEU+3ZOqWwOXgp8an5XyrsTwEbR565tZhcQQ069oIowt4kd9cYdjyoqdLJ+Xk6Wu
	 QXqShW0Y7p7foYb13hn6ZG/uXduzgrHlNTFtSmxpYstYqJ2V/7dYsdjT2SfQNUGodjQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792660372;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:
	 Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:X-B4-Tracking:
	 X-Change-ID:To:Cc:X-Mailer:X-Last-TLS-Session-Version;
	bh=QxIVZi956bm1gCgqK2NJrL5eCNIcMpvqgqerM8iP2DE=;
	b=MJFI0j8PvlmRTWmMt/uyxWQ+c6LmUB/hM6BkMuOuJVGc7gwAg/zNRoFFzFmQEIWKQxog
	 utZblwJjcFlngCAtZ508b4C1y99QAbDYiaFQGz9g8Tl6AQ7rQ025gS2OrX+lkJwsxiXrP
	 yGebKi+jRWkQr1khCcguRCxcCM4Cbd42xetYM6aMNcm2jmZvwMyP4TSvLh7rCaALX7BL2
	 Lb2ObuXmxnwXSxGNxtKgRkJ/VRMzMCEp1qM3Y3Qnqjn7KBa7PiT3IhP4+8lEe/012ZUnn
	 Rka9ZK2z4PJ2vezxsA9N8GieCAu+i+evTstYF9ARHlhVodZ5LSVSTBlzq7RImEBZ/Gg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=tipi-net.de header.i=@tipi-net.de header.a=rsa-sha256 header.s=dkim header.b=F0fS+8SR;
	dmarc=none header.from=tipi-net.de;
	spf=pass smtp.mailfrom=tipi-net.de;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 06181606A321;
	Thu, 22 Oct 2026 09:12:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=tipi-net.de header.i=@tipi-net.de header.a=rsa-sha256 header.s=dkim header.b=F0fS+8SR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=194.13.80.246
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792660371;
	b=TzdhDLjS+fyVfTNBQtvVrLhQIbNE9seTWf0uxppIFuLxGpSDEL2azAJ8ZSL3cRjwPMdn
	 dOgWD+aqTzJO/8kEhZWF/PqipWeVGcCodETbTzp2IlUMreu4O3jx8IH+Ci13QIj7QxQb7
	 Q5pQYPPy9tVT16nCFyanCBljT9hGF9r9nfO3WiuZtB62DSIloe0Oek4Cid71q7HmpMV7+
	 T/O4fEeg/9Qw4RwZseqapBSGKlKHGVwruwc704SI20Kd3H9zQI89fDi3+vbjwBiL1kyzs
	 9FOHuODQfsn7+Td1XDZ8tPk6pVoZNUKkWinbLBPf7BBOMH7N/aDRigPBWjk4Rs/6vZA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792660371;
	h=DMARC-Filter:Received:DKIM-Signature:From:Date:Subject:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:X-B4-Tracking:
	 X-Change-ID:To:Cc:X-Mailer:X-Last-TLS-Session-Version;
	bh=QxIVZi956bm1gCgqK2NJrL5eCNIcMpvqgqerM8iP2DE=;
	b=pQaz9UdzZBTvaIf8MsdZvvZPkJOw0fH5Mech82fdQiHkxA6J/dO+XnfprkNSX6tRZx2q
	 z/uKoTj5sC+Ex270cMDqRDSaMkdwTOagrMM+8dSEat6XJ0uIqD5fpaNyvpZHoAjX4TsKF
	 vBAzkAwAvcF0lNKRmYyGn1YzVF2/X+q8vXf5KbW/tSsDSVo70QsQhOtQETZKFKKY3L1dU
	 QWlRrb291lRriOKy+BKSrO5yFGXgm77ttkBM93M0pO7jlARibVYlR14NSO2ATbZrqd9tk
	 9LbWaTYCIYC7uzVebzuml0R0PYFZ4YJSwurtvxeo5IdpKQ1Tk4qvE4nF2FGFtmGiqkw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=tipi-net.de;
	spf=pass smtp.mailfrom=tipi-net.de;
	dkim=pass header.d=tipi-net.de header.i=@tipi-net.de header.a=rsa-sha256 header.s=dkim header.b=F0fS+8SR;
	arc=none smtp.remote-ip=194.13.80.246
X-Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A29BA606A319;
	Thu, 22 Oct 2026 09:12:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A29BA606A319
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de
X-Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BE64BA0190;
	Thu, 22 Oct 2026 11:12:45 +0200 (CEST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim;
	t=1792660367; h=from:subject:date:message-id:to:cc:mime-version:content-type:
	 content-transfer-encoding; bh=QxIVZi956bm1gCgqK2NJrL5eCNIcMpvqgqerM8iP2DE=;
	b=F0fS+8SR7/eyPrVn4eviPfx+XSgCvWKP/MqEzlXKqK2yW1/fN7G+H6Pa2rQzp0ouP1Nk+q
	e3FhtUwhfzE7qwV/0bVT3fqvptQVC3GJQ/DdKksWQ0j1+ZNYhhMJ0jMnKQMUHYIyrZKXTw
	4oGNRPxOuHXNfX3CBbhxqGGYeSpO8a8anmGr9eKYSgPsR+pGLyltVNaOOUWXRjRA8qqEJs
	HzmMEssf6LgtkF/o1wT3GR2u8EjgIl3KGULH4aTF2ROkUpg86odwbD80ds7zYcSgHKb2n/
	cBpGXETJe0A4dDvZpRfoS3eZ1FpT8Og0DDYaeq4lwH3blbHeQxj+Ujmj17zKvg==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-B4-Tracking: v=1; b=H4sIAAAAAAAC/4WOwQ6CMBBEf4Xs2TW0kmI9+R+GQwuLrImFtIVgC
 P9uix/gcWbfzM4GgTxTgFuxgaeFA48uCXkqoB2MexJylzTIUipRCo3O4hhXiWvv3zi7MBhP6Ci
 isnVltDLXThOk+OSp5/WofkACoPmZYbYvamMuzdjAIY7+cwxYxAH//7UIFEikrax6Taq+3CNPn
 E/njqDZ9/0Lw/6QytkAAAA=
X-Change-ID: 20261019-nb-otx2-xfrm-unshare-net-6b74a96a8d9e
X-Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, 
 Nicolai Buchwitz <nb@tipi-net.de>
X-Mailer: b4 0.16.0
X-Last-TLS-Session-Version: TLSv1.3