🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26021

[PATCH net-next 17/23] can: peak_usb: validate the data length of PCAN-USB Pro CAN records

#26021
From: Marc Kleine-Budde
Date: Wed, 02 Dec 2026 23:04
69 lines
12988 bytes
From: Stéphane Grosjean <s.grosjean@peak-system.fr>

The PCAN-USB Pro decoder takes the data length of a received CAN frame
from the 4-bit DLC field of the record, i.e. 0 to 15, and copies that
many bytes from the record into can_frame->data. This length is checked
neither against CAN_MAX_DLEN nor against the size of the record, which
depends on its type: RXMSG8, RXMSG4 and RXMSG0/RXRTR records carry 8, 4
and 0 data bytes. pcan_usb_pro_decode_buf() only checks that the record
fits in the URB, according to its type.

A faulty or malicious device can therefore make the driver:
- copy bytes located beyond the record into the frame, i.e. stale bytes
  of the RX buffer or, when the record ends the 1024-byte buffer, bytes
  beyond it, and deliver them to the CAN sockets;
- write up to 7 bytes past can_frame->data[] with a DLC of 9 to 15;
- deliver an RTR frame whose len is greater than CAN_MAX_DLEN.

Convert the DLC with can_cc_dlc2len() and reject a data frame whose
length exceeds the number of data bytes of its record type, as the
other malformed records are.

Found by Sashiko AI review.

Fixes: d8a199355f8f ("can: usb: PEAK-System Technik PCAN-USB Pro specific part")
Cc: stable@vger.kernel.org
Signed-off-by: Stéphane Grosjean <s.grosjean@peak-system.fr>
Link: https://patch.msgid.link/20261126-canfd_check_channel_idx-v9-8-abe0099b4585@peak-system.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
index 9e2f48683a9d..38307d452a5a 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
@@ -534,6 +534,7 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,
 				      struct pcan_usb_pro_rxmsg *rx)
 {
 	const unsigned int ctrl_idx = (rx->len >> 4) & 0x0f;
+	const u8 len = can_cc_dlc2len(rx->len & 0x0f);
 	struct peak_usb_device *dev;
 	struct net_device *netdev;
 	struct can_frame *can_frame;
@@ -543,6 +544,12 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,
 	if (ctrl_idx >= ARRAY_SIZE(usb_if->dev))
 		return -EINVAL;
 
+	/* the number of data bytes depends on the record type */
+	if (!(rx->flags & PCAN_USBPRO_RTR) &&
+	    len > pcan_usb_pro_sizeof_rec[rx->data_type] -
+		  offsetof(struct pcan_usb_pro_rxmsg, data))
+		return -EINVAL;
+
 	dev = READ_ONCE(usb_if->dev[ctrl_idx]);
 
 	/* reject records for a channel that is not (or no longer) set up */
@@ -556,7 +563,7 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,
 		return -ENOMEM;
 
 	can_frame->can_id = le32_to_cpu(rx->id);
-	can_frame->len = rx->len & 0x0f;
+	can_frame->len = len;
 
 	if (rx->flags & PCAN_USBPRO_EXT)
 		can_frame->can_id |= CAN_EFF_FLAG;
-- 
2.53.0
Technical Details
Message-ID: <20261202230853.2665144-18-mkl@pengutronix.de>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376117-linux-kernel-netdev=dewy.ru
References: <20261202230853.2665144-1-mkl@pengutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376117-linux-kernel-netdev=dewy.ru
From: mkl@pengutronix.de (Marc Kleine-Budde)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 17/23] can: peak_usb: validate the data length of PCAN-USB Pro CAN records
Date: Thu,  3 Dec 2026 00:04:42 +0100
Organization: Usenet Network
Message-ID: <20261202230853.2665144-18-mkl@pengutronix.de>
References: <20261202230853.2665144-1-mkl@pengutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2084844"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7ICX+hwAYtt6hoogDe/KX/5oocE= sha256:lyiC239Q+gf7RxKovSgQcWrqKwk3mmYFNS21sEPpIlE=
	sha1:jI6i33qPy80I//nggyocXT2YgCA= sha256:WFZuDFkytNkgqocXB6jDczyyIvrVgaySxl25Mc4Syt0=
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 2458A11778E; Thu,  3 Dec 2026 02:10:37 +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.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=pengutronix.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 f3R2-3RxLns7;
	Thu,  3 Dec 2026 02:10:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376117-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E99B011773F; Thu,  3 Dec 2026 02:10:24 +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 40F5E2A86F; Wed,  2 Dec 2026 23:10:21 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796253021;
	b=sgv5HBOlhhQQjy6qPWCCmdW4J7kznjSO3qVAzbCVgSmHa1zR64uVJjL+XaOuqPxatxyW
	 n3hGIqgagvKPK4GhSxnXIiO0GiUCEjeegUV1YYdSgSRPiiUd9rQv8nrIggf99UMSQh6FW
	 mNuLsEecBrMlvv28iWuxFNyeeyBHOlap7nkBaadx5WzhdnJ0P3XmfnxlaPPuM1L0p8RiS
	 77SyhAJ16x653/FJqobrbKmKSWS75QShZT/3gv/QM3sekmECw2YwvzbV9FFlz9Gw4kg92
	 nHV6zhbW/NbLDGCsidxjoz0gOhiVp+cjVtMiM5pjARl5IVyBaIT4GNrLs1/Q6kt4gBA==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796253021;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=0kKzJ52bouFlTWNxN7p/vcAIQ8zGEFrnn6ugbjvkeG8=;
	b=y9AMjXUetkoc65ALZtAVDEeFeezuQcHNhnRN7Gu1rjzmNc15AsSW9NNjBhEAnDs8pRDq
	 GvVBe6VorOulgwK9X7+0OQwsmmZAe6AHIAN1RmHdls6/29H3qyjzgEJSSEPg4NLfUPF7+
	 kHXzb2Fpw4O0FbxpH9Rqx9BI1qmLER7RViBYopUY93A/UC92ZEbvXqEgZlyxVcrFa3f6P
	 LZmN635X0e5RibOxMBlHWZv5g0Jpd/tkHleRwXPIW2MkmKvlFatKXNspH9mOhVgAtdbdl
	 mR1YZ5Rn8xySetcIFfnk+xYYxGwfnxjZbzO5qJmKZzIkHav4Sg1q4sTup/cBC1TXMYQ==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=J60EUBRe;
	dmarc=none header.from=pengutronix.de;
	spf=pass smtp.mailfrom=pengutronix.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 18CBE606A337;
	Wed,  2 Dec 2026 23:10:21 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=J60EUBRe
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796253020;
	b=LeZQHNgSsGzKr2upQ2iBl12ixc1v0AtyzOzDq1bc7UXk6CiUEJFINrDKxibsvvUJW/Wy
	 YCgBsHvEHVxNNpOtI2rtKLdQtTJMbjr8KkyNFdOnnkHm7NEP+5n3qjioD4M/teW3RTgAl
	 KZnROvjdpc6JqgqIWB6oerVKrg+3iiXTbMWfBCwn6a/EIMRDj3JJYFTxGYpO+C+3lxd6n
	 WNS4gQe3OXbAB7+9Lso5Nj/nIiaaV8TOATLZ5UVc18NZh52jcURV1qe+8C3WhQjgRN+Mn
	 sRy6eI7DGx9+BzJkZw4PssFVsFY2jLnYCUyTEbXqBa/wGO1O8ejMKL2MB1ImVicTpcQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796253020;
	h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=0kKzJ52bouFlTWNxN7p/vcAIQ8zGEFrnn6ugbjvkeG8=;
	b=13VOEBDqEn54+cFOclicxwxzNO02YAWw/g1T1A7MVaNXBeKq/rKmTZC3q5dFvmevRVW4
	 G2pfcU7Ce/5L1cEttjR4/QESggRpg5NxTF3F7cNkxvJ3Yn/VMjV+nTg/isH08Ce4yNZIm
	 qVyCtQccXfFBNtJAUzFljF+HFLZMGdViTGjROk44t96QZKuuAMTLaTp4fe6qDQ7CEriHE
	 6g/WKuwGeDSPSoy2IyUta2fXKreuJwdn1wkXNW7NpfNYxCgmGiuYYg6MPDR2fDCquk0S5
	 Y4UkicjC4r1jcdbjxCUl79AJg6JQDGa2D/CrkJAR5qIkH+8mx64g3o7rgtvO39HWm4w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=pengutronix.de;
	spf=pass smtp.mailfrom=pengutronix.de;
	dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=J60EUBRe;
	arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13
X-Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13])
	(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 B030A606A32D;
	Wed,  2 Dec 2026 23:10:19 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B030A606A32D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de
X-Received: from pengutronix.de (unknown [IPv6:2a0e:1580:1000::2dff:fe0e:e982])
	(Authenticated sender: mkl@pengutronix.de)
	by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id B9216205BD6;
	Thu, 03 Dec 2026 00:10:13 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1796253013;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=0kKzJ52bouFlTWNxN7p/vcAIQ8zGEFrnn6ugbjvkeG8=;
	b=J60EUBRev6TZujhIuXivj6/SRCe1HhRPQdJSQ8gw8gJppFGX+P2C7qD/Zzj3OTPjXcFdm+
	l5gfZkk46h5zZ9r8R6SWarJjFipQ2QO56bQbP7WjpAlx4xahr8N3VL5je2eUjyexTmrzbR
	x1YwPXDYxqatGd7M8em4FoBveHU+9iN35lI8+1VWIl9Hu4Z3vvPB2aUDSiIDfytQwtao3k
	JDejT81a6c4zoGWr76c/KXhhOejcCleO5XSEPlXXXQ6pdTTca4CAfsHjbb/IGsikED/cAL
	Z5ON+qre3fqd4yPyyWxF14drvibbS4at/CdfnRs9lsfXjwiuHZY1B+lKuJmc2g==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1796253013;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=0kKzJ52bouFlTWNxN7p/vcAIQ8zGEFrnn6ugbjvkeG8=;
	b=Pk9LV4kfEkWiUDM8HWVgu31QiICB5ZB7G7DgW2lv1QdbdTJRNnWrnjA7rrLt2BuQ6jDzge
	d5JbLEZTpWNeaaSvjUC3jyXbSRk2py4orJ1t9nDoGVFjkb2of+ky/GqK5shBSpF/4jy1A2
	TuoHIzYYMHhNR3PvIsUedWDM7NmJLT3ld8n7Tg7LqWgZg/t8aFgXBdGBwznbtfs8QkBu66
	ehn7acCynzNFVBbUOVjgFr2WVdFrAylB+qSJhRjbu2+HN0QcyYo+BFFfVkkxrw86dbmfrw
	4i495l1mYBvezZGH5kHnIvQyeJ8c/UjxiaI8bliThWmQE9U1eX/ThByHNkc2Mw==
X-ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1796253013; a=rsa-sha256;
	cv=none;
	b=MbiXp6e/iqzASI+yLlYLtqKcfd4IsOeRJLGi3AKlImZS+V6f+wdVsPhhY3BzfMlHS+plTM
	JIzV/m6aR4pnaknwe8eiIiQ96k5aY0R0lcRt3/qtT4e7UD39HfWsI3/+S8nE9EPwgWnRI1
	f/It4kk90CwEEHwj37wmZvtoB1yAIOFIh2Uqwzuua4de4w3+1NAx1fIpTeeuOFnQ6vjSbE
	/nfseSEq9+PpncUKcwQiCexH2GmMKKAzyGhd3sug8S0pgWIFHKkY2kX5E76/qVznnSUexg
	Jm8MRKxDCiRUqhNLdtDAyCfHr724XrODlvUVDFY12EtvJ4TTAP0V7Y3V/BKDYg==
X-ARC-Authentication-Results: i=1;
	ORIGINATING;
	auth=pass smtp.auth=mkl@pengutronix.de smtp.mailfrom=mkl@pengutronix.de
X-Cc: davem@davemloft.net,
	kuba@kernel.org,
	linux-can@vger.kernel.org,
	kernel@pengutronix.de,
	Stéphane Grosjean <s.grosjean@peak-system.fr>,
	stable@vger.kernel.org,
	Marc Kleine-Budde <mkl@pengutronix.de>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261202230853.2665144-1-mkl@pengutronix.de>
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