* [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two
@ 2026-11-30 3:34 Piyus Kedia
2026-11-30 3:34 ` [PATCH net v4 1/2] can: j1939: do not pass a NULL skb to the socket layer Piyus Kedia
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Piyus Kedia @ 2026-11-30 3:34 UTC (permalink / raw)
To: Robin van der Gracht, Oleksij Rempel, Oliver Hartkopp,
Marc Kleine-Budde, linux-can
Cc: kernel, linux-kernel, Kapil Vaswani
v3 was one patch doing both halves. Oleksij asked for the NULL check to
go out on its own, small, for stable, with the DPO range check following
as its own patch, so here they are as 1/2 and 2/2.
1/2 is the stable fix and carries the only Cc: stable. It is Oleksij's
own hunk, with the netdev_warn() rewrapped to fit; it says in the message
that it is only a mitigation and leaves the protocol alone, so there is no
reason to ask it for the checks that 2/2 adds.
2/2 is the protocol fix: refuse a data packet offset that is not below
session->pkt.total, abort the session so the peer is told, and complete a
receive session from offset 0. No Cc: stable.
Posted as a series rather than as two independent patches because 2/2 does
not apply without 1/2 - sent separately, the second one fails to apply for
everyone and for the bots. If you would rather have 1/2 alone first and
2/2 after it lands, say so and I will resend that way.
Measured on current net.git main with KASAN and kasan_multi_shot=1, over
one vcan pair, the same reproducer each time:
unpatched null-ptr-deref in j1939_sk_recv() in the receive softirq,
then "Kernel panic - not syncing: Fatal exception in
interrupt" - which is also why only one report prints
despite kasan_multi_shot.
1/2 only no report, no panic, and the new warning once per round
of the reproducer, so the path is still reached and is now
handled.
1/2 + 2/2 no report, no panic, the offset refused when it arrives, and
1/2's warning never fires at all - the range check stops the
NULL skb existing. The EOMA guard in 2/2 fires in that run,
so it is not speculative.
Found by AI-driven fuzzing built on top of syzkaller; every analysis was
checked by hand against the code, as each patch records. The reproducer
is not posted - it goes to anyone who asks.
Changes in v4:
- split into the stable mitigation (1/2) and the protocol fix (2/2), as
asked; 1/2 is Oleksij's hunk and credits him with Suggested-by
- 1/2 carries the KASAN report and the panic line, and says it is only a
mitigation
- 2/2 keeps the EOMA-on-a-cancelled-session guard and the deactivate on a
second out-of-range DPO, and explains why each is needed
- recipients are get_maintainer.pl for net/can/j1939/transport.c:
linux-can and the CAN maintainers, no netdev
- stable@vger.kernel.org dropped from the recipient list; the Cc: stable
tag on 1/2 is the mechanism
v3: https://lore.kernel.org/all/20261124181757.638280-1-piyus@iiitd.ac.in/
The review:
https://lore.kernel.org/all/awxMr_bAtgqEwbrf@pengutronix.de/
Piyus Kedia (2):
can: j1939: do not pass a NULL skb to the socket layer
can: j1939: reject an out-of-range data packet offset
net/can/j1939/transport.c | 55 +++++++++++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 5 deletions(-)
base-commit: 9437ee8b6cf607e883b36e44bd755968daaebd48
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH net v4 1/2] can: j1939: do not pass a NULL skb to the socket layer 2026-11-30 3:34 [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Piyus Kedia @ 2026-11-30 3:34 ` Piyus Kedia 2026-11-30 3:34 ` [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset Piyus Kedia 2026-11-30 7:47 ` [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Oleksij Rempel 2 siblings, 0 replies; 8+ messages in thread From: Piyus Kedia @ 2026-11-30 3:34 UTC (permalink / raw) To: Robin van der Gracht, Oleksij Rempel, Oliver Hartkopp, Marc Kleine-Budde, linux-can Cc: kernel, linux-kernel, Kapil Vaswani Check for a NULL skb in j1939_session_completed() and end the session with EPROTO, so that sockets reading the error queue get an RX abort. Print a rate-limited warning, because a peer can cause the missing skb. A peer can send an ETP DPO at or beyond the end of the message. When the session completes after that, j1939_session_completed() finds no skb and passes NULL to j1939_sk_recv(), which dereferences it. The dereference happens in the receive softirq, so it is fatal: BUG: KASAN: null-ptr-deref in j1939_sk_recv+0xd4/0x3c0 Read of size 8 at addr 0000000000000018 by task repro/9528 <IRQ> j1939_sk_recv+0xd4/0x3c0 j1939_xtp_rx_eoma+0x207/0x300 j1939_tp_recv+0x64c/0xa10 j1939_can_recv+0x51a/0x640 can_receive+0x19e/0x2a0 __netif_receive_skb+0x120/0x270 process_backlog+0x427/0xd50 net_rx_action+0x3f7/0x870 handle_softirqs+0x1e5/0x6a0 </IRQ> netif_rx+0x89/0xa0 can_send+0x71f/0x7e0 raw_sendmsg+0x9ed/0xab0 Kernel panic - not syncing: Fatal exception in interrupt This is only a mitigation, and it leaves the transport protocol alone on purpose. The DPO is still not checked when it arrives, and no abort frame is sent to the peer. These checks follow as a separate patch. Found by AI-driven fuzzing built on top of syzkaller; the analysis was then checked by hand against the code. Measured on current net.git main with KASAN and kasan_multi_shot=1, over one vcan pair, with the same reproducer each time: without this patch the report above and the panic; with it no report and no panic, and the new warning fires once per round of the reproducer, so the path is still being reached and is now handled. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Suggested-by: Oleksij Rempel <o.rempel@pengutronix.de> Cc: stable@vger.kernel.org Co-developed-by: Kapil Vaswani <kapil@presceralabs.ai> Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in> --- 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 8fcfd13e5e6f..fa30273df326 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1243,9 +1243,17 @@ static void j1939_session_completed(struct j1939_session *session) if (!session->transmission) { se_skb = j1939_session_skb_get(session); - /* distribute among j1939 receivers */ - j1939_sk_recv(session->priv, se_skb); - consume_skb(se_skb); + if (!se_skb) { + if (net_ratelimit()) + netdev_warn(session->priv->ndev, + "%s: 0x%p: no skb found for completed session\n", + __func__, session); + session->err = EPROTO; + } else { + /* distribute among j1939 receivers */ + j1939_sk_recv(session->priv, se_skb); + consume_skb(se_skb); + } } j1939_session_deactivate_activate_next(session); -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset 2026-11-30 3:34 [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Piyus Kedia 2026-11-30 3:34 ` [PATCH net v4 1/2] can: j1939: do not pass a NULL skb to the socket layer Piyus Kedia @ 2026-11-30 3:34 ` Piyus Kedia 2026-11-30 3:51 ` sashiko-bot 2026-12-01 17:47 ` netdev-bot+sashiko 2026-11-30 7:47 ` [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Oleksij Rempel 2 siblings, 2 replies; 8+ messages in thread From: Piyus Kedia @ 2026-11-30 3:34 UTC (permalink / raw) To: Robin van der Gracht, Oleksij Rempel, Oliver Hartkopp, Marc Kleine-Budde, linux-can Cc: kernel, linux-kernel, Kapil Vaswani j1939_xtp_rx_dpo_one() takes the peer's data packet offset and stores it without checking it against the session: session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data); j1939_session_skb_get_by_offset() then looks for a buffered skb at pkt.dpo * 7, and j1939_xtp_rx_dat_one() copies into the session's skb at that offset. An offset past the session's packet count has no skb behind it, so the lookup returns NULL. Reject an offset that is not below session->pkt.total and abort the session, so the peer is told rather than left waiting, and complete a receive session from offset 0 rather than from whatever window the last DPO named. Two consequences of aborting here, both handled: - an EOMA can still arrive for a session already waiting for its abort to go out. Completing it then would hand its data to the receiving sockets and queue a second RX_ABORT, so j1939_xtp_rx_eoma_one() now leaves a cancelled session to the abort path. - j1939_session_cancel() is a no-op once the state is WAITING_ABORT, so on a second out-of-range DPO it would not restart the timeout cancelled just above. Deactivate the session instead, as j1939_xtp_rx_rts_session_active() does, or it stays on the active list with no timers and holds its skb and netdev references for good. The NULL skb this used to produce is handled on its own, as a mitigation for stable, by "can: j1939: do not pass a NULL skb to the socket layer". This patch is the protocol fix and deliberately has no Cc: stable. Found by AI-driven fuzzing built on top of syzkaller; the analysis was then checked by hand against the code. Measured on current net.git main with KASAN, over one vcan pair, on top of the mitigation: the offset is refused when it arrives ("data packet offset 16777215 is not below the 1171 packet(s) of this session"), the mitigation's NULL-skb branch is then never reached at all, and the EOMA guard above does fire for the cancelled sessions. No KASAN report and no panic. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Co-developed-by: Kapil Vaswani <kapil@presceralabs.ai> Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in> --- net/can/j1939/transport.c | 41 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index fa30273df326..187a7e6849eb 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1242,7 +1242,10 @@ static void j1939_session_completed(struct j1939_session *session) struct sk_buff *se_skb; if (!session->transmission) { - se_skb = j1939_session_skb_get(session); + /* the whole message, not the window the peer's last DPO + * happened to name + */ + se_skb = j1939_session_skb_get_by_offset(session, 0); if (!se_skb) { if (net_ratelimit()) netdev_warn(session->priv->ndev, @@ -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. + */ + netdev_info(session->priv->ndev, + "%s: 0x%p: EOMA on a cancelled session\n", + __func__, session); + return; + } + session->pkt.tx_acked = session->pkt.total; j1939_session_timers_cancel(session); /* transmitted without problems */ @@ -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; + + 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); + 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]; j1939_tp_set_rxtimeout(session, 750); -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset 2026-11-30 3:34 ` [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset Piyus Kedia @ 2026-11-30 3:51 ` sashiko-bot 2026-11-30 11:00 ` Piyus Kedia 2026-12-01 17:47 ` netdev-bot+sashiko 1 sibling, 1 reply; 8+ messages in thread From: sashiko-bot @ 2026-11-30 3:51 UTC (permalink / raw) To: Piyus Kedia, linux-can Cc: Marc Kleine-Budde, Oliver Hartkopp, Vincent Mailhol, Oleksij Rempel 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 <piyus@iiitd.ac.in> 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_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; > + > + 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 = session->state >= ... (false) netdev_info(...) j1939_tp_rxtimer() j1939_session_list_lock() hrtimer_start(&session->rxtimer, ...) __j1939_session_cancel() session->state = 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 = j1939_etp_ctl_to_packet(skb->data); > + session->pkt.dpo = dpo; > session->last_cmd = 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 >= J1939_SESSION_WAITING_ABORT is only checked inside the dpo >= session->pkt.total branch, an in-range DPO on a cancelled 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 >= 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. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261130033422.2143435-1-piyus@iiitd.ac.in?part=2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset 2026-11-30 3:51 ` sashiko-bot @ 2026-11-30 11:00 ` Piyus Kedia 0 siblings, 0 replies; 8+ messages in thread From: Piyus Kedia @ 2026-11-30 11:00 UTC (permalink / raw) To: sashiko-reviews Cc: linux-can, Marc Kleine-Budde, Oliver Hartkopp, Vincent Mailhol, Oleksij Rempel, Kapil Vaswani Hello, Thanks for the review! We tried to fix these issues in another version: https://lore.kernel.org/all/20261130105233.2512536-1-piyus@iiitd.ac.in/ Best, Piyus Kedia Kapil Vaswani On Mon, Nov 30, 2026 at 9:21 AM <sashiko-bot@kernel.org> wrote: > > 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 <piyus@iiitd.ac.in> > > 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_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; > > + > > + 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 = session->state >= ... > (false) > netdev_info(...) > j1939_tp_rxtimer() > j1939_session_list_lock() > hrtimer_start(&session->rxtimer, ...) > __j1939_session_cancel() > session->state = > 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 = j1939_etp_ctl_to_packet(skb->data); > > + session->pkt.dpo = dpo; > > session->last_cmd = 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 >= J1939_SESSION_WAITING_ABORT is only checked > inside the dpo >= session->pkt.total branch, an in-range DPO on a cancelled > 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 >= 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. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261130033422.2143435-1-piyus@iiitd.ac.in?part=2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset 2026-11-30 3:34 ` [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset Piyus Kedia 2026-11-30 3:51 ` sashiko-bot @ 2026-12-01 17:47 ` netdev-bot+sashiko 1 sibling, 0 replies; 8+ messages in thread From: netdev-bot+sashiko @ 2026-12-01 17:47 UTC (permalink / raw) To: piyus Cc: robin, o.rempel, socketcan, mkl, linux-can, kernel, linux-kernel, kapil, kuba 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two 2026-11-30 3:34 [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Piyus Kedia 2026-11-30 3:34 ` [PATCH net v4 1/2] can: j1939: do not pass a NULL skb to the socket layer Piyus Kedia 2026-11-30 3:34 ` [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset Piyus Kedia @ 2026-11-30 7:47 ` Oleksij Rempel 2026-11-30 10:57 ` Piyus Kedia 2 siblings, 1 reply; 8+ messages in thread From: Oleksij Rempel @ 2026-11-30 7:47 UTC (permalink / raw) To: Piyus Kedia Cc: Robin van der Gracht, Oliver Hartkopp, Marc Kleine-Budde, linux-can, kernel, linux-kernel, Kapil Vaswani Hi Piyus, On Mon, Nov 30, 2026 at 09:04:20AM +0530, Piyus Kedia wrote: > Posted as a series rather than as two independent patches because 2/2 does > not apply without 1/2 - sent separately, the second one fails to apply for > everyone and for the bots. If you would rather have 1/2 alone first and > 2/2 after it lands, say so and I will resend that way. Yes, please send 1/2 alone first. Please use "can" instead of "net" in the subject prefix, for example [PATCH can v5]. When you resend 1/2, you can add my Acked-by. Regards, Oleksij ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two 2026-11-30 7:47 ` [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Oleksij Rempel @ 2026-11-30 10:57 ` Piyus Kedia 0 siblings, 0 replies; 8+ messages in thread From: Piyus Kedia @ 2026-11-30 10:57 UTC (permalink / raw) To: Oleksij Rempel Cc: Robin van der Gracht, Oliver Hartkopp, Marc Kleine-Budde, linux-can, kernel, linux-kernel, Kapil Vaswani Hi Oleksij, Thanks for the review! Both patches are out; 1/2 first, as you asked: The NULL-skb mitigation: https://lore.kernel.org/all/20261130101232.2464732-1-piyus@iiitd.ac.in/ The DPO range check: https://lore.kernel.org/all/20261130105233.2512536-1-piyus@iiitd.ac.in/ The range check no longer depends on the mitigation - it can be applied before it, after it, or on its own. v4's 2/2 did not apply without 1/2, and that came from a single hunk in j1939_session_completed(): the message lookup there uses the window of the peer's last DPO rather than offset 0, which is a separate bug from the range check. We split it out, so it will follow as its own patch once the mitigation lands. The range check is also not the patch you saw in v4. The Sashiko AI review <https://lore.kernel.org/all/sashiko-outbox-240339@kernel.org/> found three real defects in it, and all three are fixed: it aborts with J1939_XTP_ABORT_BAD_EDPO_OFFSET rather than J1939_XTP_ABORT_FAULT, it deactivates the session instead of leaving it on the active list with no timers once the ETP.DT frames that follow the rejected DPO hit out_session_cancel, and it ignores a DPO on a session already waiting for its abort. The details are in the patch. Thanks, Piyus Kedia Kapil Vaswani On Mon, Nov 30, 2026 at 1:17 PM Oleksij Rempel <o.rempel@pengutronix.de> wrote: > > Hi Piyus, > > On Mon, Nov 30, 2026 at 09:04:20AM +0530, Piyus Kedia wrote: > > Posted as a series rather than as two independent patches because 2/2 does > > not apply without 1/2 - sent separately, the second one fails to apply for > > everyone and for the bots. If you would rather have 1/2 alone first and > > 2/2 after it lands, say so and I will resend that way. > > Yes, please send 1/2 alone first. > > Please use "can" instead of "net" in the subject prefix, for example > [PATCH can v5]. > > When you resend 1/2, you can add my Acked-by. > > Regards, > Oleksij ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-01 17:47 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-30 3:34 [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Piyus Kedia 2026-11-30 3:34 ` [PATCH net v4 1/2] can: j1939: do not pass a NULL skb to the socket layer Piyus Kedia 2026-11-30 3:34 ` [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset Piyus Kedia 2026-11-30 3:51 ` sashiko-bot 2026-11-30 11:00 ` Piyus Kedia 2026-12-01 17:47 ` netdev-bot+sashiko 2026-11-30 7:47 ` [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Oleksij Rempel 2026-11-30 10:57 ` Piyus Kedia
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox