Article View: linux.kernel.netdev
Article #11318[PATCH net-next v4 10/15] net: skbuff: reject a negative length in skb_copy_and_csum_bits()
From: Josef Bacik
Date: Wed, 04 Nov 2026 20:47
Date: Wed, 04 Nov 2026 20:47
76 lines
14594 bytes
14594 bytes
The head, frag and frag_list copies in skb_copy_and_csum_bits() each
clamp their length to @len. A negative @len from a broken caller
therefore becomes the copy length, and the copy takes it as a huge
unsigned value. The two len > 0 tests around the zero-fills only
protect the zero-fills.
Reject a negative @len on entry with -EINVAL and drop the two tests.
@to isn't touched in that case. Every caller already handles an error,
and skb_copy_and_csum_dev() zeroes its whole frame on one. No caller is
known to pass a negative length.
Found by the Sashiko AI review of the BUG_ON() series.
Link: https://lore.kernel.org/all/20261007-b4-skbuff-bug-on-v2-0-b9a5f732895b@toxicpanda.com/
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
net/core/skbuff.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index b017c9f861fe..7ecf6701f68c 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3731,8 +3731,7 @@ static noinline int skb_copy_and_csum_frag_list(const struct sk_buff *skb,
if (unlikely(len)) {
DEBUG_NET_WARN_ON_ONCE(1);
/* Don't hand the caller a buffer with stale bytes in it. */
- if (len > 0)
- memset(to, 0, len);
+ memset(to, 0, len);
return -EFAULT;
}
out:
@@ -3748,9 +3747,10 @@ static noinline int skb_copy_and_csum_frag_list(const struct sk_buff *skb,
* @len: number of bytes to copy
* @csump: where to store the checksum of the copied bytes
*
- * Return: 0 on success, or -EFAULT if @skb has unreadable frags or runs
- * out before @len does. On failure *@csump is not set and the part of
- * @to that couldn't be filled is zeroed.
+ * Return: 0 on success, -EINVAL if @len is negative, or -EFAULT if @skb
+ * has unreadable frags or runs out before @len does. On failure *@csump
+ * is not set. On -EFAULT the part of @to that couldn't be filled is
+ * zeroed, and on -EINVAL @to is not touched.
*/
int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
u8 *to, int len, __wsum *csump)
@@ -3760,6 +3760,14 @@ int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
int pos = 0;
__wsum csum = 0;
+ /* Everything below clamps its copy to @len, so a negative one would
+ * turn into a huge copy.
+ */
+ if (unlikely(len < 0)) {
+ DEBUG_NET_WARN_ON_ONCE(1);
+ return -EINVAL;
+ }
+
/* Copy header. */
if (copy > 0) {
if (copy > len)
@@ -3775,8 +3783,7 @@ int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
if (!skb_frags_readable(skb)) {
/* Don't hand the caller a buffer with stale bytes in it. */
- if (len > 0)
- memset(to, 0, len);
+ memset(to, 0, len);
return -EFAULT;
}
--
2.55.0
Technical Details
Message-ID:
<20261104-b4-skbuff-bug-on-followups-v4-10-b7ffeb364f5d@toxicpanda.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356921-linux-kernel-netdev=dewy.ruReferences:
<20261104-b4-skbuff-bug-on-followups-v4-0-b7ffeb364f5d@toxicpanda.com>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-356921-linux-kernel-netdev=dewy.ru
From: josef@toxicpanda.com (Josef Bacik)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v4 10/15] net: skbuff: reject a negative length in
skb_copy_and_csum_bits()
Date: Wed, 04 Nov 2026 20:47:22 +0000
Organization: Usenet Network
Message-ID: <20261104-b4-skbuff-bug-on-followups-v4-10-b7ffeb364f5d@toxicpanda.com>
References: <20261104-b4-skbuff-bug-on-followups-v4-0-b7ffeb364f5d@toxicpanda.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="3499973"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zBxUqRGbLDZx5HRcDqGF24oK824= sha256:7Muypat4rcwXdxRQlw5efydIHzJexxqmGFXfnV1hIgU=
sha1:9HpPYyIahPm3g5DYhfe6JXVLkHs= sha256:D19gozmdb0+ypLOCgxARFPTr6ToqF4mVv6HttUL9oAk=
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 A7909112DB5; Thu, 5 Nov 2026 01:11:50 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-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,
URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=toxicpanda.com
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 leyeuKprHeuv;
Thu, 5 Nov 2026 01:11:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-356921-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=toxicpanda.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 1EC51112DB2; Thu, 5 Nov 2026 01:11:38 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 88B1A644480; Wed, 4 Nov 2026 21:26:02 +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=1793825283;
b=A6DjaGheuV5h34/HavhZUmLXFZBv+4N2Z/J8zw0isgJYEYOwcmwsSMklgZHB4BPEdjr9
9aEtPcSjM9xjZy4Meg8WreGN17mu7MYxYJ4BzhOLpwK4dN7GWxT7fODbduX8lbILHzEfa
y/2IT3YRHkbqOAfFSeKgFNWBRiEWBiJuH8dotdCM87nJyy7OmCGz44HCPAFDtMgeJgKeJ
dHV+4Lv0+lxxlWNmKCfIzBIJvFpQe9WqNTTaQ5ZxzDg6MTeQE7rMICreVhrbjYi5bbyIV
jIVYLI/FU766ufWb8NAsHli/VucFFHttJsQuQbkemZVq0ICcSVx7dn6+CndEomIHJCA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793825283;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received: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:References:In-Reply-To:To:Cc:X-Mailer:
X-Developer-Signature:X-Developer-Key;
bh=PP/fidHZYkfblatQP/IijP74GKPYKHpT3ch7DoXcS4E=;
b=BGrjegRph4nHdyGBUStkK5/6rW6EjkfC48/Muw/b1jkAWFabGh5HzOs3LCn9fpD75SmV
81xRCI+kLilnmhTaRvEo8I4LdZyv5GQv2lSHg0FXDgmdPO4CFPTPPglYaxxf4Wtx5Rnxy
f0spFEQ7wDb6l0lpVOK3dQsFgTEuKxyA/0ptBtZsPmplK66qhM/6tI8gn38U328quq8CL
t/hFutSgOvg98bS6tnsN0NJO2OCWiSFKKI2Eh5ZeVbamll4hjnTUZ3l66/9dnyhQyhJaW
d4BWqXeRvq0qvHExF16FjyMoioRtc87dVF0z5R3Yp4DSvjldN5QfmQZL/eRU+qyYXvA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=UDyEGERo;
dmarc=none header.from=toxicpanda.com;
spf=pass smtp.mailfrom=toxicpanda.com;
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 D45A06097642;
Wed, 4 Nov 2026 20:48:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=UDyEGERo
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.173
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793825283;
b=ps1jF6ubdyel7EoItVWLm32k0S7x+agOOfKS5gJ4G3pfOF20JYSZ+So8uzvTO2jmb7H6
LbJYhrJpEO8OYrgyqAa72Ar/Vp/3aSPFDzYHvwzFu5MO8C+dNR3mOe9F2bzf70v2hi9Dr
7+pj9MpuQvsmMmdAql32iDSPBRPKAGcV1+imLZUwKo1hcUQ15AZq+2Cj9H1ZfZMGUt47n
7IuoYhTh2H5eE1oFDP0N534PMm8+vShA4jbyHZ5TFuTvmjKPqTSxOVParvYPh1STKv1V2
wcwj91ZePrcQSa/7D9vDgr6AgNIhHlX+QlhmfKqRf7Da/mhvX5I8AFu6RP1F5qbxVgw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793825283;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:
Message-Id:References:In-Reply-To:To:Cc:X-Mailer:
X-Developer-Signature:X-Developer-Key;
bh=PP/fidHZYkfblatQP/IijP74GKPYKHpT3ch7DoXcS4E=;
b=R3gRQw9oyrRFk0cG3HgOCHD4LrCQrJdnDQ3bmpvLdnYRD2JRbAYMNLEp9LIrFGtZ0wCx
VacyRDJSZYDIEaO5sLCjlBvAiFPuo8aGUrEO8LFSIGFrQ1d+3rlhB/4JGuIkxswcZ9GRv
A25utsXDGAa9AWx68eJ5pOEV8vVRL2pcj2m+Rr6iJJsfDtGGJQzjV3vVhjEw+ZKhPW9wT
nwRnA2nZS/O89GVU2Kk9lKZ/UuX9EKwuL36rrSNSXvpT9COan39xE+vlaRsrXT3G1REx1
IWmfSVNSw5y3DTpvCo+E7To95bBkD71SNpDocJqYO9LdGdrCah7txWsY3HpWvSU0w2A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=none header.from=toxicpanda.com;
spf=pass smtp.mailfrom=toxicpanda.com;
dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=UDyEGERo;
arc=none smtp.remote-ip=209.85.222.173
X-Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id A320860A6F4C
for <netdev@vger.kernel.org>; Wed, 4 Nov 2026 20:48:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A320860A6F4C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com
X-Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-93f22a8515eso113948385a.2
for <netdev@vger.kernel.org>; Wed, 04 Nov 2026 12:48:02 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=toxicpanda.com; s=google; t=1793825281; x=1794430081; darn=vger.kernel.org;
h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
:content-type:mime-version:subject:date:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=PP/fidHZYkfblatQP/IijP74GKPYKHpT3ch7DoXcS4E=;
b=UDyEGERoLdfOCtbRBl6mhF5vCiTIPKKkkFvAlPeTb2DdgsEnpcpTayfj6MjlmyZmjn
Kai/ZGN3HzOxK7Srkd3tvU+hruGw0Vi7J8GgLGlY1b12s7meMpdQpOyrg+nsXEEzqFeo
ohuYvTQ3CpXd4RZtZUQfpGjCVjQbHFmuxAbaBWnvj6b3W32zgSbnkFi+AVOpHaJuTtsN
36fKlKeaVA0NhT2G4upI9o1wpHtekeKWvjT0xNxSJrI/DnMY+WgToX4BXC4kZJvX1w0c
oeR+ZY3mcj2uycKHuhlPayrYSmQvCYTa1weiU4w0dkXeTWxXICY3CWppgw5GHyurUI35
mx8w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793825281; x=1794430081;
h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
:content-type:mime-version:subject:date:from:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=PP/fidHZYkfblatQP/IijP74GKPYKHpT3ch7DoXcS4E=;
b=yw0P3od/NCj1W8dQys/VjUzTlNNRP+9bfgXJTT+OYVetI7e7GgM4jjfR+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yC1YCdvkKbY36cT/MlvhkgoD2CncqII+puNfgtGzzlWVxzF3J+oCzxTWaT5f2Z
qCOz6BbRnWMQOmg/Z7ReOsi0Xb8k5ejqVTF+/BP5v1b5HQ==
X-Received: by 2002:a05:620a:2b8b:b0:93f:2941:6b8d with SMTP id af79cd13be357-94421581808mr2833471185a.6.1793825281522;
Wed, 04 Nov 2026 12:48:01 -0800 (PST)
X-Received: from toxicpanda.com ([153.61.196.245])
by smtp.gmail.com with ESMTPSA id af79cd13be357-945d468f69asm294179385a.1.2026.11.04.12.48.00
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 04 Nov 2026 12:48:01 -0800 (PST)
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-In-Reply-To: <20261104-b4-skbuff-bug-on-followups-v4-0-b7ffeb364f5d@toxicpanda.com>
X-Cc: Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Fernando Fernandez Mancera <fmancera@suse.de>,
Mina Almasry <almasrymina@google.com>,
David Laight <david.laight.linux@gmail.com>, netdev@vger.kernel.org,
xen-devel@lists.xenproject.org, Josef Bacik <josef@toxicpanda.com>
X-Mailer: b4 0.15.2
X-Developer-Signature: v=1; a=openssh-sha256; t=1793825269; l=2784;
i=josef@toxicpanda.com; h=from:subject:message-id;
bh=wThWIHnCxUs0o2n1wKVOZp8MJH+DkfwjLDuEZ2TxA3k=;
b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG
JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA
QFsB+WUd2uViaXOb0v3E8Fyx/YypTY3hkcuEnhwIIaLSj1kGnyibicHErE4iRl1Wqf0Tvo/bwuX
fykUuqyoPQgk=
X-Developer-Key: i=josef@toxicpanda.com; a=openssh;
fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA