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=1796036799; b=24c4cgFISY6smzm82UxRv7j9gs4xP3Gk4Fyv2hyAgqffAo0Xv3KZOEUpqm1Q2lKVX/yA HlzbVUhvNtC7CYehmBATq8L34sArbLU6Wg5U0yhYX3Q0iWg10q3QPC+FMaUO4+/TJP7d7 o6fzJmMbYDDhLujoLADm+udqnL72mL4yBqkdUULEnf0MolOXnkq4RyxKWWvbXDF4+ssY1 MVH+ZcBtEImOWdhz9qNguz3L/091vITr6zkuP+p1hOUkfmBzjqMBu0U2VL4Ie5ui6A3P9 rQ9k/63Ih391ehQkle7p9rl0XfpyPiWU0N26hH2UmdWup0FOFyoWoghcuoCGxuCLwyg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796036799; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/O300b24OaNr5YqwQ+dZrhOOjrJ27cMjPNVEzqGFj2k=; b=K3paYY1aoXDMjbPcCkdR/PGCFWB8PTvklbSPzVRg9V8r/Rntvzmtj7Hrh4gDvPsTECIU rrbWCAz5SKLwatxvANzWrtRK5yUPPJmAiMgvLm5yTI89j7Gw6gQ74+7VPnNYRZkO1KRd+ NDR9zSenJ5kjJjplQ0M+vRAAFOVHX2NghUyPdfJsPicdpu/k9t4gYpPVoWF66OEUIiUFy YQy7YHdhjohPrLDpjU6aJgSVcWhw4WtGdNnHjFqKI18rEA7XP2+xNFaVUGqJrp63T6nfF qAZ08xonVcATygxlBWqw5mGtbjVH1MbRjEDlcsHURCOLK60zZL/eMQ+M+ZEx8XZ9dSg== 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=AgSNwZVG; 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 B3057606A31C for ; Mon, 30 Nov 2026 11:06:39 +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=AgSNwZVG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E3041F00896; Mon, 30 Nov 2026 11:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796036799; bh=/O300b24OaNr5YqwQ+dZrhOOjrJ27cMjPNVEzqGFj2k=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=AgSNwZVGsNKvhbiFSx68PfQNIzSSLpUVztLfTLTGXgA6P4DqWSVEjsf5ArxNRv5ZA L+Q3HDTE4J99gjfGzO7tiwArK4icTv1LBVpdI4dc3aX5v+UIzcd37wHNeOFO+8peDZ iD9JkJKFEIblqBcIRkFyAurAKq8q2lDoNBCaXUaLew4gyeycMaVxMk2zUm8AuP+QR3 qgHImyBLxUXAiWdVpa9BfEitZQE8PDuPyrO/Vb2n2x+wWJo2ERw0ADEnKlpO2L9GJ5 EVTHbtdB6OZbLnjBTdL6DNtvMxapO0udhSuFex9XP8EtsNms2dusF4QHyTKko6gcgX vt/b7M+/EC38w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH can v5] can: j1939: reject an out-of-range data packet offset Reply-To: sashiko-reviews@lists.linux.dev To: "Piyus Kedia" , linux-can@vger.kernel.org Cc: "Marc Kleine-Budde" , "Oliver Hartkopp" , "Vincent Mailhol" , "Oleksij Rempel" In-Reply-To: <20261130105233.2512536-1-piyus@iiitd.ac.in> References: <20261130105233.2512536-1-piyus@iiitd.ac.in> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 11:06:38 +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 2 potential issues to consider: - [High] can: j1939: uncancelled abort rxtimer in j1939_xtp_rx_dpo_one() - [Medium] can: j1939: unlocked state check races with j1939_tp_rxtimer() -- commit ba940f757909ea5e7086befe7e0b0d4acb71baf2 Author: Piyus Kedia can: j1939: reject an out-of-range data packet offset This commit validates the data packet offset in j1939_xtp_rx_dpo_one(), aborts and deactivates the session when the offset is out of range, and ignores EOMA and DPO frames arriving on sessions already waiting to abort. Link: https://lore.kernel.org/all/sashiko-outbox-240339@kernel.org/ > diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c > index 8fcfd13e5e6f8..37a253c892328 100644 > --- a/net/can/j1939/transport.c > +++ b/net/can/j1939/transport.c > @@ -1418,6 +1418,19 @@ j1939_xtp_rx_eoma_one(struct j1939_session *sessio= n, struct sk_buff *skb) > =20 > netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session); > =20 > + if (session->state >=3D J1939_SESSION_WAITING_ABORT) { > + /* This session has been cancelled and is waiting for its abort > + * to go out. Completing it here would hand its data to the > + * receiving sockets and queue a second RX_ABORT, so leave it to > + * the abort path. > + */ > + if (net_ratelimit()) > + netdev_info(session->priv->ndev, > + "%s: 0x%p: EOMA on a cancelled session\n", > + __func__, session); > + return; > + } > + > session->pkt.tx_acked =3D session->pkt.total; > j1939_session_timers_cancel(session); > /* transmitted without problems */ [Severity: Medium] Can checking session->state before cancelling session->rxtimer race with j1939_tp_rxtimer() here and in j1939_xtp_rx_dpo_one()? CPU0 CPU1 j1939_xtp_rx_eoma_one() if (session->state >=3D J1939_SESSION_WAITING_ABORT) /* false: state is ACTIVE */ j1939_tp_rxtimer() j1939_session_list_lock(...) hrtimer_start(&session->rxtimer, ..= .) __j1939_session_cancel(session, J1939_XTP_ABORT_TIMEOUT) session->err =3D EHOSTUNREACH session->state =3D J1939_SESSION_WAITING_ABORT j1939_session_list_unlock(...) j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT) j1939_session_timers_cancel(session) j1939_session_completed(session) <-- completes aborted session When j1939_tp_rxtimer() fires between the unlocked state check and j1939_session_timers_cancel(), j1939_xtp_rx_eoma_one() cancels the newly armed abort timer and completes the timed-out session, handing the data to receiving sockets and queuing a second abort notification when j1939_session_destroy() sees session->err set. The same window exists in j1939_xtp_rx_dpo_one() before j1939_tp_set_rxtimeout(), where an in-range DPO re-arms rxtimer to 750 ms and queues J1939_ERRQUEUE_RX_DPO after J1939_ERRQUEUE_RX_ABORT. > @@ -1823,14 +1836,50 @@ static void j1939_xtp_rx_dpo_one(struct j1939_ses= sion *session, > struct sk_buff *skb) > { > const u8 *dat =3D skb->data; > + unsigned int dpo; > =20 > if (j1939_xtp_rx_cmd_bad_pgn(session, skb)) > return; > =20 > netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session); > =20 > + if (session->state >=3D J1939_SESSION_WAITING_ABORT) { > + /* This session has been cancelled and is waiting for its abort > + * to go out. Taking a new offset here would reset its timeout > + * and queue an RX_DPO behind the RX_ABORT already queued, and > + * the data packets that follow would be copied into a session > + * nobody is going to read. Leave it to the abort path. > + */ > + if (net_ratelimit()) > + netdev_info(session->priv->ndev, > + "%s: 0x%p: DPO on a cancelled session\n", > + __func__, session); > + return; > + } > + > + dpo =3D j1939_etp_ctl_to_packet(dat); > + if (dpo >=3D session->pkt.total) { > + netdev_info(session->priv->ndev, > + "%s: 0x%p: data packet offset %u is not below the %u packet(s) of= this session\n", > + __func__, session, dpo, session->pkt.total); > + j1939_session_timers_cancel(session); > + j1939_session_cancel(session, J1939_XTP_ABORT_BAD_EDPO_OFFSET); > + /* Force deactivation, as j1939_xtp_rx_rts_session_active() does > + * for the receiver. The abort frame has already gone out, and > + * an ETP sender does not wait for it: the data packets that > + * follow this DPO reach j1939_xtp_rx_dat_one(), whose last_cmd > + * check takes them to out_session_cancel, which cancels the > + * timers and then calls j1939_session_cancel() - a no-op on a > + * session already in WAITING_ABORT. That would strand this > + * session on the active list with no timers, holding its skb > + * and netdev references for good. > + */ > + j1939_session_deactivate_activate_next(session); > + return; > + } [Severity: High] Does calling j1939_session_cancel() after j1939_session_timers_cancel() leave session->rxtimer armed on the deactivated session? Because session->state is J1939_SESSION_ACTIVE here, j1939_session_cancel() starts session->rxtimer for J1939_XTP_ABORT_TIMEOUT_MS: net/can/j1939/transport.c:j1939_session_cancel() { ... if (session->state >=3D J1939_SESSION_ACTIVE && session->state < J1939_SESSION_WAITING_ABORT) { j1939_tp_set_rxtimeout(session, J1939_XTP_ABORT_TIMEOUT_MS); __j1939_session_cancel(session, err); } ... } j1939_session_deactivate_activate_next() then unlinks the session from priv->active_session_list and sets session->state to J1939_SESSION_DONE while session->rxtimer is still running. Neither the looped-back abort frame in j1939_xtp_rx_abort_one() nor teardown in j1939_cancel_active_session() can find the unlinked session to cancel the timer, and when session->rxtimer expires 500 ms later, j1939_tp_rxtimer() sees J1939_SESSION_DONE instead of J1939_SESSION_WAITING_ABORT, enters the else branch, and queues a duplicate J1939_ERRQUEUE_RX_ABORT before final session destruction queues another. Cancelling the timers after j1939_session_cancel() (as j1939_xtp_rx_rts_session_active() does before deactivating) would avoid leaving the abort timer active. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130105233.2512= 536-1-piyus@iiitd.ac.in?part=3D1