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=1796170935; b=ukhB+SAAIaEKJP9QhrnypsnMCwfG57C28UqeeAs7U/BPx3DYNajEe6q9IXNIxyMQSMWU RyRWYX8/asgYbvMYQsQus++885YcPjwRFJWBxsjVD0r5EB+msEry5gBXELzblH2TmB1xf KxoctBTApYW31ZWKfPxN2aBLAIVcSsp1dT7MwFmJmxHE5sfIbP6vEyGMTI9wre/K1ZZ0x BVXy+2hSxTA8DIbTqMsUNttCBXfvMBvAvv936gXdc8EY9eryk+Z3TnL6GPko6w6CmaBCo LWeEnA6NZ/nULxesL8DNZR01/uH6Pf2sPSpNvMCpp2iAFAXrLV3fmhO8B/S2V5XfDBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796170935; 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=CgPJi0FhTVvP/nBwhYXaRDDaEz7tNPgzLKSV7TZgg4I=; b=I+2K/d6cZnSchO6eaYXcLv2Ih/de+/LqtilOFp1Ub6oyvndy0oJT6onZnUI6mnuGv9cB TsLTJQ+6gRu5EgdDeRPiA24z5A1YEL7eAYBcDcVcuGxvARDL+y0G3oivIX9yT1Sx+VCwa MNMSvLkh+QYN3mgDhT6oiFflRaZKCN5cB0oxuTcYWXGJ332wEFkg4naIo3/bk5pjS4QCR vHf5oqUXO+UwpgMbg9CuFpTdARtzysVHbxvo6AKa7HFjq68Z7rxSzRgaHCsFzNqoSwocf 6gkzsfOBtj3Aa1OLX4juziWBdkj5yBA16/CEl8K2R0J1YULEcTaB7QTX6dXI1bsszcA== 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=fGQ7BGR5; 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 D8F88606A322; Wed, 2 Dec 2026 00:22:15 +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=fGQ7BGR5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD15A1F00896; Wed, 2 Dec 2026 00:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796170935; bh=CgPJi0FhTVvP/nBwhYXaRDDaEz7tNPgzLKSV7TZgg4I=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fGQ7BGR5y/ncTYjD+HMEji5VjGNzJFIX+8BAorgXSHIOgrChcqliHYtCyIKnofhrj ehyyfPNimNYis8A9VBYrJ7eS0UocH7zepHXckRqP/JjIoz+4w6tPWeg9MMmiWcsBH8 3N2+OZ0rGXEsLm9T4jw0pBfM7b9NCgyP7gnHAySR8K5SCfwYCsyookmVYMeczRbzsk BWYKZj4OwFPnH2GN1gfpI4vRrA07vPR8OcCllmNQ+hwSs+BvGVnWqQiEGlIDL59PQm R9pzKuJv4Yek2oR5dxGjUP4RYtYG/gCShxi+u+rxCaRVciE3lBjM3pStJ1LlbOqn6i MQoO5NUSbU/Kw== Subject: Re: [PATCH can v5] can: j1939: reject an out-of-range data packet offset From: netdev-bot+sashiko@kernel.org To: piyus@iiitd.ac.in Cc: robin@protonic.nl, o.rempel@pengutronix.de, socketcan@hartkopp.net, mkl@pengutronix.de, linux-can@vger.kernel.org, kernel@pengutronix.de, linux-kernel@vger.kernel.org, kapil@presceralabs.ai, kuba@kernel.org Date: Wed, 02 Dec 2026 00:22:14 +0000 Message-ID: <179617093429.3142.3648486850669011953@kernel.org> In-Reply-To: <20261130105233.2512536-1-piyus@iiitd.ac.in> References: <20261130105233.2512536-1-piyus@iiitd.ac.in> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@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 7 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 1 · Low: 5 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). - [High] The new WAITING_ABORT guard in j1939_xtp_rx_dpo_one() (line 1846) turns a sequence that used to clean itself up into a permanently… - [Medium] In j1939_xtp_rx_dpo_one() (net/can/j1939/transport.c), the out-of-range DPO branch leaves the abort rxtimer armed on a session it… - [Low] The new range check in j1939_xtp_rx_dpo_one() also runs on transmit sessions, and the commit message does not say so. - [Low] The commit message says that, even with the range check, j1939_session_completed() takes the message from the window named by… - [Low] The new comment in j1939_xtp_rx_eoma_one() (line 1421) and the commit message give, as a reason to leave a cancelled session to the… - [Low] Both new guards, j1939_xtp_rx_dpo_one() line 1846 and j1939_xtp_rx_eoma_one() line 1421, test `session->state >=… - [Low] The new `session->state >= J1939_SESSION_WAITING_ABORT` guards in j1939_xtp_rx_dpo_one() (line 1846) and j1939_xtp_rx_eoma_one() (line… -- can: j1939: reject an out-of-range data packet offset This patch makes j1939_xtp_rx_dpo_one() reject an ETP DPO whose offset is not below session->pkt.total. Such a session is aborted with J1939_XTP_ABORT_BAD_EDPO_OFFSET and then force-deactivated. The patch also makes j1939_xtp_rx_dpo_one() and j1939_xtp_rx_eoma_one() ignore frames for sessions that are already waiting for their abort. Link: https://lore.kernel.org/all/sashiko-outbox-240339@kernel.org/ > - j1939_session_completed() still takes the message from the window the > peer's last DPO named, because j1939_session_skb_get() returns > j1939_session_skb_get_by_offset(session, session->pkt.dpo * 7). With > the check above the offset is in range, so there is an skb there, but > for a multi-block ETP transfer it is not the start of the message. > That is its own fix and follows separately. [Severity: Low] Is this accurate for the receive path? j1939_session_completed() only calls j1939_session_skb_get() when !session->transmission. A receive session has one skb that covers the whole message. It is allocated in j1939_session_fresh_new(): skb = alloc_skb(size, GFP_ATOMIC); ... skb_put_zero(skb, size); That skb's skcb is copied from the RTS. j1939_can_recv() zeroes the RTS cb, so skcb->offset is 0. j1939_session_skb_queue() is only called from the tx path in socket.c, so a receive session never holds more than that one skb. With dpo < pkt.total, dpo * 7 is below the message size. That means j1939_session_skb_get_by_offset() always returns the single skb, and it starts at message offset 0. So once this check is in, doesn't multi-block ETP completion already deliver the whole message? If so, the promised follow-up has nothing to fix. > 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 *session, struct sk_buff *skb) > > netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session); > > + if (session->state >= 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. > + */ [Severity: Low] Is the "queue a second RX_ABORT" part of this reasoning right? j1939_session_completed() doesn't queue RX_ABORT itself. The second one comes from j1939_session_destroy() when the last reference drops, because j1939_session_cancel() has already set session->err: } else if (session->err) { j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT); } The abort path this defers to (j1939_tp_rxtimer() in WAITING_ABORT -> j1939_session_deactivate_activate_next()) also reaches j1939_session_destroy() with err set. It queues the same second RX_ABORT. So does the new out-of-range DPO path in j1939_xtp_rx_dpo_one(). Only the "hand its data to the receiving sockets" half seems to apply. Could the comment and the commit message be adjusted? > + if (net_ratelimit()) > + netdev_info(session->priv->ndev, > + "%s: 0x%p: EOMA on a cancelled session\n", > + __func__, session); > + return; > + } [Severity: Low] This guard, and the matching one in j1939_xtp_rx_dpo_one(), tests >= J1939_SESSION_WAITING_ABORT. In enum j1939_session_state, both J1939_SESSION_ACTIVE_MAX and J1939_SESSION_DONE sort above WAITING_ABORT. j1939_session_deactivate_locked() sets DONE on any deactivation, including normal completion. A DPO or EOMA handler holds a reference taken under the list lock. It can therefore see a session that another CPU deactivated after the lookup. In that case the comment and the "cancelled session" log messages say the session was cancelled when it was not. Returning early is still correct for DONE. Should the comment and log text describe the broader condition? > session->pkt.tx_acked = session->pkt.total; > j1939_session_timers_cancel(session); > /* transmitted without problems */ > @@ -1823,14 +1836,50 @@ static void j1939_xtp_rx_dpo_one(struct j1939_session *session, > struct sk_buff *skb) > { > const u8 *dat = skb->data; > + unsigned int dpo; > > if (j1939_xtp_rx_cmd_bad_pgn(session, skb)) > return; > > netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session); > > + if (session->state >= 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; > + } [Severity: High] Can this early return strand a receive session permanently? Take an ETP receive session where the peer's DPO arrives just after the 1250 ms rx timeout. By then j1939_tp_rxtimer() has moved the session to WAITING_ABORT and armed the 500 ms abort timer. last_cmd is still J1939_ETP_CMD_CTS, or J1939_ETP_CMD_RTS if no CTS went out. With this patch the DPO returns here. last_cmd is not updated and the timer is left as it is. WAITING_ABORT sessions stay on active_session_list, so the ETP.DT frames that follow still find the session. In j1939_xtp_rx_dat_one() the stale last_cmd hits the default case: switch (session->last_cmd) { case 0xff: break; case J1939_ETP_CMD_DPO: if (skcb->addr.type == J1939_ETP) break; ... default: ... goto out_session_cancel; and then: out_session_cancel: kfree_skb(se_skb); j1939_session_timers_cancel(session); j1939_session_cancel(session, abort); j1939_session_timers_cancel() cancels the abort timer, which was the only thing left that would deactivate the session. j1939_session_cancel() does nothing in WAITING_ABORT. The session then sits on the active list with no timers. It holds its receive skb, its netdev reference and a priv reference. The new EOMA guard also removes completion as a way out. The commit message names this stranding as the problem the forced deactivation is meant to prevent. Before this patch, the same DPO set last_cmd to DPO and re-armed the rxtimer. The DTs then passed the switch, and j1939_tp_rxtimer() eventually deactivated the session. Receive sessions have sk == NULL, so j1939_sk_release() won't match them. Once the last j1939 socket on the interface closes, __j1939_rx_release() unregisters the CAN receiver and clears the priv. After that, neither RX nor j1939_netdev_notify() can reach the session. Could unregister_netdevice() then wait forever on that netdev reference? The out_session_cancel pattern in j1939_xtp_rx_dat_one() and j1939_xtp_rx_cts_one() was already there, but this guard adds a new route into it. Would it help to force deactivation here, or to handle WAITING_ABORT in out_session_cancel or j1939_session_cancel()? [Severity: Low] This state check, and the one in j1939_xtp_rx_eoma_one(), reads session->state without priv->active_session_list_lock. Every writer of session->state holds that lock. One of them is j1939_tp_rxtimer(), an HRTIMER_MODE_REL_SOFT timer that can run on another CPU while this RX softirq is in progress: j1939_session_list_lock(session->priv); if (session->state >= J1939_SESSION_ACTIVE && session->state < J1939_SESSION_ACTIVE_MAX) { ... __j1939_session_cancel(session, J1939_XTP_ABORT_TIMEOUT); } j1939_session_list_unlock(session->priv); Suppose the guard sees ACTIVE and j1939_tp_rxtimer() cancels the session right after. The DPO path still sets pkt.dpo and last_cmd. It then replaces the abort timer with j1939_tp_set_rxtimeout(session, 750) and queues RX_DPO after RX_ABORT. On the EOMA side, j1939_session_completed() can still deliver the data of a session that has just been aborted. These are the outcomes the guards are meant to prevent. The commit message also lists, as a benefit, removing a state sample that "raced with j1939_tp_rxtimer() setting WAITING_ABORT in between". Would reading the state and acting on it under j1939_session_list_lock() close this window? > + > + dpo = j1939_etp_ctl_to_packet(dat); > + if (dpo >= session->pkt.total) { [Severity: Low] This check also runs on transmit sessions, because j1939_tp_cmd_recv() passes the local node's own echoed DPO through j1939_xtp_rx_dpo(priv, skb, true). Is that intended? The transmitter takes its offset from j1939_session_tx_dpo(): session->pkt.dpo = session->pkt.tx_acked; and tx_acked comes from the peer's CTS in j1939_xtp_rx_cts_one(), with no check against pkt.total: /* set packet counters only when not CTS(0) */ session->pkt.tx_acked = pkt - 1; So a peer CTS with a next-packet value beyond pkt.total makes the local node send an out-of-range DPO. When that DPO loops back, this check aborts the transmit session with J1939_XTP_ABORT_BAD_EDPO_OFFSET and the sending socket gets EPROTO. The abort reason on the bus then blames the DPO the local node sent. The real fault is the peer's CTS, which J1939_XTP_ABORT_ECTS_TOO_BIG would describe. The missing CTS validation predates this patch. The transmit-side behaviour is new, though, and the commit message doesn't mention it. Should it? > + 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 [ ... ] > + j1939_session_deactivate_activate_next(session); > + return; > + } [Severity: Medium] Does this leave the abort rxtimer armed on a session that has already been deactivated? For an ACTIVE session, j1939_session_cancel() arms the abort timer and takes a session reference: if (session->state >= 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 sets the state to DONE and removes the session from the active list. It does not cancel that timer. j1939_xtp_rx_rts_session_active(), which the comment cites, calls j1939_session_timers_cancel() again before its forced deactivation. Because the session is no longer on the active list, j1939_cancel_active_session() on NETDEV_DOWN or NETDEV_UNREGISTER cannot cancel the timer. The receive skb, netdev and priv references stay held for up to J1939_XTP_ABORT_TIMEOUT_MS. When the timer fires, the state is DONE rather than WAITING_ABORT, so j1939_tp_rxtimer() takes its final else branch. Nothing is re-armed, but this still runs: if (!session->sk) j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT); j1939_session_destroy() then queues one more because session->err is set. Doesn't that make three RX_ABORT notifications for one rejected DPO? Would calling j1939_session_rxtimer_cancel() between j1939_session_cancel() and the forced deactivation fix both effects? > > /* transmitted without problems */ > - session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data); > + session->pkt.dpo = dpo; [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130105233.2512536-1-piyus%40iiitd.ac.in