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=1795894047; b=o7L8xi/Xp4NqQnBeu9SCZFlFHZUJdyeGkjveif/EhEUB5WWfQq4YeU9XwUqBw76hAqg3 GjInCn8WlGhDzBmfiQZ/n7FjlwV/m177xFtog+cmVUTbIDt35+kA0drkQzaYmJvYF0xZe yik/B549VCn/wF2lfCg7+F3BxOEtGDpkGRDoYLsK+pOAL27h2atuiUavRS8NFxe05uMf1 kFLVTe1tp9XHviIhO4aEe6hLFjVUAx+TQ0q4/1V/pX4k9kwsy6vxlaYuYFsE9QEp5RauA f/fmPpic5JGNsoAZ41XCCNGjRomytlsS9yE0ijlsRZFBOUggV9XEFLo7+t0nyhF+7gQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795894047; 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=cSAHE0gyoRNVfJW+r1yI7115HXK85PiC4X6/NSih0es=; b=O+VFpWcfg7eS5kBZbiNpMNx4n0YGDI97cRuXMhpSKZumEbC58BdRfkO7ff3jYWy3cnIS RF6jiIt8miUEb2mUKx3SptJSsQ+2vC5VM40minwdCEtaVxOJj2ZI9Nc8ziGrXXm+lAP/0 w+e0eUiJrUNH+EYmxGxyf5x8cct2luiy4VnDktT7UrEznuRiumy0gv0tQf6UVhsbflKGa PQLYTDVRQLXuGaNbe1TRn8dDhq9lfIdwoeIGc3RQ6xo6RJbraj2uyckZFC2VmpBkyw1p1 dxSJzjNgs5cAOMbF2FtiOlT8WOBsuJ3gPDhpASX6i2YdmggbdGa352UpKuquM/Umy4w== 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="nV9V/Miw"; 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 9CB7A606A31C; Sat, 28 Nov 2026 19:27:27 +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=nV9V/Miw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 996691F000C1; Sat, 28 Nov 2026 19:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795894047; bh=cSAHE0gyoRNVfJW+r1yI7115HXK85PiC4X6/NSih0es=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=nV9V/Miw6pC8HqtLOivkTHaWc/+ojNKhl76qfoyRrEho7vt6Leyy9Iz7gL6i4G1OC +py/2LFyquTv/0mwJcGLN+/KN1vf/KesJ/hP2cbs1xGA/dvgUTDIEldvASRi0VnaRY gIrKrWDMOIPNhvU5hjj8XviAmBI9gI+KZTqH03FlmHqmyLobSZswf6qK9b6WGVrmq3 il7R+mi87mW6KlxUQE1xmzrW2r8xurqCRdtUgs0qaPGpzBXEmjdfb8H+3IYocbbxew kFKeUgkhLj3iWiM7QNx6IVE9Kic2xS4YkeIpmC68KCCxMppJXJSQgTitrVbOM4n2/0 vx6ODWo8OObng== Subject: Re: [PATCH net v2] 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, netdev@vger.kernel.org, kernel@pengutronix.de, linux-kernel@vger.kernel.org, kapil@presceralabs.ai, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, stable@vger.kernel.org Date: Sat, 28 Nov 2026 19:27:26 +0000 Message-ID: <179589404616.3135.8619866704479644293@kernel.org> In-Reply-To: <20261124181757.638280-1-piyus@iiitd.ac.in> References: <20261124181757.638280-1-piyus@iiitd.ac.in> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@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 3 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 1 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 net/can/j1939/transport.c, the new out-of-range check in j1939_xtp_rx_dpo_one() cancels the session with J1939_XTP_ABORT_FAULT. - [Medium] The new reject path in j1939_xtp_rx_dpo_one() calls j1939_session_timers_cancel() and then j1939_session_cancel() without… - [Low] The commit message's reason why rejecting an out-of-range DPO loses nothing is wrong at the boundary. -- 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 pkt.total, and cancel the session when that happens. It also changes j1939_session_completed() to look up the received message at offset 0 instead of at the DPO window. The NULL test stays there as a second guard. Link: https://lore.kernel.org/all/179553126874.3135.14817947057284289051@kernel.org/ > An out-of-range offset has no other legitimate effect either: every data > packet that follows is rejected by the "packet > session->pkt.total" test > in > j1939_xtp_rx_dat_one(), which computes packet from the same dpo, so the > session can never complete with data. [Severity: Low] Does this hold at the boundary? j1939_xtp_rx_dat_one() does: packet = (dat[0] - 1 + session->pkt.dpo); if (packet > session->pkt.total || (session->pkt.rx + 1) > session->pkt.total) { With dpo == total and dat[0] == 1, packet == total passes the > test. The packet is only rejected later, when j1939_session_skb_get_by_offset() returns NULL. With dpo == total and dat[0] == 0 (the sequence number is never checked for zero), packet works out to total - 1. That passes the test, the lookup finds the message skb, and the payload is copied into the last 7-byte slot. The new dpo >= session->pkt.total check closes both cases, so the code itself is fine. Could the commit message describe the bounds check in j1939_xtp_rx_dat_one() more precisely? Accepting sequence number 0 may also be worth a separate look. > diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c > index 8fcfd13e5e6f8..225467843e428 100644 > --- a/net/can/j1939/transport.c > +++ b/net/can/j1939/transport.c [ ... ] > @@ -1823,14 +1828,25 @@ 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) { > + 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: Medium] Is J1939_XTP_ABORT_FAULT the right abort reason here? Its description in enum j1939_xtp_abort is "Maximal retransmit request limit reached", and j1939_xtp_abort_to_errno() maps it to ENOTRECOVERABLE. The file already defines a code for this exact condition, and nothing in net/can/j1939/ uses it yet: J1939_XTP_ABORT_BAD_EDPO_OFFSET = 12, /* Bad EDPO offset */ j1939_xtp_abort_to_errno() maps that one to EPROTO. __j1939_session_cancel() passes the chosen code to the peer and to the error queue: session->err = j1939_xtp_abort_to_errno(priv, err); ... j1939_xtp_tx_abort(priv, &session->skcb, !session->transmission, err, session->skcb.addr.pgn); So the TP.Conn_Abort frame tells the peer reason 5 instead of 12. The J1939_ERRQUEUE_RX_ABORT queued for this receive session reports ENOTRECOVERABLE. Documentation/networking/j1939.rst lists "Invalid PGN or offset in EDPO/ECTS" under EPROTO. It keeps ENOTRECOVERABLE for the retransmit limit. The DPO check in j1939_xtp_rx_cmd_bad_pgn() also uses the specific J1939_XTP_ABORT_BAD_EDPO_PGN. The commit message gives j1939_xtp_rx_dat_one() as the precedent. Its FAULT, though, covers data packet numbers, not EDPO offsets. Would J1939_XTP_ABORT_BAD_EDPO_OFFSET fit better here? [Severity: Medium] Can this path lose the abort timeout? j1939_xtp_rx_dpo() still finds sessions in J1939_SESSION_WAITING_ABORT, because j1939_session_get_by_addr_locked() matches only on address and direction. Suppose a second out-of-range DPO arrives after the first one cancelled the session, but before the echo of our abort frame is processed: first bad DPO j1939_session_timers_cancel() j1939_session_cancel() j1939_tp_set_rxtimeout(session, J1939_XTP_ABORT_TIMEOUT_MS) __j1939_session_cancel() session->state = J1939_SESSION_WAITING_ABORT second bad DPO j1939_session_timers_cancel() <- cancels the abort rxtimer j1939_session_cancel() state < J1939_SESSION_WAITING_ABORT is false, so no re-arm j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT) The WAITING_ABORT branch of j1939_tp_rxtimer() is the only timer-driven cleanup for this session. j1939_xtp_tx_abort() ignores allocation and can_send() failures, so the abort frame may never be sent or echoed. In that case, does the session stay on active_session_list, holding its references and receive skb? It would only go away on a new RTS from the peer, a peer abort, or the interface going down. Each such DPO also queues another J1939_ERRQUEUE_RX_ABORT, because that call in j1939_session_cancel() is unconditional when session->sk is NULL. j1939_xtp_rx_rts_session_active() already works around the same problem for a second RTS: } else if (session->state == J1939_SESSION_WAITING_ABORT) { /* Force deactivation for the receiver. * If we rely on the timer starting in j1939_session_cancel, * a second RTS call here will cancel that timer and fail * to restart it because the state is already WAITING_ABORT. */ j1939_session_deactivate_activate_next(session); } Before this patch, a DPO in this state went through j1939_tp_set_rxtimeout(session, 750), which always re-armed the timer. Does the new path need a similar state check or forced deactivation? > + return; > + } > + [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124181757.638280-1-piyus%40iiitd.ac.in