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=1796010670; b=yxpdlhfZiQemONZVeYbNA1H1gsYkSrDuTsytK8Chdtkw3/ZB+4+/pecdeCiRD3DEAw/M hbmjIBc8TZP3b5R9zc4vRWbI1huhgt4FwH2G7Z/Pa257YYhiHXHuRpDxrVxbgBeMnEsbu pJnNr0zSVzHCfwUc6TBaT14gVgFcQ5dhcemcqnpJILUu7jpHRv8VbU7zoSwq2k4NT8O33 J1sOUe/PKRDx4MbI093Iz/vI1xN1vyDXN3VGVvoqrI/B3gflXxMAGFSqdNw/l1GhQotc7 /nsij3CAnHJF99E6s8mAummgD5OCkPU8Wubh0yVUUkiG9Ip26bWCKAstX82rQHPgmrw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010670; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=7QkBcHHbwIagGJDTHu/vLWlXqcBFJK8NrtdyKwbyo98=; b=E9xC09FQOp3UpFrwVmZifh8J2pd57yp6Me1bHI0A7TJ+akcB+TpO/42ru9OJuFCZe0Fy QgKEgxKXsszxTSX3yYl5Z8AVBs34vTkSolHCsg7SR251i0SfzyOi20SrIvn9uIocAkR9W B6/Y66S1eojZuf+ybxxzzLXlCwhFfPhOP25+vfGeG3PJXDcABtrLnAA91blnYBcyqC/rR km1bwtkBieoSxE1U/pTgeS+UF6nZkHM5OjneR518cNdWU/2+fXt05yTkSMOCnz4/cAP7S y5fqOG26rI5peFqIqFtPaz/rOWLpIScgDLsSf3xxdCJ/YInAl6CmayCT9oh0HN0Ru0w== 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=UqihdsQk; 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 CF7C7606A327 for ; Mon, 30 Nov 2026 03:51:10 +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=UqihdsQk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55CF81F00896; Mon, 30 Nov 2026 03:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796010670; bh=7QkBcHHbwIagGJDTHu/vLWlXqcBFJK8NrtdyKwbyo98=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UqihdsQkUxvmKtPd2rPsWc5zrYyN4IfSPKczffDnTZ7HuFmCMnH4/2doMdhCwC6p+ mp0aGW3LejEWZ6OUlRCWnJiz/zPY7JQQtsOunUTxxdrZFnNJIa+lRbCMfMJOli6fE4 fvz+2TW8XxPbNjAO3pYHjVECFvtvAcu0foFeOIAJmcwt+np2vY0yQqT15TNn+aPT4/ wL4XGIN7vzk0WU9+8p66wBHIrNL9mJNbnJbTe72fPqsz0G6Mvpi1gTN9xRr+RZoDqj 6bfv8ejoNrkEF9hu4He6kARBBVOwcQEDkYUMovPYldLCyZzazarUTT5jiJXoXVqMhL HXKAMWkqA7RCw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net v4 2/2] 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: <20261130033422.2143435-3-piyus@iiitd.ac.in> References: <20261130033422.2143435-1-piyus@iiitd.ac.in> <20261130033422.2143435-3-piyus@iiitd.ac.in> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 03:51:09 +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 4 potential issues to consider: - [High] can: j1939: session and netdev leak in j1939_xtp_rx_dat_one() after bad DPO - [Medium] can: j1939: j1939_xtp_rx_dpo_one() processes DPO on WAITING_ABORT session - [Medium] can: j1939: TOCTOU race on was_dying in j1939_xtp_rx_dpo_one() leaks session - [Medium] can: j1939: wrong abort code used for bad DPO in j1939_xtp_rx_dpo_one() -- commit 133f5c5fbbb6cfa752a4d3f573aecb398ca549b9 Author: Piyus Kedia can: j1939: reject an out-of-range data packet offset This commit validates the ETP data packet offset against session->pkt.total in j1939_xtp_rx_dpo_one(), ignores EOMA frames on cancelled sessions, and fetches the completed receive skb from offset 0. > 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 [ ... ] > @@ -1831,14 +1846,36 @@ 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 > + dpo =3D j1939_etp_ctl_to_packet(dat); > + if (dpo >=3D session->pkt.total) { > + bool was_dying =3D session->state >=3D J1939_SESSION_WAITING_ABORT; > + > + 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); [Severity: Medium] Can reading session->state into was_dying before cancelling the timers race with j1939_tp_rxtimer() and leak the session? CPU0 CPU1 j1939_xtp_rx_dpo_one() was_dying =3D session->state >=3D ... (false) netdev_info(...) j1939_tp_rxtimer() j1939_session_list_lock() hrtimer_start(&session->rxtimer, ..= .) __j1939_session_cancel() session->state =3D J1939_SESSION_WAITING_ABORT j1939_session_list_unlock() j1939_session_timers_cancel() j1939_session_cancel() (no-op) if (was_dying) (false) <-- session stranded with no timers j1939_session_timers_cancel() cancels the abort rxtimer started by CPU1, j1939_session_cancel() sees J1939_SESSION_WAITING_ABORT and does not restart it, and was_dying is stale so j1939_session_deactivate_activate_next() is skipped, leaving the session on active_session_list with its skb and netdev references held forever. > + j1939_session_cancel(session, J1939_XTP_ABORT_FAULT); [Severity: Medium] Should this pass J1939_XTP_ABORT_BAD_EDPO_OFFSET instead of J1939_XTP_ABORT_FAULT? transport.c defines J1939_XTP_ABORT_BAD_EDPO_OFFSET (reason 12, mapped to EPROTO) specifically for a bad EDPO offset, whereas J1939_XTP_ABORT_FAULT sends SAE J1939-21 abort reason 5 (retransmit limit reached) on the bus and reports ENOTRECOVERABLE to local sockets. > + 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; > + } [Severity: High] Does rejecting an out-of-range DPO still leak the session and its netdev reference when the ETP.DT data packet that follows it arrives? In ETP, the sender transmits ETP.DT frames right after ETP.CM_DPO without waiting for an acknowledgment. When the first out-of-range DPO is rejected here, session->state becomes J1939_SESSION_WAITING_ABORT with a 500 ms abort rxtimer and session->last_cmd remains at RTS or CTS. When the following ETP.DT frame reaches j1939_xtp_rx_dat_one(), the last_cmd check fails and jumps to out_session_cancel: net/can/j1939/transport.c:j1939_xtp_rx_dat_one() { ... 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 500 ms abort rxtimer and j1939_session_cancel() is a no-op because session->state is already J1939_SESSION_WAITING_ABORT, stranding the session on active_session_list with no timers and leaking its queued skb and netdev reference. Also, if a prior block had left session->last_cmd at 0xff, j1939_xtp_rx_dat_one() does not check for J1939_SESSION_WAITING_ABORT and continues copying ETP.DT payload into the previous DPO window and rearming txtimer on the cancelled session. > + > /* transmitted without problems */ > - session->pkt.dpo =3D j1939_etp_ctl_to_packet(skb->data); > + session->pkt.dpo =3D dpo; > session->last_cmd =3D dat[0]; > j1939_tp_set_rxtimeout(session, 750); [Severity: Medium] Does j1939_xtp_rx_dpo_one() still accept in-range DPOs and queue duplicate abort notifications when session->state is already J1939_SESSION_WAITING_ABORT? Because session->state >=3D J1939_SESSION_WAITING_ABORT is only checked inside the dpo >=3D session->pkt.total branch, an in-range DPO on a cancell= ed session still updates session->pkt.dpo and session->last_cmd, resets rxtimer to 750 ms, queues J1939_ERRQUEUE_RX_DPO after J1939_ERRQUEUE_RX_ABORT, and lets subsequent ETP.DT frames write into the session skb and schedule txtimer. Even when dpo >=3D session->pkt.total on an already-cancelled session, calling j1939_session_cancel() still reaches j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT) outside the state guard and queues a duplicate RX_ABORT on the socket error queue. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130033422.2143= 435-1-piyus@iiitd.ac.in?part=3D2