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, netdev@vger.kernel.org,
kernel@pengutronix.de, linux-kernel@vger.kernel.org,
kapil@presceralabs.ai, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, stable@vger.kernel.org
Subject: Re: [PATCH net v2] can: j1939: reject an out-of-range data packet offset
Date: Sat, 28 Nov 2026 19:27:26 +0000 [thread overview]
Message-ID: <179589404616.3135.8619866704479644293@kernel.org> (raw)
In-Reply-To: <20261124181757.638280-1-piyus@iiitd.ac.in>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
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).
- [Medium] In net/can/j1939/transport.c, the new out-of-range check in
j1939_xtp_rx_dpo_one() cancels the session with J1939_XTP_ABORT_FAULT.
- [Medium] The new reject path in j1939_xtp_rx_dpo_one() calls
j1939_session_timers_cancel() and then j1939_session_cancel() without…
- [Low] The commit message's reason why rejecting an out-of-range DPO
loses nothing is wrong at the boundary.
--
can: j1939: reject an out-of-range data packet offset
This patch makes j1939_xtp_rx_dpo_one() reject an ETP DPO whose offset is
not below pkt.total, and cancel the session when that happens. It also
changes j1939_session_completed() to look up the received message at
offset 0 instead of at the DPO window. The NULL test stays there as a
second guard.
Link: https://lore.kernel.org/all/179553126874.3135.14817947057284289051@kernel.org/
> An out-of-range offset has no other legitimate effect either: every data
> packet that follows is rejected by the "packet > session->pkt.total" test
> in
> j1939_xtp_rx_dat_one(), which computes packet from the same dpo, so the
> session can never complete with data.
[Severity: Low]
Does this hold at the boundary? j1939_xtp_rx_dat_one() does:
packet = (dat[0] - 1 + session->pkt.dpo);
if (packet > session->pkt.total ||
(session->pkt.rx + 1) > session->pkt.total) {
With dpo == total and dat[0] == 1, packet == total passes the > test. The
packet is only rejected later, when j1939_session_skb_get_by_offset()
returns NULL.
With dpo == total and dat[0] == 0 (the sequence number is never checked
for zero), packet works out to total - 1. That passes the test, the
lookup finds the message skb, and the payload is copied into the last
7-byte slot.
The new dpo >= session->pkt.total check closes both cases, so the code
itself is fine. Could the commit message describe the bounds check in
j1939_xtp_rx_dat_one() more precisely? Accepting sequence number 0 may
also be worth a separate look.
> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> index 8fcfd13e5e6f8..225467843e428 100644
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
[ ... ]
> @@ -1823,14 +1828,25 @@ 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) {
> + 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: Medium]
Is J1939_XTP_ABORT_FAULT the right abort reason here? Its description in
enum j1939_xtp_abort is "Maximal retransmit request limit reached", and
j1939_xtp_abort_to_errno() maps it to ENOTRECOVERABLE.
The file already defines a code for this exact condition, and nothing in
net/can/j1939/ uses it yet:
J1939_XTP_ABORT_BAD_EDPO_OFFSET = 12,
/* Bad EDPO offset */
j1939_xtp_abort_to_errno() maps that one to EPROTO.
__j1939_session_cancel() passes the chosen code to the peer and to the
error queue:
session->err = j1939_xtp_abort_to_errno(priv, err);
...
j1939_xtp_tx_abort(priv, &session->skcb,
!session->transmission,
err, session->skcb.addr.pgn);
So the TP.Conn_Abort frame tells the peer reason 5 instead of 12. The
J1939_ERRQUEUE_RX_ABORT queued for this receive session reports
ENOTRECOVERABLE.
Documentation/networking/j1939.rst lists "Invalid PGN or offset in
EDPO/ECTS" under EPROTO. It keeps ENOTRECOVERABLE for the retransmit
limit. The DPO check in j1939_xtp_rx_cmd_bad_pgn() also uses the specific
J1939_XTP_ABORT_BAD_EDPO_PGN.
The commit message gives j1939_xtp_rx_dat_one() as the precedent. Its
FAULT, though, covers data packet numbers, not EDPO offsets. Would
J1939_XTP_ABORT_BAD_EDPO_OFFSET fit better here?
[Severity: Medium]
Can this path lose the abort timeout? j1939_xtp_rx_dpo() still finds
sessions in J1939_SESSION_WAITING_ABORT, because
j1939_session_get_by_addr_locked() matches only on address and direction.
Suppose a second out-of-range DPO arrives after the first one cancelled
the session, but before the echo of our abort frame is processed:
first bad DPO
j1939_session_timers_cancel()
j1939_session_cancel()
j1939_tp_set_rxtimeout(session, J1939_XTP_ABORT_TIMEOUT_MS)
__j1939_session_cancel()
session->state = J1939_SESSION_WAITING_ABORT
second bad DPO
j1939_session_timers_cancel() <- cancels the abort rxtimer
j1939_session_cancel()
state < J1939_SESSION_WAITING_ABORT is false, so no re-arm
j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT)
The WAITING_ABORT branch of j1939_tp_rxtimer() is the only timer-driven
cleanup for this session. j1939_xtp_tx_abort() ignores allocation and
can_send() failures, so the abort frame may never be sent or echoed. In
that case, does the session stay on active_session_list, holding its
references and receive skb? It would only go away on a new RTS from the
peer, a peer abort, or the interface going down.
Each such DPO also queues another J1939_ERRQUEUE_RX_ABORT, because that
call in j1939_session_cancel() is unconditional when session->sk is NULL.
j1939_xtp_rx_rts_session_active() already works around the same problem
for a second RTS:
} else if (session->state == 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);
}
Before this patch, a DPO in this state went through
j1939_tp_set_rxtimeout(session, 750), which always re-armed the timer.
Does the new path need a similar state check or forced deactivation?
> + return;
> + }
> +
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124181757.638280-1-piyus%40iiitd.ac.in
next prev parent reply other threads:[~2026-11-28 19:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 18:17 [PATCH net v2] can: j1939: reject an out-of-range data packet offset Piyus Kedia
2026-11-28 19:27 ` netdev-bot+sashiko [this message]
[not found] <sashiko-outbox-233959@kernel.org>
2026-11-26 15:03 ` 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=179589404616.3135.8619866704479644293@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--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=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=piyus@iiitd.ac.in \
--cc=robin@protonic.nl \
--cc=socketcan@hartkopp.net \
--cc=stable@vger.kernel.org \
/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