From: sashiko-bot@kernel.org
To: "Piyus Kedia" <piyus@iiitd.ac.in>, linux-can@vger.kernel.org
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH net v3] can: j1939: reject an out-of-range data packet offset
Date: Fri, 27 Nov 2026 15:03:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-237670@kernel.org> (raw)
In-Reply-To: <20261126150339.2110025-1-piyus@iiitd.ac.in>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] can: j1939: session leak on ETP.DT after bad DPO in
j1939_xtp_rx_dpo_one()
- [Medium] can: j1939: unlocked was_dying check in
j1939_xtp_rx_dpo_one() leaks session
- [Medium] can: j1939: j1939_xtp_rx_dpo_one() and rx_dat_one() accept
aborted sessions
- [Medium] can: j1939: duplicate RX_ABORT and wrong abort code in
j1939_xtp_rx_dpo_one()
- [Medium] can: j1939: unlocked state check before timer cancel in
j1939_xtp_rx_eoma_one()
- [Low] can: j1939: commit message misstates NULL skb copy and omits
EOMA state check
--
commit 42dc0f1ef825e9a1fb806f7836041c2eaa69424c
Author: Piyus Kedia <piyus@iiitd.ac.in>
can: j1939: reject an out-of-range data packet offset
This commit rejects out-of-range ETP data packet offsets in
j1939_xtp_rx_dpo_one(), ignores EOMA on cancelled sessions in
j1939_xtp_rx_eoma_one(), and looks up the completed receive skb at offset 0
in j1939_session_completed().
Link: https://lore.kernel.org/all/179553126874.3135.14817947057284289051@kernel.org/
> 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 and the copy and the completion run on it.
>
> Reject an offset that is not below session->pkt.total, and look the
> completed receive message up at offset 0 rather than at whatever window
> the peer's last DPO named.
[Severity: Low]
Does the commit message accurately describe what happens when
j1939_session_skb_get_by_offset() returns NULL, and should it also mention
the state check in j1939_xtp_rx_eoma_one()?
j1939_xtp_rx_dat_one() already checks for a NULL se_skb and jumps to
out_session_cancel before copying, so only j1939_session_completed() ran on
a NULL skb. Also, the new J1939_SESSION_WAITING_ABORT guard in
j1939_xtp_rx_eoma_one() and the second-DPO deactivation are only described
below the "---" tearline, which git am strips.
> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> index 8fcfd13e5e6f8..54e7ae9a88c3e 100644
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
[ ... ]
> @@ -1418,6 +1423,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 */
[Severity: Medium]
Can j1939_tp_rxtimer() race with this unlocked session->state check before
j1939_session_timers_cancel() cancels rxtimer?
CPU0 CPU1
j1939_xtp_rx_eoma_one()
if (session->state >=
J1939_SESSION_WAITING_ABORT)
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_sk_errqueue(..., RX_ABORT)
j1939_session_timers_cancel()
j1939_session_completed() <-- delivers aborted data and queues 2nd RX_ABORT
If rxtimer expires on CPU1 between the state check and
j1939_session_timers_cancel(), CPU0 cancels the 500 ms abort timer and calls
j1939_session_completed(), handing the cancelled session's skb at offset 0
to receiving sockets and queueing a second J1939_ERRQUEUE_RX_ABORT when
j1939_session_destroy() sees session->err set.
> @@ -1823,14 +1840,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)
> + /* The cancel above is a no-op once the state is
> + * WAITING_ABORT, so it does not restart the timeout
> + * this function just cancelled. 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 an ETP.DT data frame arriving right after a rejected out-of-range DPO
still leak the session?
In ETP, the sender transmits ETP.DT packets immediately 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 rxtimer, and the function returns before setting session->last_cmd to
J1939_ETP_CMD_DPO. When the following ETP.DT packet arrives in
j1939_xtp_rx_dat_one(), switch (session->last_cmd) hits default 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 timer, and
j1939_session_cancel() does not restart it because session->state is already
J1939_SESSION_WAITING_ABORT. The session stays on
priv->active_session_list with no timers, leaking its queued skb and netdev
reference and causing unregister_netdevice() to hang once the socket closes.
[Severity: Medium]
Can sampling was_dying without active_session_list_lock before
j1939_session_timers_cancel() also leak the session if rxtimer fires
concurrently?
CPU0 CPU1
j1939_xtp_rx_dpo_one()
was_dying = session->state >=
J1939_SESSION_WAITING_ABORT;
/* 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()
if (was_dying) /* false */ <-- skips deactivate, session leaked
CPU0 cancels the 500 ms abort timer started by CPU1, j1939_session_cancel()
does not re-arm it because the state is now J1939_SESSION_WAITING_ABORT, and
the stale was_dying value skips j1939_session_deactivate_activate_next().
[Severity: Medium]
Does calling j1939_session_cancel() when was_dying is true queue a duplicate
J1939_ERRQUEUE_RX_ABORT, and should the abort reason be
J1939_XTP_ABORT_BAD_EDPO_OFFSET instead of J1939_XTP_ABORT_FAULT?
In j1939_session_cancel(), j1939_sk_errqueue(session,
J1939_ERRQUEUE_RX_ABORT) runs outside the session->state <
J1939_SESSION_WAITING_ABORT check, so calling j1939_session_cancel() when
was_dying is true emits an extra RX_ABORT before j1939_session_destroy()
emits another. Also, transport.c defines J1939_XTP_ABORT_BAD_EDPO_OFFSET
(12, "Bad EDPO offset") specifically for an invalid ETP.CM_DPO offset,
whereas J1939_XTP_ABORT_FAULT (5) is for exceeding the retransmit limit.
> +
> /* 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]
Should j1939_xtp_rx_dpo_one() and j1939_xtp_rx_dat_one() reject frames when
session->state >= J1939_SESSION_WAITING_ABORT, just as
j1939_xtp_rx_eoma_one() now does?
If a peer sends an in-range DPO during the 500 ms abort window,
j1939_xtp_rx_dpo_one() updates session->pkt.dpo and session->last_cmd,
extends rxtimer to 750 ms, and queues J1939_ERRQUEUE_RX_DPO after RX_ABORT.
Subsequent data packets in j1939_xtp_rx_dat_one() then write into the
cancelled session's skb and can schedule txtimer to transmit CTS or EOMA for
the aborted session, or call j1939_session_completed() directly on a final
BAM packet and deliver the aborted message at offset 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126150339.2110025-1-piyus@iiitd.ac.in?part=1
next prev parent reply other threads:[~2026-11-27 15:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 15:03 [PATCH net v3] can: j1939: reject an out-of-range data packet offset Piyus Kedia
2026-11-27 15:03 ` sashiko-bot [this message]
2026-11-27 16:04 ` netdev-bot+sashiko
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=sashiko-outbox-237670@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=piyus@iiitd.ac.in \
--cc=sashiko-reviews@lists.linux.dev \
--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