Article View: linux.kernel.netdev
Article #17788[PATCH net] can: j1939: fix null-ptr-deref in j1939_session_completed()
From: Xue Boyang
Date: Tue, 17 Nov 2026 10:35
Date: Tue, 17 Nov 2026 10:35
66 lines
13542 bytes
13542 bytes
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
Technical Details
Message-ID:
<20261117103516.535910-1-fuchen.dust@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365167-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365167-linux-kernel-netdev=dewy.ru
From: fuchen.dust@gmail.com (Xue Boyang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] can: j1939: fix null-ptr-deref in j1939_session_completed()
Date: Tue, 17 Nov 2026 04:35:15 -0600
Organization: Usenet Network
Message-ID: <20261117103516.535910-1-fuchen.dust@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2304037"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:QKAcvK9b5L4iie7Eq/WwVoZAqKk= sha256:GJfkzlVtg7KR6q3UiYCAYMH8pI6DqSTaMJpM1odTDhc=
sha1:/zQyjOWUqGWvsXmn9SVfnaMyUAc= sha256:y1AtUY8PHSZNWjbARd84KSuDfhiUYCnqO9NARKdCHRU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 44EED114EFF; Tue, 17 Nov 2026 13:36:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 9O0QVCZkxN7G;
Tue, 17 Nov 2026 13:36:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-365167-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 14C75114EF7; Tue, 17 Nov 2026 13:36:21 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 8F3C234586; Tue, 17 Nov 2026 10:35:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794911726;
b=bJ1SWbFobt2jai/HGqSJ4qtBzhZjiSRXzGZ6G5bVNOHDzMI+rP2C06G4FzVr/VWd3VmP
V/r84achHir1HSOXvDcJq/bpOtBOVig7VPOYabCrWxow1+PJ5rNEUwEMjsdeFrCxIMwub
rfNIYUQWxfy39c+/HmCA0oFLezfrC94ci2RoGdTb5eyGqXRSDJXgrf07u5YaeExv1mT18
GBz4CwQ1R7LkQaAEt7QwaT08WCzcduMpjiUrNZ4hGl/KHJtzi+fLIrb4TG9hnqCxp8KSj
bqYU1+rZxfh+gStIsUbmrhyNOhCTt+TAEFPDZyGFVuZQAbDaH+WgPuarsJ/aI4ojQdA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794911726;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=RuyZ4/NgPAofSNXbBjGZkZZB9QA0/aMDca1cWrs9WFg=;
b=T+Ulrzu5NQ7gpZ29dD7RvPk3tggzPN4wpNtMgsomgbokq/48S+vUVld/J1oRw8kgz3jm
GQ9Rt7t44SeOpI/6XJoHS8fvTAdjdxjlI4DjRcJ4uD7IoJ/2GWW2px2CEC5EugM/Y5M0H
cB2NWEUK4xhj2rhF++rhkO59Heq3gug8XgUqfwfHjAa08d5dOSLy/5If0tJWjyO9pyH7H
vC2WtWMKPdtbYzwLt6uAIUf610lOg6Wbq7vaCwqxg/QxRzdOiXNwPQ/85abQOCi4Lt4My
06PlO/eQk/00Ws6ZUz9WKH2hANVRuAkhdb0B3Fr2dyV8WYbsmDolNk0KyM/j0VA7nuA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=RvFXG8Wj;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id B0A21606A899;
Tue, 17 Nov 2026 10:35:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=RvFXG8Wj
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.170
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794911725;
b=4Dm3lo3n0YaXVQLa8UF1y6SmISHW1tKq2OXt4i0XJnold+BH0l5+ElsQlxl8KFhuVg9W
kEz1O8FOrCEQz6tJupJXwdzSUP9kttvIcf8YL2BZ9dkKGEefn0/WBxUdQJg0n9eiHYN5D
B82e9JAOWIxaKlvr2Ft6jc5I+uhlIp8tOXLE3bHvoCTlfGygXxehpJ/aTGVy88xwBTB+O
7EHtkFMfxELSFocdOt/sBZywrVp7hG7y3+2e6msA5T690TSIKS0kxucehZpb6PdeSy3tY
a1wFLONRLg+Z6J3Uv4aVauyFs1/y0bLshWKzXsiCRM03Jt//VZv2zG0hW3zYNvipeQw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794911725;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=RuyZ4/NgPAofSNXbBjGZkZZB9QA0/aMDca1cWrs9WFg=;
b=DyR9vY1o13fW/0nqV4TCwHMjJ25i+z1era6pbMEe+KpxxzvZF2azTNfVcyzf34TlOwpo
0WhG53hNp2/+d6Dtei3DQzA/LNz4YwgVNedJvOdsWsCg1wCgoy2vhzTLppOy7u9LAdWN5
TNXKqoOgWM7hSqTQ55cE+iB2sd8RGfJnHCX01vWIuy3N1sdyHf0QjCOgPbMc+o7cLpRwM
hNuuFMAs6PExoK1twmFzZ5+rODPu3VyMgBYh0DFZ1PyBJHhWTEcCa0pDfcAD33T9BegIS
ox9uuG9+L19u7zB+RR8y6YL+MLniSMABn0FGDM37Fzw9Tu0J1VAgF80T+7JWtJz9CJQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=RvFXG8Wj;
arc=none smtp.remote-ip=209.85.215.170
X-Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC22606A893
for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 10:35:25 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7EC22606A893
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-cc751eddf25so3472296a12.3
for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 02:35:25 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794911725; x=1795516525; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=RuyZ4/NgPAofSNXbBjGZkZZB9QA0/aMDca1cWrs9WFg=;
b=RvFXG8WjjKnTMy0oENVxlESIdVeF6WKEdiNDXunqUUCkkvQvKrb1EXZV9xmGB08fS3
GKBazE4QO+VsYoH2bZHPTRAvxGv4vB31iiEM/JNLZ+0ti7GUimE9nOHnUyWU5J+oxavn
Usr7arx6vVCNPU0a0O/knm5dDC0CPAlKkRY+lI4/OwzgM+9n7B61/hvjrn9xMv/3vf41
MaBmT7CMkPOuR1+8iWIJEUqhi1dzJ4sKDGGwtXG7WmbGSjsvwMs5u+yaDQ6lUdy31rP6
SPBda7tpj6zYniwGPOHetVokVPwpScwCsEiYqFE0y6oRJCAuK3KxHcP9sXQUmXeWuTBZ
3neg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794911725; x=1795516525;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=RuyZ4/NgPAofSNXbBjGZkZZB9QA0/aMDca1cWrs9WFg=;
b=GvaKiZiThq9w8bqmUOOD0P4/yfHgziCZ8iyON8gd9KSGmPLuDoXuPNlwHhgKU5gjPF
Uvht8tJgZtMt777FUjA3sC7XAcG8FTgPgjf4W0i7WzufEso0nR9jnDPCSC/RkQKgSM+7
oNU/SMSQbc6Ca2y28PbCuGtDAp4HLY5vDvYW2WnXxgh7Ewb/aJkc6TYMwgtyznbz51kK
JWptWUNcr2Pf2Z3FzAMYlYY6nGC4AwWC3wTicxutos+fclR8isNp9DUb1yyWrSINIOk4
EhvkVg4p7WPyh06yhN6oMgSEHMD9kFguMR/RwhNIqojKaKts7TQs5zA+lQNIRJ47uPDq
A8ZQ==
X-Forwarded-Encrypted: i=1; AL+hErHqI4kncdpWW21WsQVnnBbbohGg29nLEz+77g8UNqcB9Hdz+pwbYyzE3PwPI0qIs2GY9fOKceA=@vger.kernel.org
X-Gm-Message-State: APuU4Z91A3T52z8yaIeeavRfkUmCWfGHEW0lx7yMeTLAqai54sx4xOe8
yO5TMAAjx5QyGxPdIMHwj1PgrUTP35+eAEjlts0ypqkI0kEBnz75u/yF
X-Gm-Gg: AZFdTZfCJSHUZZtTLmk/t4G27cQLunDq2/fmP+/4mife63qVqtVoznIU8aKkXD4hzSG
G/DUU7djMZNN3c3dExt9MHMIjvnUIp3BNRHh+wEbpKwbpKMx6w2NmzHDTT8eMqq3NOtHqmlxCAr
01VHmp0UBPIwL7nspgIhno5ByQMcoQZoRDr4FN+XJVVoSQCIBkhz3ySDwW20t2BTiClytpkfe1n
gjwKDJDsFx4HwR+9mTJZ9Ld/Y6c2D5r/2c32pURzTMIDEXRLintyGYej+m6nNQdSWc8xfjG4HJy
lQm94LNPpj9Vq+0yFP9uqwS1XzRSH51DstSzh5IeknfBgGt4dRaZ+c6KoIU4KmtUl9fY26u8BFb
x9+I+mmOacRFcV+MK3iV/zSjNkG/UW9KTK0NzbkTkcafZU4HyE6njP9qcAkprkxAuBW9QrakCbk
QqDHXbeXL51K9mnKxqIjNDEJhgIqcv6x0izBhA3Ttxi4rXI1AE7ln5UtBJ9E4ewgaq+lwCSZEZ8
caQ5NVGtH8WqgQ65O+FW1edjM4yweDJpgg1I8xuhOQmgg/3INoJ4EIHCKP8wZn9b5b+r3BpZjx6
x6ugFWbYYWWKVMaYxBzLrbMCzdmGSiusO1ql3qopve+e
X-Received: by 2002:a17:90b:1f86:b0:3ac:7556:8ee0 with SMTP id 98e67ed59e1d1-3b1b0b666c5mr13803607a91.19.1794911724811;
Tue, 17 Nov 2026 02:35:24 -0800 (PST)
X-Received: from gmail.com ([116.162.234.168])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b3abeaf532sm3518806a91.14.2026.11.17.02.35.20
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 17 Nov 2026 02:35:24 -0800 (PST)
X-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
X-Mailer: git-send-email 2.53.0
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list