From nobody Tue Nov 24 11:27:46 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.2 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794393473; b=3Bp5q2oa/PSNrUcXhXmyymTh9ztkCM3v9Qg2xO1IL8fAB/HjGCLtJcx4bD2vUflLG5eD cfut7tCOYQCcgS7ukbrF1HVFf39u8nQ3mGTi8pHukPn876hhh3CdxZarvl2uB2zvX1rjD 0RkRKO47NO9ec5R9ERTryFmEuDrZKaylXsY144y7FoXTDQDqN3AwVkHFaGlx924HV1qOR 3bHX+YAh8XswUZpKbk7+inLSJt69m4DsVWkvssvxvwNQplm4c+CtSBSCmUMwv9hIi+GhP 7AJmNEUJUAPxkh8JjEg64URmROh2ADZ2HJDiojtVQH9FwGZ7Jo244CYitLUXRC22kfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794393473; h=DMARC-Filter:DKIM-Signature:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-CM-TRANSID:X-Coremail-Antispam:Sender: X-CM-SenderInfo; bh=LTxP+YIomqSIzpLJsllAgnu6yXFb3cfcIae7hFBjMxU=; b=o9e4Ud/QN8twp6KxPvlSquPkA94KVq0lv0wGGhHPLYq5OdexF/LB5g0fWeBGaHN6z6Zi eoDt4lbPX4ZFTBOqi6M9k1jGPb9FsBW2BeyHMjyUT/wbhYP1pB+gWV+vbRTglb9N8nDQN F2UQ5bVIySReJF0Rh375DY7ocWepv0/kDasvUY7FsBRkp90CE/bNqY6xVTarqz1a0jrUr FCa87t90WXxeuG//KKO+SFtqpb+0TAHynelhbhKDhQMhkPsXMR3XYVNz3Z9SVZm6iR0jV xnNdKtmcVseOd3xOEFM7u1d04Z4CWfYXuGt4meteijOgGFDFZ3UKxmhABiC3aKKMMzQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=gmail.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=Nh18guJG; arc=none smtp.remote-ip=117.135.210.2 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBF5F606A886; Wed, 11 Nov 2026 10:37:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DBF5F606A886 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=Nh18guJG DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Date:Subject:MIME-Version:Content-Type: Message-Id:To; bh=LTxP+YIomqSIzpLJsllAgnu6yXFb3cfcIae7hFBjMxU=; b=Nh18guJG8ApkMjdlkyqc/hCyytu3uslVQWSivIuQ/BJNbc2abEO7oZCLHs4PZT hWorljnw88qNgdlp4G2u4nCp6LgfwOQmTU8q1yymPF4sDwLwXRK+4tCbisWvhxMa K4tYovKTztyNqnAPljpE6rLJsTRbnhIajTavO5/PTWekc= From: Chaosheng Qu Date: Wed, 11 Nov 2026 18:31:22 +0800 Subject: [PATCH net v9 1/4] can: j1939: serialize cancel and rearm of the receive timer 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261111-j1939-edpo-v9-v9-1-e779ca334a81@163.com> References: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> In-Reply-To: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> To: Robin van der Gracht , Oleksij Rempel , Oliver Hartkopp , Marc Kleine-Budde Cc: kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-Mailer: b4 0.16.0 X-CM-TRANSID: _____wD3n3ZtRfRq73WgGQ--.5537S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxKrWDKw47XrWUXF4kCw1kGrg_yoWxCryrpr W3Wry3Gr17WF47Zr4ktFyDWryFvwn3J348Wr1xJ3s2yay3Cr45tF1DG34xWa9rtrW8Z3y3 ua4Sqwn8Gw4kt37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j7o7NUUUUU= Sender: quchaosheng000406@163.com X-CM-SenderInfo: xtxfxtprvkv0bjqqikiqw6il2tof0z/xtbC4w5EuWr0RW5fvwAA3F From: Chaosheng Qu Cancel and rearm the receive timer as one atomic step under active_session_list_lock. j1939_tp_set_rxtimeout() cancels the timer, takes a reference and starts it again, but its callers do not agree on that lock: the receive handlers call it without the lock, while j1939_session_cancel() is reached from the transmit timer path and used to call it with the lock held. That makes the sequence non-atomic. If one caller starts the timer after another has cancelled it and before that one starts it again, the second hrtimer_start() reprograms an already armed timer. hrtimer_start() does not report that the timer was armed and does not drop the reference the first caller took, so that reference is never released: the session, and the netdev_hold() reference it carries, leak. The lock cannot simply be taken around the existing helper, because hrtimer_cancel() waits for a running callback and j1939_tp_rxtimer() takes the same lock. Add j1939_tp_arm_rxtimer_locked(), which uses hrtimer_try_to_cancel() instead: it never waits, so it is safe under the lock, and it returns 1 only when the timer was queued, which is the only case in which the caller's reference has to be dropped. j1939_tp_set_rxtimeout() now holds the lock around the helper, j1939_session_cancel() calls the helper instead of hand-rolling get + hrtimer_start(), and the rx timeout branch of j1939_tp_rxtimer() does the same, removing a second copy of that sequence. Every existing caller of j1939_tp_set_rxtimeout() is outside the lock, so the added acquisition does not recurse. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Chaosheng Qu --- net/can/j1939/transport.c | 66 ++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index 8fcfd13e5..fa23260e1 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -721,15 +721,42 @@ void j1939_tp_schedule_txtimer(struct j1939_session *= session, int msec) HRTIMER_MODE_REL_SOFT); } =20 -static inline void j1939_tp_set_rxtimeout(struct j1939_session *session, - int msec) +/* + * Rearm the receive timer as one step under active_session_list_lock. + * + * j1939_tp_set_rxtimeout() is called from receive handlers that do not ho= ld + * the session list lock, while j1939_session_cancel() is called from the + * transmit timer path. If the cancel and the rearm are not serialized, a + * concurrent caller can start the timer after this one cancelled it and + * before this one starts it again: hrtimer_start() on an already armed ti= mer + * reprograms it without dropping the reference taken by that caller, and = the + * session leaks together with its netdev reference. + * + * hrtimer_try_to_cancel() does not wait for a running callback, so it can= be + * called with the lock held even though j1939_tp_rxtimer() takes the same + * lock; a callback that is already running drops its own reference. For = the + * same reason the return value is only 1 when the timer was queued: when = this + * runs from j1939_tp_rxtimer() itself, the timer is no longer queued and = 0 is + * the expected result. + */ +static void j1939_tp_arm_rxtimer_locked(struct j1939_session *session, int= msec) { - j1939_session_rxtimer_cancel(session); + if (hrtimer_try_to_cancel(&session->rxtimer) =3D=3D 1) + j1939_session_put(session); + j1939_session_get(session); hrtimer_start(&session->rxtimer, ms_to_ktime(msec), HRTIMER_MODE_REL_SOFT); } =20 +static inline void j1939_tp_set_rxtimeout(struct j1939_session *session, + int msec) +{ + j1939_session_list_lock(session->priv); + j1939_tp_arm_rxtimer_locked(session, msec); + j1939_session_list_unlock(session->priv); +} + static int j1939_session_tx_rts(struct j1939_session *session) { u8 dat[8]; @@ -1161,18 +1188,29 @@ static void __j1939_session_cancel(struct j1939_ses= sion *session, static void j1939_session_cancel(struct j1939_session *session, enum j1939_xtp_abort err) { + bool waiting; + j1939_session_list_lock(session->priv); =20 + waiting =3D session->state =3D=3D J1939_SESSION_WAITING_ABORT; 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_tp_arm_rxtimer_locked(session, J1939_XTP_ABORT_TIMEOUT_MS); } =20 j1939_session_list_unlock(session->priv); =20 if (!session->sk) j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT); + + /* The abort already went out on an earlier call, so this one armed no + * timer. Several callers cancel the timers before calling here, which + * would otherwise leave the session on the list with nothing to finish + * it off, so deactivate it now. + */ + if (waiting) + j1939_session_deactivate_activate_next(session); } =20 static enum hrtimer_restart j1939_tp_txtimer(struct hrtimer *hrtimer) @@ -1279,10 +1317,8 @@ static enum hrtimer_restart j1939_tp_rxtimer(struct = hrtimer *hrtimer) session->state < J1939_SESSION_ACTIVE_MAX) { netdev_alert(priv->ndev, "%s: 0x%p: rx timeout, send abort\n", __func__, session); - j1939_session_get(session); - hrtimer_start(&session->rxtimer, - ms_to_ktime(J1939_XTP_ABORT_TIMEOUT_MS), - HRTIMER_MODE_REL_SOFT); + j1939_tp_arm_rxtimer_locked(session, + J1939_XTP_ABORT_TIMEOUT_MS); __j1939_session_cancel(session, J1939_XTP_ABORT_TIMEOUT); } j1939_session_list_unlock(session->priv); @@ -1729,16 +1765,10 @@ static int j1939_xtp_rx_rts_session_active(struct j= 1939_session *session, =20 j1939_session_timers_cancel(session); j1939_session_cancel(session, J1939_XTP_ABORT_BUSY); - if (session->transmission) { - j1939_session_deactivate_activate_next(session); - } else if (session->state =3D=3D 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); - } + /* Both roles: the peer is restarting the transfer, so free the + * slot now rather than wait out the abort timeout. + */ + j1939_session_deactivate_activate_next(session); =20 return -EBUSY; } --=20 2.43.0 From nobody Tue Nov 24 11:27:46 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.2 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794393473; b=cLEpGiMJ5veopgXA/rYEfbV47JYjuR+sd70ahriev9tAt0v3+4Pj+hfxfAyGqr1wAJGo od+plP1XQDDyvUNPVHVXHvYGjTYhfBDhWOyiN7hRoCVTJNO8bbPFxYjPiDo+kxSP9uAHz goC7hAev3Z4XSrr8OfKtHsY72pAZ2r/SA/xyMB/vHQAbVTCiTJA1Yu1UQ+DWb4yS7auEI 2DV1qhf8zeo13i0uzCz55xC5/XwaLaOqcUAetSWMupZyeMrVnVaeEnpmye5wCbdgcCuLv qsfdYha/7fovMWq91JhitvgBS+W2pzuhrU1wvp3k3UzUGs6AtFIGHDhpzBgrvQUuWFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794393473; h=DMARC-Filter:DKIM-Signature:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-CM-TRANSID:X-Coremail-Antispam:Sender: X-CM-SenderInfo; bh=d3FKuqc6u/Y7Kk2Jk+Mpg4j89GV6lD7jgrDIj8trkuE=; b=YRtHTQhLM+quLZNwE4AENSiytxcK2AmrOb5+C0vMkuaYWNxbthduWXSBCwVlEHIzavFo e4IUl6xno9qoO4MdLgUff1uVm9UUSggVrDOhfFl6yj0XsLsMkAAJhEkPya/Ge0f5hyeHa S8+3wPMgIg3CymYlFQQ8TKMsTBwJT/FLciDhnjCnI6Luf4vsZoobjYsErTiJ+1J0UryxJ Q/xVR9miqBut3nt7085bgD88IavlikLCNxjLKwMttvOPKRFmz4lqHaY0AJbPfuqoOxdAf ep/pSzNL0yDdgY7F0Fncmz9qeEZ432roA9cGdsM7M0GjkURCVEd01ZmqMKG5DIph9jA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=gmail.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b="n+InSik/"; arc=none smtp.remote-ip=117.135.210.2 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0CBE606A332; Wed, 11 Nov 2026 10:37:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B0CBE606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=n+InSik/ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Date:Subject:MIME-Version:Content-Type: Message-Id:To; bh=d3FKuqc6u/Y7Kk2Jk+Mpg4j89GV6lD7jgrDIj8trkuE=; b=n+InSik/pCTGBactsyLDZqen3iv5yu+rrX65WOIj97riEnt6ATOP9OAuhmimCC Kuuz4Qb+8LAO/F+PN24sQjV5L4wRP6HNAZHGqv0OR+R86moWldYjxzoKzkGB76K0 OCbodr4t7cXbJbWo/aAQ1skuGj4ZROJpAZZx/q5VTbfn8= From: Chaosheng Qu Date: Wed, 11 Nov 2026 18:31:23 +0800 Subject: [PATCH net v9 2/4] can: j1939: validate the EDPO packet number 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261111-j1939-edpo-v9-v9-2-e779ca334a81@163.com> References: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> In-Reply-To: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> To: Robin van der Gracht , Oleksij Rempel , Oliver Hartkopp , Marc Kleine-Budde Cc: kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-Mailer: b4 0.16.0 X-CM-TRANSID: _____wD3f79uRfRqf2sZGg--.8132S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF1xWryDXrWfKr18Wr1kAFb_yoWrAr1kpa y3KrW3GrnrJr1Iyws3trZYqryayrs3JFWfW3W2q3sakwsxCF4rtFyDKry2gayDJ3y8u345 uryDX3ZxGr4DXrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UMWl9UUUUU= Sender: quchaosheng000406@163.com X-CM-SenderInfo: xtxfxtprvkv0bjqqikiqw6il2tof0z/xtbC5A9EuWr0RW+jwgAA3D From: Chaosheng Qu Validate the packet number in ETP.CM_DPO, which is peer controlled and currently accepted without any check. It names the packet a transmission window starts at, and j1939_xtp_rx_dat_one() places incoming data at "dat[0] - 1 + pkt.dpo", so a value past the end of the message moves pkt.dpo beyond the reassembled buffer. The transfer still completes normally in that case. With pkt.dpo =3D=3D pkt.total, a closing ETP.DT frame with dat[0] =3D=3D 0 evalu= ates to packet pkt.total - 1, which is the last in-order packet, so pkt.rx reaches pkt.total and the receiver emits its own EOMA. The local loopback of that EOMA runs j1939_session_completed(), which asks j1939_session_skb_get() for offset "pkt.dpo * 7" -- one full packet past the end of the queued skb -- gets NULL, and passes it straight to j1939_sk_recv(), which dereferences oskb->sk. Reject a packet number at or past pkt.total and abort the session. The check has to be ">=3D" and not ">": pkt.total is a packet count, so the last valid packet is pkt.total - 1. The abort code depends on the role: a receiver rejects a bad offset with J1939_XTP_ABORT_BAD_EDPO_OFFSET, while a transmitter only builds an EDPO from pkt.tx_acked, which comes from the responder's ETP.CM_CTS, so an out-of-range value there is an oversized CTS and is reported as J1939_XTP_ABORT_ECTS_TOO_BIG. Cancel the session timers before aborting, as the other receive-path abort handlers do. j1939_session_cancel() only rearms the abort timer and leaves session->txtimer armed, so on the transmitter path the retry timer keeps firing on an aborting session, retries up to J1939_XTP_TX_RETRY_LIMIT and overwrites session->err with -ENETUNREACH; on the receiver path the retries transmit CTS or EOMA and clobber the abort timeout. The CTS packet number that feeds the transmitter-side EDPO is bounded in 4/4, on its own, because it is a different input parsed in a different function; this patch only stops an EDPO value from being used as an offset. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Chaosheng Qu --- net/can/j1939/transport.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index fa23260e1..258009182 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1853,14 +1853,42 @@ static void j1939_xtp_rx_dpo_one(struct j1939_sessi= on *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); + + /* EDPO is peer controlled. j1939_xtp_rx_dat_one() places data at + * "dat[0] - 1 + pkt.dpo", so a value at or past pkt.total moves + * pkt.dpo past the reassembled buffer, and the ETP completion path + * then looks up an offset no queued skb covers. + * + * This bounds the receiver-side writer only. j1939_session_tx_dpo() + * copies pkt.tx_acked, which comes from an ETP.CM_CTS packet number + * that the responder controls, and 4/4 bounds it where it is parsed. + */ + if (dpo >=3D session->pkt.total) { + netdev_warn(session->priv->ndev, + "%s: 0x%p: EDPO %u out of range (total %u), aborting\n", + __func__, session, dpo, session->pkt.total); + j1939_session_timers_cancel(session); + /* The transmitter only sees this on the echo of an EDPO it built + * from an oversized ETP.CM_CTS packet number, so it is the + * responder's CTS that is too big, not the EDPO offset. + */ + j1939_session_cancel(session, + session->transmission ? + J1939_XTP_ABORT_ECTS_TOO_BIG : + J1939_XTP_ABORT_BAD_EDPO_OFFSET); + return; + } + /* 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); =20 --=20 2.43.0 From nobody Tue Nov 24 11:27:46 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794393473; b=g2Bs/x2AI3bofdP3/EGxhp9siQpv1wqOVza4ZUv/Hd6hq7a/2Rmnp6ADsQGVmS2wCbFO iGw1zf3v6ad0psBbRfHLpm+l2OAPL6BVTQ+tc+8ZrvlBBFrv6wvduiQu4CHKC2C6RKtIY dpQxV2clxoKMQyNUszLhcN+x+wglfbAypkOlci3g2fE4t2bztHngaIQgtpDbYPjiJpvYD NSM5axE2/HnQKvb7du+WhG8q6LXUBvHyM+KZaDcofeETOWkUzZlZV37ELSL9oaOgIaLgJ FEom2kCFgncKBGu+52uRs4ol8jZOpc7thctJj0P32jHipoacSbp4o2L887mx1zzsShA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794393473; h=DMARC-Filter:DKIM-Signature:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-CM-TRANSID:X-Coremail-Antispam:Sender: X-CM-SenderInfo; bh=6Ho2M0VUW7VCGgUrpM5ofB3aUX9egvXjmTtH+qZ/dEo=; b=bi5nVoqhz10CPvfV8ZG0lijfTcgDB201rwSw+iq79xptupunNWgfgw45vtnFRpBpbXIQ BvnVX4rwhtH+mU1XvvD+2+6hJIsoPeIZ4V5gd1s9wsOqgwU5keKX6kNgFwnesbc3otM1D 2h9p+h4m79YCSO168BHwJ4c1EsSYrxvHySaBUIcxy3zDlV9PrIc+3EOQN6BP4tOvQVSd0 u/8g4a8dcQoWqtK3DAhI+/QVottKFkJrJxaenWHPqQEl0EsiR3/PP1zE3IldNcbG/YI/W SDGWOrppUO7OH3ddEWZtdVVulpgsQOwTNCNVMitZ5xBPyXPyaBZ7z5GAz1hpsjeMdlg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=gmail.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=XDWKkjbP; arc=none smtp.remote-ip=220.197.31.5 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 687BA606A887; Wed, 11 Nov 2026 10:37:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 687BA606A887 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=XDWKkjbP DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Date:Subject:MIME-Version:Content-Type: Message-Id:To; bh=6Ho2M0VUW7VCGgUrpM5ofB3aUX9egvXjmTtH+qZ/dEo=; b=XDWKkjbPTPxXderyAtatzGncYj2SKg43LlCq5joI0NbiS4GaDYhUnNQcRJ0mBO hEA3fMCLygHey27qdF+BjU4C89jvzx3SNZdSkyTxq54ZmEw3CFanGSRccAX/1EF7 c8f5BjvE5p/XXVZWW5sczt9VgeIC8TfAHFb2Np8yfAoHw= From: Chaosheng Qu Date: Wed, 11 Nov 2026 18:31:24 +0800 Subject: [PATCH net v9 3/4] can: j1939: drop the message when the reassembled skb is gone 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261111-j1939-edpo-v9-v9-3-e779ca334a81@163.com> References: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> In-Reply-To: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> To: Robin van der Gracht , Oleksij Rempel , Oliver Hartkopp , Marc Kleine-Budde Cc: kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.16.0 X-CM-TRANSID: _____wDn38ZvRfRqIHegGQ--.49604S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zw18Aw15Wr1ruw4fAr13urg_yoW8Xw4UpF y7KryUGr9rXF47ArsagrWDX345C3Zaqry8GFyUtwn3C3y5Cw45trs8Kryaqan8Aan5u3ya ga43X3W7Kay0937anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jcWrAUUUUU= Sender: quchaosheng000406@163.com X-CM-SenderInfo: xtxfxtprvkv0bjqqikiqw6il2tof0z/xtbC4xBFumr0RXBf3QAA3l From: Chaosheng Qu Check the skb that j1939_session_completed() hands to j1939_sk_recv(), which dereferences oskb->sk. A NULL here is the last step of the EDPO out-of-range sequence fixed by the previous patch; the bounds check makes the lookup succeed, but the dereference should not depend on that. Drop the message instead, which is what the other caller of j1939_session_skb_get(), j1939_simple_txnext(), already does. Assisted-by: LLM Signed-off-by: Chaosheng Qu --- net/can/j1939/transport.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index 258009182..fc2840f33 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1281,9 +1281,17 @@ static void j1939_session_completed(struct j1939_ses= sion *session) =20 if (!session->transmission) { se_skb =3D j1939_session_skb_get(session); - /* distribute among j1939 receivers */ - j1939_sk_recv(session->priv, se_skb); - consume_skb(se_skb); + + /* Defense in depth: pkt.dpo is range checked when an EDPO is + * received, so the lookup should always find the skb. Drop + * the message rather than hand a NULL skb to j1939_sk_recv() + * if the offset arithmetic ever regresses. + */ + if (se_skb) { + /* distribute among j1939 receivers */ + j1939_sk_recv(session->priv, se_skb); + consume_skb(se_skb); + } } =20 j1939_session_deactivate_activate_next(session); --=20 2.43.0 From nobody Tue Nov 24 11:27:46 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794393473; b=HmOk6167RLxtLCzYdDHc+d//WKvEFKPKi8kgO97QddmvB2LGkl/mLj6l79+NFoltd+2s R9ffU4slu5Zi1yW2kJcm4BksbLYTh0BRhHKtwkkQ/Hpp5u6u5/y0QJ4jOKXZjLgL7RX4U axpR7vayqSrmiVBQnpdoeFQkzZMUhdR5myMrFmn2mpqL6LMNdjyZwcoimjG/6+j5XTQwS NIwyIFMksHJ/YsU3RM3eFvl0oNS5CApFKfT6yd9Hy9ihH8qdv4/u7f62TiD0YVP/qQhG1 gt1AUpagupo3p2ndxmu/qvcpcIXur1qsgkid6WijI+0fNmYAObJa8+JnHCEdLuuaVHw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794393473; h=DMARC-Filter:DKIM-Signature:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-CM-TRANSID:X-Coremail-Antispam:Sender: X-CM-SenderInfo; bh=28Q6WmpAlZrwLLkP6jX7TaLtLGOPmnTXA1hWKXPeSDU=; b=qAAmtuvRmVA1Kjw9EJhymLOf7/04Bbes04aRnsJUh5qDZxSkY6yQZpSORBz9v14ydZT/ 83eZUpm2Ge6u2LGyjAgNRTu0QqziR7sbpsgyxqAf6eBg8ngcm8P+Rud+QkFMWp9EVBEZL CnA0fyh2viAQFcbDEfjskTJ9EzK9FaPGUUjjCafKfWHhpl3vBTCSlOF/bwS2XRFygbNPI QuI31QVFyFuMVzNHjGTA+BZHpghVLLCovT7d6SWP42xTK0FYzEPStfj7P355xAEeqc1Gv NfRWCxiLfsRyE8FBqe3zMLYro5mDWukM+9xOLzM0kSWBdJUQ9mqnmZN0lu2PwrwtWcg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=gmail.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=CtHh7cAH; arc=none smtp.remote-ip=117.135.210.4 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ACD5606A885; Wed, 11 Nov 2026 10:37:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4ACD5606A885 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=CtHh7cAH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Date:Subject:MIME-Version:Content-Type: Message-Id:To; bh=28Q6WmpAlZrwLLkP6jX7TaLtLGOPmnTXA1hWKXPeSDU=; b=CtHh7cAHJkPYY9WL+DH3iVnGvfzxo2PE9qflOAOQrqkgap9dbxBQcqxtRPqcyr HHgkgEd1rgXx57ECIWBF/ytPptsrzG9t98DE83Y985A1JQtKN5lsnp/YL1ST4XyX 0uAu6/BZJynTlH6LnAl+PIpJv4Hp7YUFCdun/ludwj4c8= From: Chaosheng Qu Date: Wed, 11 Nov 2026 18:31:25 +0800 Subject: [PATCH net v9 4/4] can: j1939: reject a CTS that names more packets than the message has 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261111-j1939-edpo-v9-v9-4-e779ca334a81@163.com> References: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> In-Reply-To: <20261111-j1939-edpo-v9-v9-0-e779ca334a81@163.com> To: Robin van der Gracht , Oleksij Rempel , Oliver Hartkopp , Marc Kleine-Budde Cc: kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-Mailer: b4 0.16.0 X-CM-TRANSID: PigvCgCXwCdwRfRqPGBrFQ--.14481S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zw1rCrWDCFWDGw48Kr15urg_yoW8ArW7pa 9xKry3Cr18Jrn3Aws2kF1DXa4UCws8G347WFyjq3s3Kw4DAF13tayqqrZ2g3yDJF45u3y5 ZF43Xwn3W34vg37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jz_M-UUUUU= Sender: quchaosheng000406@163.com X-CM-SenderInfo: xtxfxtprvkv0bjqqikiqw6il2tof0z/xtbDABFFumr0RXE3TQAA3+ From: Chaosheng Qu Reject a CTS packet number above pkt.total in j1939_xtp_rx_cts_one(). The function rejects a zero packet number and a window above pkt.block, but not a packet number above pkt.total. It then stores "pkt - 1" in pkt.tx_acked, and the transmitter reports that value back in an ETP.CM_DPO. That value is what j1939_xtp_rx_dpo_one() now bounds, so an oversized CTS is currently caught one step later and reported as a bad EDPO offset. Reject it where it originates instead, with the abort code that describes it: J1939_XTP_ABORT_ECTS_TOO_BIG, "ECTS requested packets exceeds message size". Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Chaosheng Qu --- net/can/j1939/transport.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index fc2840f33..377991d36 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1512,6 +1512,15 @@ j1939_xtp_rx_cts_one(struct j1939_session *session, = struct sk_buff *skb) goto out_session_cancel; else if (dat[1] > session->pkt.block /* 0xff for etp */) goto out_session_cancel; + else if (pkt > session->pkt.total) { + /* The responder asks for more packets than the message has. + * pkt - 1 becomes pkt.tx_acked below, and the transmitter + * reports that value in an ETP.CM_DPO, where it would name a + * packet past the end of the message. + */ + err =3D J1939_XTP_ABORT_ECTS_TOO_BIG; + goto out_session_cancel; + } =20 /* set packet counters only when not CTS(0) */ session->pkt.tx_acked =3D pkt - 1; --=20 2.43.0