mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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, stable@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH net] can: j1939: do not pass a NULL session skb to the socket layer
Date: Tue, 24 Nov 2026 14:41:08 +0000	[thread overview]
Message-ID: <179553126874.3135.14817947057284289051@kernel.org> (raw)
In-Reply-To: <20261123143625.4021586-2-piyus@iiitd.ac.in>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · 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] The commit message gives the wrong cause for the NULL, and the
  real cause is not fixed.
- [Low] When se_skb is NULL, the new branch in j1939_session_completed()
  still ends the receive session as a success.

--

can: j1939: do not pass a NULL session skb to the socket layer

This patch adds a NULL check on the skb returned by
j1939_session_skb_get() in j1939_session_completed(). A receive session
that completes without a matching skb no longer passes NULL to
j1939_sk_recv(). The session is still deactivated as before.

> j1939_session_skb_get() returns the skb covering the session's current
> offset, or NULL when the queue holds none, and j1939_sk_recv_one() then
> dereferences it on its first statement:

[ ... ]

> A peer reaches this by completing a transport session that has no data
> queued - an EOMA for a connection whose data packets never arrived:

[ ... ]

> Test the skb before using it, as the two other callers of the getter in
> this file already do (j1939_session_tx_dat() returns -ENOBUFS, and
> j1939_xtp_rx_dat_one() warns and cancels the session).

[Severity: Medium]
Is this the actual trigger?  For a receive session, the queue does not
seem able to be empty while the session is alive.

j1939_xtp_rx_rts_session_new()->j1939_session_fresh_new()->
j1939_session_new() queues one skb:

net/can/j1939/transport.c:j1939_session_new() {
    ...
	skb_queue_head_init(&session->skb_queue);
	skb_queue_tail(&session->skb_queue, skb_get(skb));
    ...
}

j1939_session_fresh_new() then sizes that skb to the full message:

	/* alloc data area */
	skb_put_zero(skb, size);

Only j1939_session_skb_drop_old() and j1939_session_destroy() remove skbs
from the queue. drop_old() returns early when fewer than two are queued.

j1939_session_skb_get() looks up the skb by the DPO window, not by
offset 0:

	offset_start = session->pkt.dpo * 7;
	return j1939_session_skb_get_by_offset(session, offset_start);

So for a receive session it returns NULL only when pkt.dpo * 7 is at or
past total_message_size.

For a receive session, pkt.dpo is only written in j1939_xtp_rx_dpo_one().
That function stores the 24-bit value from the peer without checking it
against pkt.total:

	/* transmitted without problems */
	session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data);

j1939_xtp_rx_dat_one() does reject packet > session->pkt.total before it
does its lookup.

That means the splat needs an ETP RTS, then an ETP DPO with an
out-of-range offset, then an EOMA. An EOMA alone with dpo == 0 finds the
zero-filled skb. It then delivers zero or partly filled data to the
matching sockets, both before and after this patch.

Could the commit message describe the DPO trigger instead?

Would it also make sense to fix the cause? j1939_xtp_rx_dpo_one() could
reject or cancel the session when the DPO is >= pkt.total. Another option
is to fetch the RX message at offset 0 in j1939_session_completed(). The
NULL check would then stay as a second guard.

One more point: j1939_session_tx_dat() and j1939_xtp_rx_dat_one() both
call j1939_session_skb_get_by_offset(), not j1939_session_skb_get(). The
only other caller of j1939_session_skb_get() appears to be
j1939_simple_txnext().

> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> index 8fcfd13e5e6f8..af54e6a6bd714 100644
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
> @@ -1243,9 +1243,11 @@ 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) {
> +			/* distribute among j1939 receivers */
> +			j1939_sk_recv(session->priv, se_skb);
> +			consume_skb(se_skb);
> +		}
>  	}
>  
>  	j1939_session_deactivate_activate_next(session);

[Severity: Low]
When se_skb is NULL, the receive session still ends as a success. Is
user space told anything at all?

j1939_session_deactivate_locked() sets session->state to
J1939_SESSION_DONE and leaves session->err at 0. j1939_session_destroy()
only queues an abort for a receive session when err is set:

	} else if (session->err) {
			j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
	}

Sockets using the error queue have already seen J1939_ERRQUEUE_RX_RTS and
J1939_ERRQUEUE_RX_DPO for this session. After that they get neither the
data nor J1939_ERRQUEUE_RX_ABORT.

The peer gets no abort frame either, because j1939_session_cancel() is
never called on this path.

j1939_xtp_rx_dat_one() handles a NULL lookup differently. It jumps to
out_session_cancel, which sets err, sends an abort, and later queues
RX_ABORT.

The commit message says cancelling was left out on purpose. Could it also
mention that error-queue users are left with a transfer that never
completes or aborts?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123143625.4021586-2-piyus%40iiitd.ac.in

      reply	other threads:[~2026-11-24 14:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 14:36 [BUG] can: j1939: NULL dereference when a peer completes a session with no data queued Piyus Kedia
2026-11-23 14:36 ` [PATCH net] can: j1939: do not pass a NULL session skb to the socket layer Piyus Kedia
2026-11-24 14:41   ` netdev-bot+sashiko [this message]

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=179553126874.3135.14817947057284289051@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=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --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

all inboxes | Powered by JetHome®