Re: [PATCH net v2] can: j1939: reject an out-of-range data packet offset

From: Oleksij Rempel

Date: Sun Nov 29 2026 - 11:03:13 EST


Hi Piyus,

On Thu, Nov 26, 2026 at 08:33:39PM +0530, Piyus Kedia wrote:
> 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.

Thank you for the reproducer.

As far as I can see, the range check needs more changes in the session
code. I would like to keep the fix for stable small.

Could you send the NULL check in j1939_session_completed() as a separate
patch for stable first? The range check for the DPO can follow as its
own patch.

For the stable patch, I would expect something like this (untested):

if (!session->transmission) {
se_skb = j1939_session_skb_get(session);
if (!se_skb) {
if (net_ratelimit())
netdev_warn(session->priv->ndev, "%s: 0x%p: no skb found for completed session\n",
__func__, session);
session->err = EPROTO;
} else {
/* distribute among j1939 receivers */
j1939_sk_recv(session->priv, se_skb);
consume_skb(se_skb);
}
}

Other places in transport.c also set session->err without
active_session_list_lock. As far as I can see, no lock is needed here.

Please say in the commit message that this is only a mitigation. Then
the review bots should not ask for the protocol checks in this patch.
Something like this:

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

Check for a NULL skb in j1939_session_completed() and end the session
with EPROTO, so that sockets reading the error queue get an RX abort.
Print a rate-limited warning, because a peer can cause the missing skb.

A peer can send an ETP DPO at or beyond the end of the message. When
the session completes after that, j1939_session_completed() finds no
skb and passes NULL to j1939_sk_recv(), which dereferences it.

This is only a mitigation, and it leaves the transport protocol alone
on purpose. The DPO is still not checked when it arrives, and no abort
frame is sent to the peer. These checks follow as a separate patch.

<how it was found and how you tested it>

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Cc: stable@xxxxxxxxxxxxxxx

Several other people have sent fixes for the same crash.

Please send CAN patches only to linux-can and the CAN maintainers, not
to netdev.

pw-bot: cr

Regards,
Oleksij