πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26601

Re: [PATCH net-next 20/23] can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID

#26601
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 23:12
134 lines
12529 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] With args[] zero-initialized, pcan_usb_get_can_channel_id()
  (drivers/net/can/usb/peak_usb/pcan_usb.c) returns success with…

Pre-existing issues:
- [Medium] PCAN-USB Pro has the same disconnect-window leak, in
  pcan_usb_pro_get_can_channel_id()…
- [Medium] At this commit, pcan_usb_set_can_channel_id() and
  pcan_usb_set_bittiming() (drivers/net/can/usb/peak_usb/pcan_usb.c)…

--

can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID

This patch zero-initializes the args[] array in
pcan_usb_get_can_channel_id(). When pcan_usb_wait_rsp() returns success
without talking to a disconnected device, a null channel ID is now
returned instead of an uninitialized stack byte.

Link: https://patch.msgid.link/20261126-canfd_check_channel_idx-v9-11-abe0099b4585@peak-system.fr

> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
> index ff19217790656..83cf6fe7d258b 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
> @@ -386,7 +386,7 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number)
>   */
>  static int pcan_usb_get_can_channel_id(struct peak_usb_device *dev, u32 *can_ch_id)
>  {
> -	u8 args[PCAN_USB_CMD_ARGS_LEN];
> +	u8 args[PCAN_USB_CMD_ARGS_LEN] = {};

[Severity: Low]
With args[] zeroed, pcan_usb_get_can_channel_id() now reports success with
*can_ch_id = 0 whenever pcan_usb_wait_rsp() skips the USB exchange:

pcan_usb_wait_rsp() {
	/* usb device unregistered? */
	if (!test_bit(PCAN_USB_STATE_CONNECTED, &dev->state))
		return 0;
	...
}

peak_usb_stop_rx() clears PCAN_USB_STATE_CONNECTED before
peak_usb_disconnect() calls unregister_candev(). In that window,
peak_usb_get_eeprom() would return 0 to userspace and write 0 over
dev->can_channel_id.

In the same window, peak_usb_set_eeprom() would merge the user bytes into
this made-up 0 and cache the result. Meanwhile pcan_usb_send_cmd() skips
the flash write without reporting it.

The commit message says the null ID is intentional. Returning 0 for an
unplugged device is also a long-standing convention in this driver, and
the cached value is freed with the device shortly afterwards.

Would returning -ENODEV for a disconnected device be cleaner here than
reporting a successful read of ID 0?

>  	int err;
>  
>  	err = pcan_usb_wait_rsp(dev, PCAN_USB_CMD_DEVID, PCAN_USB_GET, args);

[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. Does
PCAN-USB Pro have the same disconnect-window leak in
pcan_usb_pro_get_can_channel_id() in pcan_usb_pro.c?

The request is built without the u32 dev_num argument:

pcan_usb_pro_get_can_channel_id() {
	...
	pcan_msg_add_rec(&um, PCAN_USBPRO_GETDEVID, dev->ctrl_idx);
	...
}

However, the GETDEVID case in pcan_msg_add_rec() still reads that
argument:

	case PCAN_USBPRO_GETDEVID:
	case PCAN_USBPRO_SETDEVID:
		*pc++ = va_arg(ap, int);
		pc += 2;
		*(__le32 *)pc = cpu_to_le32(va_arg(ap, u32));

Once PCAN_USB_STATE_CONNECTED is cleared, pcan_usb_pro_send_cmd() and
pcan_usb_pro_wait_rsp() both return 0 without any transfer. pdn->dev_num
still holds the indeterminate value written into the request in
dev->cmd_buf, and it is returned as the channel ID.

peak_usb_get_eeprom() then copies that value to userspace and caches it
in dev->can_channel_id.

Reaching this needs CAP_NET_ADMIN for ETHTOOL_GEEPROM, and the window is
narrow. A later commit in the series fixes it: "can: peak_usb: pass the
dev_num argument of PCAN-USB Pro GETDEVID" changes the call to pass 0 as
dev_num.

[Severity: Medium]
This isn't a bug introduced by this patch, but pcan_usb_set_can_channel_id()
and pcan_usb_set_bittiming() in the same file still declare args[] without
an initializer:

pcan_usb_set_can_channel_id() {
	u8 args[PCAN_USB_CMD_ARGS_LEN];
	...
	args[0] = can_ch_id;
	return pcan_usb_send_cmd(dev, PCAN_USB_CMD_DEVID, PCAN_USB_SET, args);
}

pcan_usb_set_bittiming() {
	u8 args[PCAN_USB_CMD_ARGS_LEN];
	...
	args[0] = btr1;
	args[1] = btr0;
	...
}

pcan_usb_send_cmd() copies all PCAN_USB_CMD_ARGS_LEN bytes into
dev->cmd_buf before usb_bulk_msg(). Doesn't that send 12 or 13
uninitialized kernel stack bytes to the device?

A later commit in the series fixes this: "can: peak_usb: don't send
uninitialized stack bytes to PCAN-USB devices" changes both declarations
to = {}.

-- 
Sashiko AI review Β· https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202230853.2665144-2-mkl%40pengutronix.de
Technical Details
Message-ID: <179633953988.3146.5292238485083319887@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376901-linux-kernel-netdev=dewy.ru
References: <20261202230853.2665144-21-mkl@pengutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376901-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 20/23] can: peak_usb: don't return an
 uninitialized PCAN-USB CAN channel ID
Date: Thu, 03 Dec 2026 23:12:19 +0000
Organization: Usenet Network
Message-ID: <179633953988.3146.5292238485083319887@kernel.org>
References: <20261202230853.2665144-21-mkl@pengutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2624907"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:XHg7VgiKUXI56yntP82ruYMPM6U= sha256:JjJz2b/OT85VaY96S1BQ+RKQ2Zpl31L7pGSfcSnu/Xc=
	sha1:dWdBQEmHjsnFFmVxx9KAwJ6iiTQ= sha256:x69IoYic1ScPbmNBQhM8lwDoN1WWVQ7XAD5b5pWiFIA=
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 30D76117A32; Fri,  4 Dec 2026 02:12:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.74
X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org
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 7nUR2A1SfUP6;
	Fri,  4 Dec 2026 02:12:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-376901-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 2322B117A5C; Fri,  4 Dec 2026 02:12:23 +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 38F796019FC; Thu,  3 Dec 2026 23:12:22 +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=1796339541;
	b=2iNzAimwVKPciVuMfPyqVUneX+kJAxqKJu0vEYWRg/j7k+IgTig/GgFih/yw8EWDm7k9
	 Kv17UYUammpqvAEvE+BbrhMVdfNtuMIrsK+/X156E5S+gyP2gDmB8K5IdC/3pcYA4bEHh
	 uc34wma49agiG2ADWb2vqurcUCqyUsVpHuB2tNMpTfNU65roqfP+fOLDVemodhGbQIcga
	 TFYWTsBlV4nhw5aSX3O+AWpG9fbUObugGAEk+k6TslSyzR+/H/mvtQutrNq8336XAwMpW
	 H4IThZy/Jaeg898xKB+kYEldmvDsF5ATFAeSpqIU6JwgPx72DtxRzqRY1jrMrJ4D8iQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796339541;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=OU3Zv4B8HCwON0PegQ2rU9N59Bem9krPnapK5OnOLcM=;
	b=JGbiMU18IFnuMvj6/E1IA16NRYoJA+CG+kjevOuTFHsUKSxNJ04YWaJtWqaCnoqUhqbj
	 XF5tFYnI9IVGKn/8/diof9fydtRG7te0Au69/hjSwXyXjosWSS4jLx3DcBnIZd2puwqjV
	 nvjUvL3k9kDevukTJuWt4LWXEbHHhWlsqhCqxSD0ymf4Fsw+1wf6Fp4Mrcl8Ws9vKrTnE
	 gwmGaQBi14SZPVM4Wmglv0RuAQVnwcxug45SZCTHHH9kt/+5o5ZhtYK62rXwYocSHQU9Q
	 9wwirTAymK4HpUBFIzwar3uZDNlKIYvTADgxBN9NFTc5ZZGVdYcGxU5nlxnTpxxNUJQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="MxxJTB/B";
	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 B0E7B606A336;
	Thu,  3 Dec 2026 23:12:21 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MxxJTB/B
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796339540;
	b=yhCFSIFngzx71d0O+PpgMZTH+1zINo7+9pWzjCVr2qN/hsulXpFbyq3Rx+604ob3xKE8
	 4PbP4txgmRuZgruP7hBSGte7Lz50kRnnKTV4fjA9T94zY8mCNW1FXBC057aIxqRGV5nAo
	 HLe+uqCultesG2h4kKYHyR/y6gsKcp9tnCTK29VAtztwDtULacnUyco/x4Hg5rah8EjJO
	 m/UYTDAOJW/QQTgO/WBQ0lpQVJpUsjyC4QnX2qzconr1yYX5xar/IY9JubpaOnSZ6EpHo
	 7A1qB/rDDmXsKAXEpCkan9Qd6QCWVOAx8je1FODkmHSLDVnAUfyQLdAkj8LD67M7pcQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796339540;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=OU3Zv4B8HCwON0PegQ2rU9N59Bem9krPnapK5OnOLcM=;
	b=mPmRFh61xu+kJXWgwSOF69DFvOn4YjnCOMM3eth8vM8t0I/MT3BlOp99F55sUv+IBMJT
	 S8Ty6GJsx+XtWBkmpnIQ+v2TMV0HVAeHGoDmhWSl7pUSwphUgGCxQmUYJQHqP2AXpSdKv
	 dJ/V+j7hNl8zSVnHWrC0n4qBAON0g8ehe6YiHsNjwpd+jV0gR64PJlNRbhOMNjrl+M6iK
	 fBPPZ6ciwgKn9DJIR2gsTVvNMZ1mXp95e1bMdQ0dtvI0u5PXjPi68FIpes8MXeJ2KisDU
	 +ndupjL/qdmGmzUNVWyxNpu1HYuwCZ5w+l/EyUsE8khuxPAz1CFCW3mO5wAC/YgKadw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="MxxJTB/B";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(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 D4583606A335;
	Thu,  3 Dec 2026 23:12:20 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 504C81F0092B;
	Thu,  3 Dec 2026 23:12:20 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796339540;
	bh=OU3Zv4B8HCwON0PegQ2rU9N59Bem9krPnapK5OnOLcM=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=MxxJTB/BSEz5NGToX+iRoTx0IcRNfUwxezIaNirVP6b1BgR/TDfD6jAgA4T+Vene7
	 L4yTPTn4OliAj8CUNWJt3dtDIqptDx+hAPYiZO+ku4Oc7EK8XtzClExyR+SiZXK2xZ
	 m9rnO1eantWstvtWCB/XUlSLJFiLtXZSL2i2d8UhUTdChOOjfu6X8IwoZ6JLEdeo1o
	 Tg1wb4PQOUMXsbIaYwydqu2X6LYWe5C+dWpejYEn29fjVt6op0v5g98ip0AI3iX/At
	 bh+CaiWe0hcsrhY4QHNv+/kLIhlE9GS/x0GLfuHVsDoWmdU3md6TGts/fv12h77UgX
	 QCC00xwWvx8IQ==
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
 linux-can@vger.kernel.org, kernel@pengutronix.de, s.grosjean@peak-system.fr,
 stable@vger.kernel.org
X-In-Reply-To: <20261202230853.2665144-21-mkl@pengutronix.de>
X-sashiko-severity: Low
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