Re: [PATCH net] can: j1939: do not pass a NULL session skb to the socket layer

From: netdev-bot+sashiko

Date: Tue Nov 24 2026 - 09:41:21 EST


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