All of lore.kernel.org
 help / color / mirror / Atom feed
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 v2] can: j1939: reject an out-of-range data packet offset
Date: Wed, 25 Nov 2026 18:18:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-233959@kernel.org> (raw)
In-Reply-To: <20261124181757.638280-1-piyus@iiitd.ac.in>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] can: j1939: session leak in j1939_xtp_rx_dpo_one() on repeated
  invalid DPO
- [Medium] can: j1939: aborted session completed in
  j1939_session_completed() on EOMA
--

commit e965a3918b3f2f0306bb887a70504c5f042637e7
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() and looks up the completed receive message skb at
offset 0 in j1939_session_completed().

Link: https://lore.kernel.org/all/179553126874.3135.14817947057284289051@kernel.org/

> 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
> @@ -1242,10 +1242,15 @@ static void j1939_session_completed(struct j1939_session *session)
>  	struct sk_buff *se_skb;
>  
>  	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);
> +		/* 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) {
> +			/* distribute among j1939 receivers */
> +			j1939_sk_recv(session->priv, se_skb);
> +			consume_skb(se_skb);
> +		}
>  	}
>  
>  	j1939_session_deactivate_activate_next(session);

[Severity: Medium]
Can an incoming EOMA frame still complete a receive session that
j1939_xtp_rx_dpo_one() already cancelled?

After j1939_session_cancel() transitions the session to
J1939_SESSION_WAITING_ABORT and queues J1939_ERRQUEUE_RX_ABORT, the
session stays on priv->active_session_list until the abort frame or the
500 ms rxtimer deactivates it.  If an EOMA frame arrives during that
window, j1939_xtp_rx_eoma() finds the session and calls
j1939_xtp_rx_eoma_one() -> j1939_session_completed() without checking
session->state or session->err.  Because j1939_session_completed() now
fetches offset 0 instead of pkt.dpo * 7, it delivers the aborted
session's skb to receiving sockets via j1939_sk_recv() and queues a
second J1939_ERRQUEUE_RX_ABORT when the session is destroyed.

> @@ -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);
> +		return;
> +	}

[Severity: High]
Does a second out-of-range DPO frame leak the session and its netdev
references?

On the first invalid DPO, j1939_session_cancel() sets session->state to
J1939_SESSION_WAITING_ABORT and starts the 500 ms rxtimer:

net/can/j1939/transport.c:j1939_session_cancel() {
	if (session->state >= J1939_SESSION_ACTIVE &&
	    session->state < J1939_SESSION_WAITING_ABORT) {
		j1939_tp_set_rxtimeout(session, J1939_XTP_ABORT_TIMEOUT_MS);
		__j1939_session_cancel(session, err);
	}
}

If a second invalid DPO arrives while the session is still in
J1939_SESSION_WAITING_ABORT (for example, when the peer source address is
not local so the looped-back abort frame is not received locally, or when
back-to-back DPO frames are already queued), j1939_session_timers_cancel()
cancels the 500 ms rxtimer and j1939_session_cancel() does not restart it.
The session then stays on priv->active_session_list with no running
timers, leaking the session, its receive skb, and its netdev_hold()
references so unregister_netdevice() hangs after the socket closes.

Should this check for J1939_SESSION_WAITING_ABORT and call
j1939_session_deactivate_activate_next(session), the same way
j1939_xtp_rx_rts_session_active() does?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124181757.638280-1-piyus@iiitd.ac.in?part=1

  reply	other threads:[~2026-11-25 18:18 UTC|newest]

Thread overview: 6+ 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-25 18:18 ` sashiko-bot [this message]
2026-11-26 15:03   ` Piyus Kedia
2026-11-28 19:27 ` netdev-bot+sashiko
2026-11-29 16:02 ` Oleksij Rempel
2026-11-30  3:34   ` 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=sashiko-outbox-233959@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.