mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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
Cc: kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	Kapil Vaswani <kapil@presceralabs.ai>
Subject: [PATCH net v4 1/2] can: j1939: do not pass a NULL skb to the socket layer
Date: Mon, 30 Nov 2026 09:04:21 +0530	[thread overview]
Message-ID: <20261130033422.2143435-2-piyus@iiitd.ac.in> (raw)
In-Reply-To: <20261130033422.2143435-1-piyus@iiitd.ac.in>

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@pengutronix.de>
Cc: stable@vger.kernel.org
Co-developed-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
 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


  reply	other threads:[~2026-11-30  3:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  3:34 [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Piyus Kedia
2026-11-30  3:34 ` Piyus Kedia [this message]
2026-11-30  3:34 ` [PATCH net v4 2/2] can: j1939: reject an out-of-range data packet offset Piyus Kedia
2026-11-30  7:47 ` [PATCH net v4 0/2] can: j1939: the NULL session skb, split in two Oleksij Rempel
2026-11-30 10:57   ` 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=20261130033422.2143435-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=o.rempel@pengutronix.de \
    --cc=robin@protonic.nl \
    --cc=socketcan@hartkopp.net \
    /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®