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

From: Piyus Kedia

Date: Tue Nov 24 2026 - 13:18:52 EST


Thank you - you are right on both counts, and the first one is the more
useful kind of wrong to be told about: the patch stopped the crash while the
commit message named a trigger that cannot happen, and the cause was left in
place. v2 fixes the cause and says what actually happens.

v2 is posted as a separate thread:

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

The changelog is under its --- line, with a Link: back to this thread.

Point by point.


1. Is this the actual trigger?

> For a receive session, the queue does not seem able to be empty while the
> session is alive.
> That means the splat needs an ETP RTS, then an ETP DPO with an out-of-range
> offset, then an EOMA.
> Could the commit message describe the DPO trigger instead?

It is not the trigger, and yours is. Checked against net.git:
j1939_session_new() queues one skb, j1939_session_fresh_new() sizes it to the
whole message with skb_put_zero(), and only j1939_session_skb_drop_old() -
which returns early below two queued skbs - and j1939_session_destroy()
remove any. So the queue is never empty for a live receive session, and
"an EOMA for a connection whose data packets never arrived" describes nothing
real. What fails is where the getter looks:

offset_start = session->pkt.dpo * 7;

and for a receive session pkt.dpo is written only by j1939_xtp_rx_dpo_one(),
straight from the wire.

The reproducer sends precisely the sequence you describe - an ETP RTS, an ETP
DPO carrying 0xffffff, 0x100000, 0x010000 and 0x001000 in turn, then an EOMA -
and its own comments in the report thread say that pkt.dpo is taken unchecked
and that the lookup then matches no skb. The analysis was there; it did not
reach the commit message I wrote. That is on me, and v2's message is written
around the DPO.

> 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.

v2 does both, because they answer different questions.

dpo = j1939_etp_ctl_to_packet(dat);
if (dpo >= session->pkt.total) {
netdev_info(...);
j1939_session_timers_cancel(session);
j1939_session_cancel(session, J1939_XTP_ABORT_FAULT);
return;
}

That is the cause, and the shape is j1939_xtp_rx_dat_one()'s: it already
refuses a packet number it cannot place and cancels the session, and the
packet numbers it checks are counted from this very offset, so checking one
and not the other was the gap. dpo >= pkt.total is exactly the condition
under which dpo * 7 lands at or past total_message_size, since
pkt.total = (len + 6) / 7.

An out-of-range offset has no legitimate use either way: every data packet
that follows is rejected by the "packet > session->pkt.total" test in
j1939_xtp_rx_dat_one(), which derives packet from the same dpo, so such a
session can never complete with data. Cancelling it costs a correct peer
nothing.

And in j1939_session_completed() the lookup is now at offset 0:

se_skb = j1939_session_skb_get_by_offset(session, 0);

The DPO window says where the next data packet belongs; at completion it is
the whole message that goes to the sockets, which for a receive session is
the single skb at offset 0. The NULL test stays, now as a second guard: if
it ever fires, an skb has gone missing from a queue this file does not touch
while the session lives, which would be a kernel bug rather than something a
peer did.

> 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().

Correct, and v1's commit message said otherwise. j1939_simple_txnext() is
the other caller and it does test the result ("if (!se_skb) return 0;").
That sentence is gone from v2 rather than repaired, since the patch no longer
rests on what other callers do.


2. When se_skb is NULL, the session still ends as a success

> Is user space told anything at all?
> Could it also mention that error-queue users are left with a transfer that
> never completes or aborts?

Nothing is told, exactly as you describe. j1939_session_deactivate_locked()
leaves session->err at 0, j1939_session_destroy() queues
J1939_ERRQUEUE_RX_ABORT only when err is set, so a socket on the error queue
sees RX_RTS and RX_DPO and then neither the data nor an abort; and no abort
frame goes to the peer, because j1939_session_cancel() is not called on that
path. v2's commit message states this in those terms.

I have not made the guard report an error, and the reason is the first point:
with the offset checked where it arrives, that path is no longer reachable
from the wire, and the peer now gets the abort frame and the socket the
RX_ABORT from j1939_session_cancel() in j1939_xtp_rx_dpo_one() instead -
which is the right place for it, since that is where the protocol was
violated. Setting session->err in j1939_session_completed() would also write
a field that __j1939_session_cancel() writes under
active_session_list_lock, and I would rather not add that to a path that
should now be unreachable.

If you would still prefer the guard to abort rather than to drop quietly, say
so and I will respin; it is a small change, but it is one I would rather not
make blind.


Thanks again for both - the first changed the patch, and the second changed
what the commit message claims.

pw-bot: cr