[PATCH net v4 1/2] can: j1939: do not pass a NULL skb to the socket layer
From: Piyus Kedia
Date: Sun Nov 29 2026 - 22:34:38 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. These checks follow as a separate patch.
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>
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Piyus Kedia <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);
--
2.34.1