mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xue Boyang <fuchen.dust@gmail.com>
To: Robin van der Gracht <robin@protonic.nl>,
	Oleksij Rempel <o.rempel@pengutronix.de>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
	kernel@pengutronix.de, linux-can@vger.kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH net] can: j1939: fix null-ptr-deref in j1939_session_completed()
Date: Tue, 17 Nov 2026 04:35:15 -0600	[thread overview]
Message-ID: <20261117103516.535910-1-fuchen.dust@gmail.com> (raw)

j1939_session_completed() looks up the receive skb using the session's
current data packet offset and passes the result to j1939_sk_recv()
without checking it. If no queued skb covers that offset, the lookup
returns NULL and receive-side processing can dereference it.

An inconsistent ETP session offset can leave the receive buffer lookup
unsatisfied when the session completes. The DPO receive path does not
validate the offset against the receive buffer, so completion cannot
assume that the lookup always succeeds.

Check the returned skb before distributing the message and releasing
the lookup reference. Keep session deactivation and activation of the
next queued session unconditional, so a missing receive buffer does
not leave the completed session active. This also matches the NULL
handling already used by j1939_simple_txnext().

AI assistance was used to analyze the bug and prepare this patch.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Cc: stable@vger.kernel.org
Signed-off-by: Xue Boyang <fuchen.dust@gmail.com>
---

Notes (j1939-null-submit):
    Based on mainline commit 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4.
    The affected transport.c and socket.c are unchanged from the original
    local report baseline daf677c2c6449011ee695d55b48b5b2977a36f88.
    
    Validation:
    - Built net/can/j1939/ with W=1 on x86_64, CONFIG_CAN_J1939=m,
      CONFIG_KASAN=y and CONFIG_WERROR=y; no build warnings or errors.
    - A temporary userspace harness executed the extracted completion
      function with stubbed dependencies. It checked missing-buffer receive,
      normal receive reference balancing, and transmit completion. The old
      function passed NULL to the delivery stub; the patched function did
      not, while retaining the completion-helper call.
    - This revision has not been boot-tested or run against a CAN interface.
      The harness is not an end-to-end kernel regression test.
    
    AI assistance (OpenAI coding assistant) was used for source analysis,
    commit-message preparation, and build and isolated-function checks.
    No packet-level reproducer or triggering sequence is included.

 net/can/j1939/transport.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 8fcfd13e5e6f8..ecf7f245f8378 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1244,8 +1244,10 @@ 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) {
+			j1939_sk_recv(session->priv, se_skb);
+			consume_skb(se_skb);
+		}
 	}
 
 	j1939_session_deactivate_activate_next(session);

base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4

                 reply	other threads:[~2026-11-17 10:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261117103516.535910-1-fuchen.dust@gmail.com \
    --to=fuchen.dust@gmail.com \
    --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®