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=1796158404; b=uH0oLwfdqra5X0K67mputzsPv40cDghybb5EBAyDk8nAsIJ2pomFxXevx7OrlTNzsCZZ h8J3/Oe7OFqwtZ6V21bRJ5sm/NZ/lkOPrBedA05KfWizJeTo30HVoZN1SA4pmDwHPI/EH 0CDA4yxAZYnLvquNNSBDsULAmpTqpt7WY6f8ca85VhHuzXW6D7zYcLSGaPvRn3mLaH4UU L8SxfE7kg2CxhDAEDvXDr/hOrXRqM+39Nt6eEyaKg/TqXJQDXBzJqumpXLyyIj9vrCBQh /KTKzUmULcaXjcTuxsEXU0uEORoXlUjTU2pUkyRPOuZLTM+9UBHR13LdyditQ5nM5kA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796158404; 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=jU+GUZ85jE+LXVO8KWUtIABmnYHfqMMnEtsIyWZkt/w=; b=OkOvYT8tO5PlYguV0g21IrziflbI+mSYGUAHEdCNP7adiTNpn0OG0lkdlcDzSycO1IG1 smi5jXKayls0zOP48yr8xbx34lZ94/d1mjr88myq6Se8UxjxMtC/6fig91kDSOmPxaE8n C6545eGHAHZdo53Ih54Z9sxF9tXMO2patCSodUqKXUMsA1ntOdIhgigFH22cxobXSWPC0 cL64PMzodGFXs4aygs959Klw2xdA80AMFZlgPfKwHOd8TO6qpW7efp+V26Z9AX0X3GKrI WvCQq+BxL4niMMBUR3LCNXGoQSbbDVC3vT6FjIQOGs9snX4xxo9l6YTKZzneXGqG0Ag== 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=PnnCdqKu; 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 1A606606A31A; Tue, 1 Dec 2026 20:53:24 +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=PnnCdqKu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7065D1F000C1; Tue, 1 Dec 2026 20:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796158403; bh=jU+GUZ85jE+LXVO8KWUtIABmnYHfqMMnEtsIyWZkt/w=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=PnnCdqKu+2BFgKvNkWzWnSlfkjDPyEAg0annC2FmVakeyVQ03aIc02DwEYxry0aYc xTPwQE9Oxs73wEpSIp3ywP48bzolpDhWJQMUiKO4vdA2fmBSyBCTApM4bmkwZkeJJQ WJbA4WarE8B8HRZ9MCrLTvW0W2fpit9/VXa7WpgjvX4KqmZsym2HYUGE+Bb6D5UeiQ rCOqRVMhY3nLF+mJUN6kiXd0tIgRw4MiasyfH2DDBG3gnL3fJtBCMRgMWV7a7wENoV QxxF/7F4KJ1MCOQxO5me/EVzqiK/XHGaeQTi5zBXvbTb/QdhqTPUJgbgB0l/+FOffE 4bwXhiPrWncpw== Subject: Re: [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails From: netdev-bot+sashiko@kernel.org To: mkl@pengutronix.de Cc: mailhol@kernel.org, pfink@christ-es.de, eric@evenchick.com, max@schneidersoft.net, wg@grandegger.com, kernel@pengutronix.de, linux-can@vger.kernel.org, stable@vger.kernel.org, kuba@kernel.org Date: Tue, 01 Dec 2026 20:53:23 +0000 Message-ID: <179615840300.3142.4259286558647803230@kernel.org> In-Reply-To: <20261130-gs_usb-fixes-v11-2-3f052bb620d4@pengutronix.de> References: <20261130-gs_usb-fixes-v11-2-3f052bb620d4@pengutronix.de> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-can@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 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] In drivers/net/can/usb/gs_usb.c, this patch moves the gs_update_state() call in gs_usb_receive_bulk_callback() ahead of… -- can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails This patch moves the CAN error frame state check in gs_usb_receive_bulk_callback() ahead of alloc_can_skb(), so state updates are not lost when the skb allocation fails. gs_update_state() now takes the raw struct gs_host_frame instead of a struct can_frame. > diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c > index 965151ab50a1e..0c65db9bbd30f 100644 > --- a/drivers/net/can/usb/gs_usb.c > +++ b/drivers/net/can/usb/gs_usb.c > @@ -495,23 +495,23 @@ static void gs_usb_timestamp_stop(struct gs_usb *parent) > cancel_delayed_work_sync(&parent->timestamp); > } > > -static void gs_update_state(struct gs_can *dev, struct can_frame *cf) > +static void gs_update_state(struct gs_can *dev, const struct gs_host_frame *hf) > { [ ... ] > - } else if (cf->can_id & CAN_ERR_CRTL) { > - if ((cf->data[1] & CAN_ERR_CRTL_TX_WARNING) || > - (cf->data[1] & CAN_ERR_CRTL_RX_WARNING)) { > + } else if (hf->can_id & cpu_to_le32(CAN_ERR_CRTL)) { > + if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_WARNING) || > + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_WARNING)) { > dev->can.state = CAN_STATE_ERROR_WARNING; > can_stats->error_warning++; > - } else if ((cf->data[1] & CAN_ERR_CRTL_TX_PASSIVE) || > - (cf->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) { > + } else if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_PASSIVE) || > + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) { > dev->can.state = CAN_STATE_ERROR_PASSIVE; > can_stats->error_passive++; > } else { [Severity: Medium] Can gs_update_state() now read a byte of hf->classic_can->data[] that the device never sent? Before this patch, data[1] came from the can_frame. alloc_can_skb() zero-fills that frame with skb_put_zero(), and then only data_length bytes were copied in: memcpy(cf->data, hf->classic_can->data, data_length); For an error frame with can_dlc <= 1, or with CAN_RTR_FLAG set (data_length == 0), cf->data[1] was therefore 0. A CAN_ERR_CRTL frame then fell through to CAN_STATE_ERROR_ACTIVE. Now gs_update_state() reads the byte directly from the URB transfer buffer. Without GS_CAN_FEATURE_HW_TIMESTAMP, gs_usb_get_minimum_rx_length() only requires the header plus data_length bytes: if (hf->echo_id == GS_HOST_FRAME_ECHO_ID_RX && !(hf->can_id & cpu_to_le32(CAN_RTR_FLAG))) data_length = can_cc_dlc2len(hf->can_dlc); ... else minimum_length = sizeof(hf->header) + data_length; So a short error frame passes validation even though data[1] was never transferred. gs_can_open() allocates the RX buffer without zeroing it: buf = kmalloc(dev->parent->hf_size_rx, GFP_KERNEL); The buffer is then reused on every resubmit. On the first completion, data[1] would be uninitialized heap memory. After that, it would be a stale byte from an earlier transfer. Could this set dev->can.state to CAN_STATE_ERROR_WARNING or CAN_STATE_ERROR_PASSIVE, and increment error_warning or error_passive, based on leftover buffer contents? The frame passed to userspace would still have data[1] == 0, so the driver state and the reported frame would disagree. The same applies when the device sends all 8 bytes with a low DLC. The state would come from bytes the DLC marks as invalid, while userspace sees them zeroed. Would it make sense to pass data_length into gs_update_state()? Another option is something like: u8 d1 = data_length > 1 ? hf->classic_can->data[1] : 0; and then test d1 instead. This code does not seem to change later in the series either. [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4%40pengutronix.de