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=1796024744; b=RBOPreZz2YJRW51h4T5KF6M1GN2kLv2RlK9kmDyGvIMuzasYaBl+nhYk+05Kef1tvwtK cSwvuqR8c+r3IKENtR/roy0fin7WzYeeqa+Gh3yvvbkfb/sFt4kP7FJd3NWkt7+p0aQV8 QjURhEWTB2GEk/ldWIxG6G2cxTSoMfFdkqxtKgfPW72Ijj/yN1W47ZU5tE+VLlVjtFCDd x/mElx7Kap7c6ZjRXBdXW2zUwcGQVgjUe1DvfbBSNuG3zqJ9O6ycNLsP6iSzvtByrpNkZ HYpK70/WSO8umE6UBy0Fa/kApCOHLO4ezceC8GOBVKAV9Jqegj04AGiZfL03ifBxqIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796024744; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=S/Tyi0TO/Luqr4y5Cb92CirttTewsGVDbeKkwkZ/LkQ=; b=r0LBj6AmM0I50EXe3DI6tZba3a5nzLXtEE+HYDKl/uyJGE9SxVJ+pSYcBlI9EEmr3sAV /Vj/24ScSDeGQx/G2MJGII6ljiBsAm10J8Aq/Wt3aSKvM+9YN0GTGHwO1jezK8/q9vjZA 2bejbPBn7N79ajQ0R+DtomRsdFabaO6bEpKnPHawj7xNMnLFqVioep4fWWJMswxb9jucT MHmk2iE+/JfT3uHOa4eRwSSh/QTX/2TN4n9FNwRy0EjiPQph55Xsd7AiM2whglrbMB2QV pNVn7yLfJ4rIjuuXLngT7Jrh+dK433BFRPlcErNVob0Cb3VZxU+pi5T5Yr0AQyN9E0g== 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=heVFQ5+a; 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 C7BA4606A31C for ; Mon, 30 Nov 2026 07:45:44 +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=heVFQ5+a Received: by smtp.kernel.org (Postfix) with ESMTPSA id 277531F00897; Mon, 30 Nov 2026 07:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796024744; bh=S/Tyi0TO/Luqr4y5Cb92CirttTewsGVDbeKkwkZ/LkQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=heVFQ5+aDCHWjemC5yZd3km/ytcQz5UCflCsGQ3oOTLWDNRxhNviTygyqwswJXWf8 bGvwEmdyx4CFf9i0h07OKPb07PmT7z6GbvKNRjQvhgLAnZNrv2Zh4utGPw1nTyWagj RFq7cfChPx7wImZju6NrWaAL+GEK2Y9HC2EcdsSjEaPHJZyfUONhzzQaYeQBGweR16 WxxNoy0l7UYt3F36jM85Lb5xhBPkVde6zNAnEmJ8r1rTuq9RNV58gh05BDFIyDxHfL +47O8mFJ7sMe/Bx2GtUa3gc+ba24VBi6luTyL1EZxlcDAdvP0BvlFEGDKzhCeovthY 8Hsb0kN5nZ0xw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails Reply-To: sashiko-reviews@lists.linux.dev To: "Marc Kleine-Budde" Cc: linux-can@vger.kernel.org, "Oliver Hartkopp" , "Vincent Mailhol" , "Oleksij Rempel" In-Reply-To: <20261130-gs_usb-fixes-v11-2-3f052bb620d4@pengutronix.de> References: <20261130-gs_usb-fixes-v11-0-3f052bb620d4@pengutronix.de> <20261130-gs_usb-fixes-v11-2-3f052bb620d4@pengutronix.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 07:45:43 +0000 X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] can: gs_usb: unvalidated data[1] read in gs_update_state() on short frames -- commit 30fc2459f9b225604427254c1421d65c0b0fa7b1 Author: Marc Kleine-Budde can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB alloc= ations fails This commit moves gs_update_state() before alloc_can_skb() in gs_usb_receive_bulk_callback() and changes it to read directly from struct gs_host_frame so CAN state updates are not lost if skb allocation fails. > 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 *pa= rent) > cancel_delayed_work_sync(&parent->timestamp); > } > =20 > -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_fra= me *hf) > { > struct can_device_stats *can_stats =3D &dev->can.can_stats; > =20 > - if (cf->can_id & CAN_ERR_RESTARTED) { > + if (hf->can_id & cpu_to_le32(CAN_ERR_RESTARTED)) { > dev->can.state =3D CAN_STATE_ERROR_ACTIVE; > can_stats->restarts++; > - } else if (cf->can_id & CAN_ERR_BUSOFF) { > + } else if (hf->can_id & cpu_to_le32(CAN_ERR_BUSOFF)) { > dev->can.state =3D CAN_STATE_BUS_OFF; > can_stats->bus_off++; > - } 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 =3D 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 =3D CAN_STATE_ERROR_PASSIVE; > can_stats->error_passive++; > } else { > @@ -685,6 +685,10 @@ static void gs_usb_receive_bulk_callback(struct urb = *urb) > =20 > memcpy(cfd->data, hf->canfd->data, data_length); > } else { > + /* ERROR frames tell us information about the controller */ > + if (hf->can_id & cpu_to_le32(CAN_ERR_FLAG)) > + gs_update_state(dev, hf); [Severity: Medium] Can gs_update_state() read uninitialized or stale memory from hf->classic_can->data[1] when a short error frame is received? Previously, alloc_can_skb() zeroed cf via skb_put_zero() and only data_length validated bytes were copied into cf->data. Because gs_usb_get_minimum_rx_length() allows classic CAN frames with data_length < 2 (when hf->can_dlc < 2 or CAN_RTR_FLAG is set), and RX URB buffers are allocated with kmalloc() in gs_can_open() and reused across transfers, reading hf->classic_can->data[1] directly without checking data_length >=3D 2 can inspect uninitialized or leftover payload bytes and misupdate dev->can.state and can_stats. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-gs_usb-fix= es-v11-0-3f052bb620d4@pengutronix.de?part=3D2