From: Piyus Kedia <piyus@iiitd.ac.in>
To: Robin van der Gracht <robin@protonic.nl>,
Oleksij Rempel <o.rempel@pengutronix.de>,
Oliver Hartkopp <socketcan@hartkopp.net>,
Marc Kleine-Budde <mkl@pengutronix.de>,
linux-can@vger.kernel.org, netdev@vger.kernel.org
Cc: kernel@pengutronix.de, linux-kernel@vger.kernel.org,
Kapil Vaswani <kapil@presceralabs.ai>,
Piyus Kedia <piyus@iiitd.ac.in>,
stable@vger.kernel.org
Subject: [PATCH net] can: j1939: do not pass a NULL session skb to the socket layer
Date: Mon, 23 Nov 2026 20:06:25 +0530 [thread overview]
Message-ID: <20261123143625.4021586-2-piyus@iiitd.ac.in> (raw)
In-Reply-To: <20261123143625.4021586-1-piyus@iiitd.ac.in>
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 <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
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
next prev parent reply other threads:[~2026-11-23 14:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 14:36 [BUG] can: j1939: NULL dereference when a peer completes a session with no data queued Piyus Kedia
2026-11-23 14:36 ` Piyus Kedia [this message]
2026-11-24 14:41 ` [PATCH net] can: j1939: do not pass a NULL session skb to the socket layer netdev-bot+sashiko
2026-11-24 18:18 ` Piyus Kedia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123143625.4021586-2-piyus@iiitd.ac.in \
--to=piyus@iiitd.ac.in \
--cc=kapil@presceralabs.ai \
--cc=kernel@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=robin@protonic.nl \
--cc=socketcan@hartkopp.net \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®