From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 504C81F0092B; Thu, 3 Dec 2026 23:12:20 +0000 (UTC) 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== Subject: Re: [PATCH net-next 20/23] can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID From: netdev-bot+sashiko@kernel.org To: mkl@pengutronix.de 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 Date: Thu, 03 Dec 2026 23:12:19 +0000 Message-ID: <179633953988.3146.5292238485083319887@kernel.org> In-Reply-To: <20261202230853.2665144-21-mkl@pengutronix.de> References: <20261202230853.2665144-21-mkl@pengutronix.de> X-sashiko-severity: Low Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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