[PATCH can v5] can: j1939: do not pass a NULL skb to the socket layer
From: Piyus Kedia
Date: Mon Nov 30 2026 - 05:12:42 EST
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. The
dereference happens in the receive softirq, so it is fatal:
BUG: KASAN: null-ptr-deref in j1939_sk_recv+0xd4/0x3c0
Read of size 8 at addr 0000000000000018 by task repro/9528
<IRQ>
j1939_sk_recv+0xd4/0x3c0
j1939_xtp_rx_eoma+0x207/0x300
j1939_tp_recv+0x64c/0xa10
j1939_can_recv+0x51a/0x640
can_receive+0x19e/0x2a0
__netif_receive_skb+0x120/0x270
process_backlog+0x427/0xd50
net_rx_action+0x3f7/0x870
handle_softirqs+0x1e5/0x6a0
</IRQ>
netif_rx+0x89/0xa0
can_send+0x71f/0x7e0
raw_sendmsg+0x9ed/0xab0
Kernel panic - not syncing: Fatal exception in interrupt
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. Those checks need further changes in the
session code, so they follow as their own patch once this one is in.
Found by AI-driven fuzzing built on top of syzkaller; the analysis was
then checked by hand against the code. Measured on current net.git main
with KASAN and kasan_multi_shot=1, over one vcan pair, with the same
reproducer each time: without this patch the report above and the panic;
with it no report and no panic, and the new warning fires once per round
of the reproducer, so the path is still being reached and is now handled.
Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Suggested-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
Acked-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
---
This is 1/2 of the v4 series resent on its own, as asked, with the "can"
subject prefix. The DPO range check that was 2/2 there will follow as its
own patch once this one lands; it does not apply without this one.
Changes in v5:
- sent on its own instead of as 1/2 of a series, as asked
- [PATCH can] rather than [PATCH net], as asked
- Oleksij's Acked-by added; the paragraph about the protocol fix now says
it follows after this patch rather than alongside it
- no other change: the hunk is byte-for-byte v4's 1/2
v4 series: https://lore.kernel.org/all/20261130033422.2143435-1-piyus@xxxxxxxxxxx/
v4 1/2: https://lore.kernel.org/all/20261130033422.2143435-2-piyus@xxxxxxxxxxx/
v3: https://lore.kernel.org/all/20261124181757.638280-1-piyus@xxxxxxxxxxx/
net/can/j1939/transport.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 8fcfd13e5e6f..fa30273df326 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1243,9 +1243,17 @@ 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) {
+ 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);
+ }
}
j1939_session_deactivate_activate_next(session);
base-commit: 9437ee8b6cf607e883b36e44bd755968daaebd48
--
2.34.1