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=1796147227; b=hB5swFgGWyJzR0ka7AIsL1MZjNlHEWOmKi/14Da+09DMbvfBd8ZbKUpyiUiN4Pjm9Lbe +HGLKF26XXKwiAgHXxislaAKhiXNRdQgFH+tyBj13Ja6njhoDJ+CS1SLle5Qo1ZCnQcQn 5kYMQnehCCiLH7fz3LIBOi/p9k0iszuRGuo6z9mhETuRJ+wuv6tPz+S6U8m/N1F5//Szc f6J9D4gYyOIvC0z8c3cIuLgacWq/XMjxxp/bx4OnkPvysY3gHEJZ51ENkkF/vPCr5O8V1 ykQUpoyK0fP3Vj0RktNrzrrBOCQaDF9Wk4RTNz43c67QQMsOUuMPEzHTbibh68M6jHQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147227; 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=qY5Apem8mksxK7dPMnUcl37lssYPLLzGvtxNictF9XA=; b=uT0UjaUn3xUX42kQfL/Zos9PJZwoQDxjZ02azXulPBnHIEK5Qwljj7UgVFXjT9hczbIP xxmj+v9l0InDVXFjurIYaYdqnIZKYbl/xOYfJy3IvCeBMZhrgEtr8xdinaX1EKABXmD99 DNHg5toyjrPHSAO96IvTYxaBggRNieezH25qe0WegZ5x09uAwxphOrj6oQOMcCNjpHufO iotq+WzjnjIpnv6aWQO0sKlPWyNVm3rRCW4cmn8ZoQrAq9dwnDgzVv5ku9hGqOCW1m/Wn 0tuR9eGK/Naq0vjlH6b3IV+jeIR/6e20qYndAsQRspRB4rGvmC7YBjOBWrXnY7yzE8Q== 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=QJ8ZRc7P; 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 9DD57606A329; Tue, 1 Dec 2026 17:47:07 +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=QJ8ZRc7P Received: by smtp.kernel.org (Postfix) with ESMTPSA id 803111F00899; Tue, 1 Dec 2026 17:47:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796147227; bh=qY5Apem8mksxK7dPMnUcl37lssYPLLzGvtxNictF9XA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=QJ8ZRc7P96qi7kpwHC2/hq/2xI9VRFSXB3ecpkJY4r5mbQxj1kZLXwafEOXTkiic9 zF5KBXNOakz3FkSWGwRte+hyFRiGQSBmlPmBBfb7tTAvhl5OYdNw08x4zfTKyB4wM6 TNHNzUxrPMXAvYlG48XEDCvsa7tMXaG255PXJXzIMuDkRuIlIMQC5EIwrbToSQ4l0x Ovnt1WeIP34146a2M8Jq3k/rZ0O8X0Rv56/WbAreOxmn1rLlc96Kjgw3Uj7277WHe2 E8nKYSUjm7A/T8av3jWJqmF+fn3DJsVeaNWmrTVUeuplKkGeunL1H1j7QxlwXvmA0Q 5SDHSh1SuK55Q== Subject: Re: [PATCH net v4 2/2] 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: Tue, 01 Dec 2026 17:47:06 +0000 Message-ID: <179614722601.3142.6142667587633925470@kernel.org> In-Reply-To: <20261130033422.2143435-3-piyus@iiitd.ac.in> References: <20261130033422.2143435-3-piyus@iiitd.ac.in> X-sashiko-severity: High 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 5 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 2 · Low: 2 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] Once the new DPO rejection has aborted a session, the next data frame leaves that session stuck on the active list with no timers. - [Medium] In the new out-of-range DPO path of j1939_xtp_rx_dpo_one() (transport.c:1858), `was_dying = session->state >=… - [Medium] Parts of the new comments and the commit message do not match the code. - [Low] j1939_xtp_rx_dpo_one() (transport.c:1864) aborts an out-of-range DPO with J1939_XTP_ABORT_FAULT. - [Low] The new guard in j1939_xtp_rx_eoma_one() (transport.c:1432) reads session->state without active_session_list_lock, and nothing re-checks… -- can: j1939: reject an out-of-range data packet offset This patch rejects an ETP DPO whose data packet offset is not below session->pkt.total and aborts the session. A receive session is now completed from offset 0. An EOMA that arrives for a session already in WAITING_ABORT no longer completes it, and a session that gets a second out-of-range DPO while already aborting is deactivated directly. > diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c > index fa30273df3263..187a7e6849eb6 100644 > --- a/net/can/j1939/transport.c > +++ b/net/can/j1939/transport.c [ ... ] > @@ -1426,6 +1429,18 @@ 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: Medium] This comment says that completing a cancelled session here would "queue a second RX_ABORT". Is that accurate for receive sessions? __j1939_session_cancel() always sets session->err. j1939_session_destroy() queues RX_ABORT whenever err is set: net/can/j1939/transport.c:j1939_session_destroy() { ... } else if (session->err) { j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT); } ... } So destroy queues the same single RX_ABORT in both cases: when j1939_session_completed() deactivates the session, and when the WAITING_ABORT branch of j1939_tp_rxtimer() does. For receive sessions, the guard seems to change only whether the data is passed to j1939_sk_recv(). On a related point, the new comment in j1939_xtp_rx_dpo_one() says j1939_session_cancel() "is a no-op once the state is WAITING_ABORT". However, the was_dying path still calls it, and this part runs outside the state check: if (!session->sk) j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT); session->sk is only set in j1939_tp_send(). For a receive session, would a second out-of-range DPO then queue an extra RX_ABORT to subscribed sockets? Also, j1939_tp_cmd_recv() calls j1939_xtp_rx_eoma() with transmitter=true for a peer's EOMA: if (j1939_tp_im_receiver(skcb)) j1939_xtp_rx_eoma(priv, skb, true); So this guard also skips completion for transmit sessions in WAITING_ABORT. Those sessions are now deactivated, and the next queued session activated, only when the J1939_XTP_ABORT_TIMEOUT_MS abort timer fires. If that timer has been cancelled, it never happens. Is that intended? The commit message only describes the receive case. Could the comments and the commit message be updated to match what the code does? [Severity: Low] This state check runs without active_session_list_lock. Nothing re-checks the state before j1939_session_timers_cancel() and j1939_session_completed(). What happens if j1939_tp_rxtimer() runs on another CPU just after the check? CPU0 CPU1 j1939_xtp_rx_eoma_one() state < WAITING_ABORT, continue j1939_tp_rxtimer() hrtimer_start(rxtimer, abort) __j1939_session_cancel() state = WAITING_ABORT j1939_session_timers_cancel() cancels the abort timer j1939_session_completed() j1939_sk_recv() Can a receive session then still be delivered to the sockets after its abort has already gone out on the bus? The "second RX_ABORT" part does not apply, since j1939_session_destroy() queues RX_ABORT on both paths. The session is still deactivated, so this only means the guard is not airtight. > + netdev_info(session->priv->ndev, > + "%s: 0x%p: EOMA on a cancelled session\n", > + __func__, session); > + return; > + } > + [ ... ] > @@ -1831,14 +1846,36 @@ 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); > > + dpo = j1939_etp_ctl_to_packet(dat); > + if (dpo >= session->pkt.total) { > + bool was_dying = session->state >= J1939_SESSION_WAITING_ABORT; [Severity: Medium] was_dying is read without active_session_list_lock and before the timers are cancelled. Can it be stale by the time j1939_session_cancel() runs? CPU0 CPU1 j1939_xtp_rx_dpo_one() was_dying = false netdev_info(...) j1939_tp_rxtimer() j1939_session_get() hrtimer_start(rxtimer, abort) __j1939_session_cancel() state = WAITING_ABORT j1939_session_timers_cancel() hrtimer_cancel() waits for CPU1, then dequeues the abort timer j1939_session_cancel() no-op, state is WAITING_ABORT if (was_dying) not taken The session would then stay on the active list in WAITING_ABORT with no timers, still holding its skb and its netdev and priv references. That is the leak the new comment says this branch prevents. j1939_xtp_rx_rts_session_active(), which the comment names as its model, checks the state after calling j1939_session_cancel(), so it does not have this window. > + > + 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_FAULT); [Severity: Low] Should this be J1939_XTP_ABORT_BAD_EDPO_OFFSET? This file describes J1939_XTP_ABORT_FAULT as "Maximal retransmit request limit reached", and j1939_xtp_abort_to_errno() maps it to ENOTRECOVERABLE. The enum already has a code for this exact condition: J1939_XTP_ABORT_BAD_EDPO_OFFSET = 12, /* Bad EDPO offset */ That code maps to EPROTO. As written, both the peer and the ee_errno in the RX_ABORT errqueue message get the generic reason. Separately, the DPO is only checked against pkt.total. It is not checked against the window our CTS requested, and dat[1] is not checked against the CTS packet count, even though J1939_XTP_ABORT_EDPO_OUTOF_CTS exists. The later checks in j1939_xtp_rx_dat_one() keep this memory-safe, so it goes beyond what this commit sets out to do. > + if (was_dying) > + /* j1939_session_cancel() is a no-op once the state is > + * WAITING_ABORT, so it does not restart the timeout > + * cancelled just above. Deactivate instead, as > + * j1939_xtp_rx_rts_session_active() does, or the session > + * stays on the active list with no timers and holds its > + * skb and netdev references for good. > + */ > + j1939_session_deactivate_activate_next(session); > + return; > + } > + > /* transmitted without problems */ > - session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data); > + session->pkt.dpo = dpo; > session->last_cmd = dat[0]; [Severity: High] Can the first ETP data frame after this abort leave the session stranded? The early return above skips the session->last_cmd = dat[0] update. So last_cmd keeps its previous value: ETP_CTS from our own CTS echo, or ETP_RTS. Meanwhile j1939_session_cancel() has moved the session to WAITING_ABORT and armed the abort rxtimer. The sender's next ETP DT frame still finds the session, because j1939_session_get_by_addr_locked() does not filter on state. In j1939_xtp_rx_dat_one() the frame then hits the default case: default: netdev_info(priv->ndev, "%s: 0x%p: last %02x\n", __func__, session, session->last_cmd); goto out_session_cancel; which leads to: out_session_cancel: kfree_skb(se_skb); j1939_session_timers_cancel(session); j1939_session_cancel(session, abort); j1939_session_put(session); j1939_session_timers_cancel() cancels the abort rxtimer. Then j1939_session_cancel() re-arms nothing, because the state is already WAITING_ABORT. Nothing deactivates the session after that, and with the new EOMA guard an EOMA can no longer complete it either. Wouldn't the session then stay on the active list with no timers? It would keep its receive skb, its netdev tracker reference and its priv reference until another RTS arrives from the same address pair, or until NETDEV_DOWN or NETDEV_UNREGISTER. The commit message says both consequences of the abort are handled. This looks handled only for a second DPO, not for the DT frame a sender actually transmits after a DPO. j1939_xtp_rx_cts_one() has the same pattern of cancelling the timers and then calling a cancel that does nothing: out_session_cancel: j1939_session_timers_cancel(session); j1939_session_cancel(session, err); Before this patch, a bad DPO followed by two or more DT frames could already strand the session through this j1939_xtp_rx_dat_one() path. With the patch, a DPO and a single DT frame are enough, and an EOMA can no longer recover the session. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130033422.2143435-1-piyus%40iiitd.ac.in