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
Subject: Re: [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset
Date: Tue, 01 Dec 2026 17:47:06 +0000 [thread overview]
Message-ID: <179614722601.3142.6142667587633925470@kernel.org> (raw)
In-Reply-To: <20261130033422.2143435-3-piyus@iiitd.ac.in>
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
next prev parent reply other threads:[~2026-12-01 17:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179614722601.3142.6142667587633925470@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=kapil@presceralabs.ai \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=piyus@iiitd.ac.in \
--cc=robin@protonic.nl \
--cc=socketcan@hartkopp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox