🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12489

[PATCH] net: skbuff: don't BUG() when skb_copy_bits() fails in __pskb_pull_tail

#12489
From: shao.mingyin
Date: Sat, 07 Nov 2026 13:50
76 lines
11165 bytes
From: Shao Mingyin <shao.mingyin@zte.com.cn>

__pskb_pull_tail() BUG()s if skb_copy_bits() returns an error.
skb_copy_bits() fails when the lengths do not add up, or when a
frag_list child carries unreadable frags (devmem net_iov, commit
65249feb6b3d ("net: add support for skbs with unreadable frags")).  The
top-level check above does not cover frag_list children, and
skb_gro_receive() links them without propagating skb->unreadable, so a
mixed skb trips the BUG().

Nothing has been committed at that point, so return NULL the way the
rest of the function already handles failures, with a
DEBUG_NET_WARN_ON_ONCE() for debug kernels.  skb_condense(), the one
net/core caller that ignores the return, now checks it and keeps the
original truesize when the pull fails, as the frags are still there.

The other direct callers that ignore the return do not build a
frag_list child: xen-netfront drops the skb when the failed pull leaves
nr_frags at MAX_SKB_FRAGS, and niu, mlx5 and ftmac100 pull at most what
their own skb holds.  A length mismatch there is a driver bug, which
the debug warning reports.

This is the separate change that commit 279877d86c82 ("net: skbuff:
don't BUG() when skb_copy_bits() fails in copy helpers") left for the
callers; the audit is above.  No Fixes: tag and no stable marking: the
mixed skb is an invariant violation, not a regression, and this is a
net-next hardening in the BUG_ON() removal series.

Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
 net/core/skbuff.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Tested on 7.3.0-next-20261030 (QEMU/TCG guest).  QEMU has no devmem
(net_iov) backend, so a TEST-ONLY hook (applied to both kernels, not
part of this patch) fabricates an skb whose frag_list child carries an
unreadable frag, then calls the real __pskb_pull_tail() on it at
late_initcall time: skb_copy_bits() recurses into the child, sees the
unreadable frag and fails.  The hook then calls skb_condense() on the
same skb, so the failed pull must not shrink truesize.

  unpatched                             patched
  kernel BUG at                         __pskb_pull_tail() returns NULL,
  net/core/skbuff.c:2903                skb_condense() keeps truesize 960,
                                        boot continues, no BUG

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 48f676411724..8a200252ef93 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2900,8 +2900,11 @@ void *__pskb_pull_tail(struct sk_buff *skb, int delta)
 			return NULL;
 	}
 
-	BUG_ON(skb_copy_bits(skb, skb_headlen(skb),
-			     skb_tail_pointer(skb), delta));
+	if (unlikely(skb_copy_bits(skb, skb_headlen(skb),
+				   skb_tail_pointer(skb), delta))) {
+		DEBUG_NET_WARN_ON_ONCE(1);
+		return NULL;
+	}
 
 	/* Optimization: no fragments, no reasons to preestimate
 	 * size of pulled pages. Superb.
@@ -7218,7 +7221,8 @@ void skb_condense(struct sk_buff *skb)
 			return;
 
 		/* Nice, we can free page frag(s) right now */
-		__pskb_pull_tail(skb, skb->data_len);
+		if (!__pskb_pull_tail(skb, skb->data_len))
+			return;	/* frags are still there, keep truesize */
 	}
 	/* At this point, skb->truesize might be over estimated,
 	 * because skb had a fragment, and fragments do not tell
--
Technical Details
Message-ID: <20261107215051120CrLjo_cGXWfdJxXk4ae8s@zte.com.cn>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358390-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-358390-linux-kernel-netdev=dewy.ru
From: shao.mingyin@zte.com.cn
Newsgroups: linux.kernel.netdev
Subject: [PATCH] net: skbuff: don't BUG() when skb_copy_bits() fails in __pskb_pull_tail
Date: Sat, 7 Nov 2026 21:50:51 +0800 (CST)
Organization: Usenet Network
Message-ID: <20261107215051120CrLjo_cGXWfdJxXk4ae8s@zte.com.cn>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="UTF-8"
Injection-Info: usenet.network;
	logging-data="4113096"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:rXYXeK/+AkR3bmNaG7RldVNtt9U= sha256:NsuRscGq19eshc+uUqzRDlrXn7jN1EnnxEhlSJb7b98=
	sha1:cYF5kp/wW9UxXfyqq7Y41bmWypU= sha256:Ud8n6tjw9AItR9lpV8wai41G2Tyss6U34dA6ckt41F4=
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 D9BB711342E; Sat,  7 Nov 2026 16:53:27 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.95
X-Spam-Status: No, score=-2.95 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001]
	autolearn=ham autolearn_force=no
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 lXeOxk5bTMwa;
	Sat,  7 Nov 2026 16:53:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358390-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=zte.com.cn
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 369BB113422; Sat,  7 Nov 2026 16:53:10 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id BCB2333F72; Sat,  7 Nov 2026 13:50:59 +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=1794059459;
	b=pwYQWtn7+66vn/kusfclZ3QlDv1TBLtsY4J4K/2c1/PlqEGlqPVJCiOgegQaEPIwnFx3
	 4OsXIU2m4+whH9gnIr4SJaV0lewej+8Iaahr/ZOUo7fK6575qlHqInCcIWBpCRUTgrZPx
	 ipNWNd92ZuJyOiT9NO+lMjUUK7QftMm9zcpKihc/RW9cuz20H2VRXOEp8+F0iCKmFrloz
	 BJbXS9d7BPCTaOrbkwYyWyP4ykO2y1u2tXJvXnOga/rstMMYbPGde3KkLQtKMOuSwGEUw
	 i9q+pheIrQbWouH9S9XjmhaqatslRc+uUQOj0aJeVXfNGwWdvUXP8wqBjBFAYCNIMQg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794059459;
	h=X-Original-To:Received:DMARC-Filter:Received:Received:Received:
	 X-Zmail-TransId:X-Mailer:Message-ID:Date:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:Mime-Version:From:To:Cc:Subject:Content-Type:X-MAIL:X-TLS:
	 X-ENVELOPE-SENDER:X-SOURCE-IP:X-CLEAN:X-Fangmail-Anti-Spam-Filtered:
	 X-Fangmail-MID-QID;
	bh=yv1aNjLkbAl4fTpgBXhNWf1+G8wEj5mdyEs/bUbPwEI=;
	b=CIINlgOUiSrCtug8bdGQrRjHx6hUevIkVMpvAJBJtuVtGBQGkIo+V7Z/VLqoIGL9COB4
	 b+ze1QopIvgsitUUee6pz5l36G4TvjhHL6zNXemyS4N48ngI/pV+XZm/2QXtlRT3XC4Vb
	 viGb55GoYfJ73NcSmZhov/vbOwqW9rfgOaoQHEQQ4EecVe/pUWeHWT9YTNjRXz06B4bjj
	 dzJWJBPnMh8B9SOnyBAtDmfnrL/MkouqjaflJ90ZfgvRed9p0t/8i/axSDbOtGI0Savbv
	 KQerlmjEsSoet49KUQ7Z/7w914PrE10mMQ8DzH9J4ET2o/dSKoTAfpy+qeOHwu0q7cA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=pass header.from=zte.com.cn;
	spf=pass smtp.mailfrom=zte.com.cn;
	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 8C32A606D804;
	Sat,  7 Nov 2026 13:50:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=160.30.148.35
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794059458;
	b=knqy7OKXzflTWHwzSXT9KTkwydTVQ2xkzJ48/b/pmIy9xiOsWx+TKSCIU9YXnZAn2X+V
	 U6Nn77YTWE7DogskB4f3wcUgc/U3aRZgxhneNL4HH3YHZTNdJHHb/2z2hBtf31xtt3N6I
	 8o0eJN3FQLX7WOBqyo4jcbF5UKSwZT34dT2Vo0h10XjxGczu4a1qkivGZwGDtAPwiKXOJ
	 j/B9UllRVeV/Bo/MPu8dowmezmR2gW/KWfbFU8u3zm5HPZ0kOi7BnPmg4yMRNPjoZgK5J
	 +uJ0YwicnB5vSVYwHKoobuc/v46gfF2D4hfPQCWYZSO2I/ASzilHYh4eSWD+mo13oEw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794059458;
	h=DMARC-Filter:Received:Received:Received:X-Zmail-TransId:X-Mailer:
	 Message-ID:Date:Mime-Version:From:To:Cc:Subject:Content-Type:X-MAIL:
	 X-TLS:X-ENVELOPE-SENDER:X-SOURCE-IP:X-CLEAN:
	 X-Fangmail-Anti-Spam-Filtered:X-Fangmail-MID-QID;
	bh=yv1aNjLkbAl4fTpgBXhNWf1+G8wEj5mdyEs/bUbPwEI=;
	b=1nvsIlBhKV2oMCWmMc4nqYbaCun0V5XnCE2py2z8a61FBlTGGHZt3jVpNhAps/Jzcxjv
	 e+fmfE1hSU0QFx4nxHdNZrHaLnOciGSEc715hvSaZf8a5vIhnTorG+MWUdfRHmU2VBWUi
	 0DZqzMCmmkVRzSyugD/h169nZdSwX29oIbSql2/Sip8hIWOpMpMPqoK++xSRVXM8g5Pn+
	 b+GRdQtkj1dAcnjQ5nknoX8vZVd7uTSf5g9mdfGanAnhGa7/sQET9PrD7F1JZ1j1QM4NR
	 TfaaRdf8W5LJ7Wdnz3D/WLTeYRr3/fjG80z7jSRVwhmvqFnuj4V5N7GpuKhooWtLSMg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=zte.com.cn;
	spf=pass smtp.mailfrom=zte.com.cn;
	arc=none smtp.remote-ip=160.30.148.35
X-Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.35])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D512A606A330;
	Sat,  7 Nov 2026 13:50:57 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D512A606A330
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn
X-Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mxhk.zte.com.cn (FangMail) with ESMTPS id 4jMHWL4KG0z8XrrJ;
	Sat, 07 Nov 2026 21:50:54 +0800 (CST)
X-Received: from xaxapp01.zte.com.cn ([10.88.99.176])
	by mse-fl2.zte.com.cn with SMTP id 6A7DonWa001651;
	Sat, 7 Nov 2026 21:50:49 +0800 (+08)
	(envelope-from shao.mingyin@zte.com.cn)
X-Received: from mapi (xaxapp04[null])
	by mapi (Zmail) with MAPI id mid32;
	Sat, 7 Nov 2026 21:50:51 +0800 (CST)
X-Zmail-TransId: 2afb6aef2cbb3ac-e1dfc
X-Mailer: Zmail v1.0
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-Cc: <horms@kernel.org>, <josef@toxicpanda.com>, <willemb@google.com>,
        <almasrymina@google.com>, <linux-kernel@vger.kernel.org>
X-MAIL: mse-fl2.zte.com.cn 6A7DonWa001651
X-TLS: YES
X-ENVELOPE-SENDER: shao.mingyin@zte.com.cn
X-SOURCE-IP: 10.5.228.133 unknown Sat, 07 Nov 2026 21:50:54 +0800
X-CLEAN: YES
X-Fangmail-Anti-Spam-Filtered: true
X-Fangmail-MID-QID: 6AEF2CBE.000/4jMHWL4KG0z8XrrJ