j1939_session_completed() hands the session's skb to the socket layer without checking that there is one: 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); } j1939_session_skb_get() returns the skb covering the session's current offset, or NULL when the queue holds none, and j1939_sk_recv_one() then dereferences it on its first statement: if (oskb->sk == &jsk->sk) sk_buff::sk sits at offset 0x18, which is the address in the report below. consume_skb() tolerates NULL, so the dereference is the only fault. A peer reaches this by completing a transport session that has no data queued - an EOMA for a connection whose data packets never arrived: BUG: KASAN: null-ptr-deref in j1939_sk_recv_one+0x34/0x170 Read of size 8 at addr 0000000000000018 by task syz-executor j1939_sk_recv_one net/can/j1939/socket.c:318 j1939_sk_recv net/can/j1939/socket.c:363 j1939_session_completed net/can/j1939/transport.c:1247 j1939_xtp_rx_eoma_one net/can/j1939/transport.c:1424 j1939_xtp_rx_eoma net/can/j1939/transport.c:1439 j1939_tp_cmd_recv net/can/j1939/transport.c:2153 j1939_tp_recv net/can/j1939/transport.c:2201 j1939_can_recv net/can/j1939/main.c:108 Test the skb before using it, as the two other callers of the getter in this file already do (j1939_session_tx_dat() returns -ENOBUFS, and j1939_xtp_rx_dat_one() warns and cancels the session). Nothing is warned about here: a session completed with no data queued is a peer's protocol error rather than a kernel one, and a netdev_warn() on this path would let a peer flood the log. Cancelling the session instead of dropping the completion may be the more correct protocol behaviour; that is left alone deliberately, so this stays a fix for the dereference. How this was found: by AI-driven fuzzing built on top of syzkaller. Its analysis was checked by hand against the code, the fault was reproduced on net.git main under KASAN, and the patched kernel is clean on the same reproducer with ordinary J1939 transport sessions unaffected. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Cc: stable@vger.kernel.org Signed-off-by: Kapil Vaswani Signed-off-by: Piyus Kedia --- net/can/j1939/transport.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index 8fcfd13e5e6f..af54e6a6bd71 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1243,9 +1243,11 @@ 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) { + /* distribute among j1939 receivers */ + j1939_sk_recv(session->priv, se_skb); + consume_skb(se_skb); + } } j1939_session_deactivate_activate_next(session); -- 2.34.1