Re: [PATCH net v2] can: j1939: reject an out-of-range data packet offset
From: Piyus Kedia
Date: Sun Nov 29 2026 - 22:35:05 EST
Hi Oleksij,
Thanks - splitting it that way is right, and 1/2 is your hunk, with only
the netdev_warn() rewrapped to fit.
the series: https://lore.kernel.org/all/20261130033422.2143435-1-piyus@xxxxxxxxxxx/
1/2 the NULL check, the one for stable:
https://lore.kernel.org/all/20261130033422.2143435-2-piyus@xxxxxxxxxxx/
2/2 the DPO range check:
https://lore.kernel.org/all/20261130033422.2143435-3-piyus@xxxxxxxxxxx/
I posted them as a series rather than as two independent patches because 2/2
does not apply without 1/2 - sent separately, the second one fails to apply
for you and for the bots. Stable still takes only 1/2, which carries the one
Cc: stable. If you would rather have 1/2 on its own first and 2/2 after it
lands, say so and I will resend that way.
I checked the two things in your version that I could have got wrong by
copying it, and both hold: EPROTO as a positive value is right, because
socket.c assigns serr->ee.ee_errno = session->err and
j1939_session_destroy() turns a non-zero err on a receive session into
J1939_ERRQUEUE_RX_ABORT; and net_ratelimit() needs no new include in
transport.c. No locking added around session->err, as you said.
Testing, on net.git main 9437ee8b6cf6 with KASAN and kasan_multi_shot=1,
one vcan pair, the same reproducer each time:
unpatched BUG: KASAN: null-ptr-deref in j1939_sk_recv+0xd4/0x3c0, then
"Kernel panic - not syncing: Fatal exception in interrupt".
The deref is in softirq context, so the machine dies rather
than surviving the report - which is also why only one report
prints despite kasan_multi_shot.
1/2 only 0 KASAN reports, no panic, and the new warning four times,
once per round of the reproducer - so the path is still being
reached and is now handled rather than not triggered.
1/2 + 2/2 0 KASAN reports, no panic, and the offset is refused when it
arrives - "data packet offset 16777215 is not below the 1171
packet(s) of this session". 1/2's warning then never fires at
all, which is the layering you asked for: 2/2 stops the
NULL skb existing and 1/2 is the backstop. The EOMA
guard below fired twice in that run, so it is not
speculative.
You were right that the range check needs more in the session code. Two
things 2/2 had to add:
- an EOMA can still arrive for a session already waiting for its abort to
go out. Completing it then hands its data to the receiving sockets and
queues a second RX_ABORT, so j1939_xtp_rx_eoma_one() now leaves a
cancelled session to the abort path.
- j1939_session_cancel() is a no-op once the state is WAITING_ABORT, so on
a second out-of-range DPO it would not restart the timeout the range
check had just cancelled. I deactivate the session instead, the way
j1939_xtp_rx_rts_session_active() does; otherwise it stays on the active
list with no timers and keeps its skb and netdev references.
Recipients are now scripts/get_maintainer.pl for net/can/j1939/transport.c -
linux-can and the CAN maintainers, no netdev. I also dropped
stable@xxxxxxxxxxxxxxx from the recipient list; the Cc: stable tag on 1/2 is
what the stable rules ask for.
> Several other people have sent fixes for the same crash.
If one of those is further along, say so and we will drop ours rather than
add noise.
Thanks and regards,
Piyus Kedia
Kapil Vaswani