Article View: linux.kernel.netdev
Article #19762Re: [PATCH net] can: j1939: fix null-ptr-deref in j1939_session_completed()
From: netdev-bot+sashiko
Date: Fri, 20 Nov 2026 10:35
Date: Fri, 20 Nov 2026 10:35
154 lines
13457 bytes
13457 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch fixes the symptom (the NULL deref in
j1939_session_completed()) but leaves in place the root cause that the…
- [Low] The commit message understates how reachable the bug is.
--
can: j1939: fix null-ptr-deref in j1939_session_completed()
This patch adds a NULL check in j1939_session_completed() on the skb
returned by j1939_session_skb_get(). The check runs before the skb is
passed to j1939_sk_recv() and consume_skb(). Session deactivation and
activation of the next queued session still happen unconditionally.
> 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.
[Severity: Low]
Could the commit message say more precisely how this is reached? As far
as I can tell, any node on the CAN bus can trigger the NULL dereference
in the unpatched code:
1. Start a valid ETP transfer to a local address that has a bound J1939
socket.
2. Send all the data packets.
3. Send an ETP.CM_DPO with dpo * 7 >= total_message_size. This can be
sent before the receiver's txtimer sends EOMA, or after EOMA is sent
but before its echo comes back.
The DPO is stored without any check:
j1939_tp_cmd_recv()
j1939_xtp_rx_dpo(priv, skb, false)
j1939_xtp_rx_dpo_one()
session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data);
Then the EOMA echo completes the session:
j1939_tp_cmd_recv()
j1939_xtp_rx_eoma(priv, skb, false)
j1939_xtp_rx_eoma_one()
j1939_session_completed()
j1939_sk_recv(priv, NULL)
j1939_sk_recv_one()
if (oskb->sk == &jsk->sk)
A matching socket must exist, because j1939_session_tx_eoma() won't send
EOMA otherwise. So the loop body in j1939_sk_recv() always runs.
This is a remotely triggerable crash. Would it help stable backporters
and security triage if the commit message said so and included the
trigger sequence?
> 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);
[Severity: High]
When se_skb is NULL here, doesn't this drop a fully received message
without any notice and then complete the session as if it succeeded?
session->err is still 0 on this path. j1939_session_destroy() only
queues RX_ABORT when err is set:
net/can/j1939/transport.c:j1939_session_destroy() {
...
} else if (session->err) {
j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
}
...
}
That has these effects:
- Errqueue listeners that already got J1939_ERRQUEUE_RX_RTS and
J1939_ERRQUEUE_RX_DPO never get a final event.
- Documentation/networking/j1939.rst describes J1939_EE_INFO_RX_ABORT as
the event for an aborted reception, and it is never sent here.
- The peer has already been sent EOMA and thinks the transfer succeeded.
- The only trace is a netdev_dbg() in
j1939_session_skb_get_by_offset().
The other RX lookup site treats the same condition as a fault and
cancels the session:
net/can/j1939/transport.c:j1939_xtp_rx_dat_one() {
...
se_skb = j1939_session_skb_get_by_offset(session, packet * 7);
if (!se_skb) {
netdev_warn(priv->ndev, "%s: 0x%p: no skb found\n", __func__,
session);
goto out_session_cancel;
}
...
}
The root cause named in the commit message is still in place.
j1939_xtp_rx_dpo_one() stores the peer's DPO without checking it against
pkt.total, total_message_size or the CTS window:
/* transmitted without problems */
session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data);
J1939_XTP_ABORT_BAD_EDPO_OFFSET and J1939_XTP_ABORT_EDPO_OUTOF_CTS are
defined, but nothing sends them.
Also, j1939_session_skb_get() looks up the RX skb using pkt.dpo * 7:
offset_start = session->pkt.dpo * 7;
return j1939_session_skb_get_by_offset(session, offset_start);
An RX session only has a single skb, allocated in
j1939_session_fresh_new() and covering [0, total_message_size). So this
lookup only fails when the peer has sent an out-of-range DPO.
Would it be better to validate the DPO in j1939_xtp_rx_dpo_one() and
abort with J1939_XTP_ABORT_BAD_EDPO_OFFSET? Another option is to look up
the RX skb without using dpo.
If the NULL check stays, could this branch at least set session->err, or
cancel the session with an abort? That way the failure is reported
instead of the session completing as a success.
The commit message also doesn't mention this change in behaviour.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117103516.535910-1-fuchen.dust%40gmail.com
Technical Details
Message-ID:
<179517095327.3136.15773180395913177394@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367870-linux-kernel-netdev=dewy.ruReferences:
<20261117103516.535910-1-fuchen.dust@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367870-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] can: j1939: fix null-ptr-deref in j1939_session_completed() Date: Fri, 20 Nov 2026 10:35:53 +0000 Organization: Usenet Network Message-ID: <179517095327.3136.15773180395913177394@kernel.org> References: <20261117103516.535910-1-fuchen.dust@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3135356"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:b7TSoAeJUkNwCRHVxvmAzL6lSvg= sha256:GEBN9oFQ5sWY/zcp5jOkg5EcAzjxNDSHLVUq+3awu8w= sha1:b3nqmXTCO3jSCj++PD3CJFOrSNg= sha256:Ck//MiXBLPf+MxriWUHSY5EQt4kJgmICrceuAVV1MLk= 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 065EF115961; Fri, 20 Nov 2026 13:36:22 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org 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 REDfCnp4H0fh; Fri, 20 Nov 2026 13:36:18 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367870-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id B8F5611595C; Fri, 20 Nov 2026 13:36:09 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 8726C1A1BE6; Fri, 20 Nov 2026 10:35:58 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1795170956; b=xY1xc1OMroyfcEPLzirfyYq5WRsrJ5i1Qd2zlhmRl+pSm3yICGDWQDLUZCN8GW940z2B qgloB7eVc1dqFwjCrwLBNLC1X8EYKrd8XLVmwSWqzahqf+NUau0SlzNshT5W9RNBRkcgi QcCvza/z8l5oMtqWsN5+W+W6bHbOiNkmNfNA9Ham5k+0i8NwzziQaomGWXE7Hiu/Zs5cK 9xQIm8Xei/GNiu7R6nvB19YPUS8e5yd8BNTzBKsMsOhXLNbAy6VxH9h1DwVA7j90iXrMW abbQiJMOzLk9rNAz6Tr6W6G5oqw4Kjhi5jxX0v44jcNnnc+qFFU9M1dDnrh7Z3/Hl/A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795170956; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=/6h6kjv6DzEWQopVb09U0/FFqFvd3pADhGDuIrBHyOg=; b=4pzyKAv9z3NWHI+5+paiByVMvsK9Pfal6aUrI3+5Xgbidwpao8MjgUBpCWmIK24MsbjE 9SL3Js9qOgs+yBrehJy2aebzDL0wASlZDiDI9+1PTOOfcRtSgl1UruSKDj3wTdmPJNa41 1AwQZh1kgsEX52JwxW2xvGnOCFrerPhKUkTsSFl8hYrsG31su0zChDthXm4n7F/rUrFqs XTZWfoqq8wztD8vqrQobE8ASYNObm/dmirnw32lFQuodHMjx4UwKTZ4RBNi15LhwuJumI tIi03uyTVbBbDrwCO/n4agqqbTmcDjTkJX3vpD6EVgSILBWUlXnrA2oVVqYKx0+yLcA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HqyRHFzw; arc=fail 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 2563260A260F; Fri, 20 Nov 2026 10:35:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HqyRHFzw X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795170955; b=Z//q4O1tJUFdy7ivc5jUQoJwcOM0lRQGcLNCsA1p57lbgC0kUdV8zsvnXV6dfWPgLZA8 X9kr2JMgUCfznE1HfBg0us1+b7B2LkYkizYCx6AkAZa0Q8NIdIEVksra8u4vYTU5pg1OB zZw5hw+n/j8MzNWyTmAHe4iaYI0lc1i5kKRJHhfPmvmH38jTrLhbzoqyrP4tRM5SmyOH8 nZOFVu0M7SSjZ3frwrMM+PcAVZnZzzjZGSO049UXqp2PpVebDha9TqggDJMWbU4ElF8ah AFqA66j65Ld6EsOJ97CYu0LFmjwLh6W034KeUU4AxMBmbgw09UabPI/ONHi26J55qJw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795170955; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=/6h6kjv6DzEWQopVb09U0/FFqFvd3pADhGDuIrBHyOg=; b=2a3TjFr29x3Zu/7NCM5i8rrXSRB570B1oR5Y4dDmlg5DgBX4FRO+fSfQb9XIFLZC/m0+ V+qkH0WQxhgW88K9dG7z9thUrSc4GVSppB0GyZu8SCzdbLZfv6ztUJzSNQmEJ1NV/bKLP eGWAIoYA5J6Mzu5FNfY0fvIc9Cux1Vcx8bGueUt0amkI6oWs1ciTD5muU2xOZjtO0x/pt MB3QWwIzX4cdB7UOzNQN3X1Z524QRJD5c05Ufol9zZ65hRTi85YMdvkjNytEsme6oVAFi tTkrHKBrRHMv/ov2Cvd0cSJrBqwEZg++jqluq17RbIYMeM5tr98nA/oLERy7kaxsIVA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HqyRHFzw; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44521606A32C; Fri, 20 Nov 2026 10:35:54 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B46C91F000C6; Fri, 20 Nov 2026 10:35:53 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795170954; bh=/6h6kjv6DzEWQopVb09U0/FFqFvd3pADhGDuIrBHyOg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=HqyRHFzwZF9szW0t2JBSkCp90F5fgPsEoHBe1RkkBwJ3jzeRdsRPbN0d8Mu5kwB8T 1FFb5VpXCPP+R6aOKTOif3hJmZ8HbPRxgzqGb/cn2L8k+s7DPq3E3s93dLI9JUCHH5 sSnwM8S9X2GyxMvajOknN15mgdxDQMijGMGVlVC3BtfiYdDW6lxZXMzUAS2Z1sIC8r eCbRLalOBjmCce17J2m2088uFXy3cITA5jKeoyVZnjjysfKJETtJ7oPyaxvJLnEMtg MLzenA08P7p2Jxm4wc7szkt/HeghRrGlbNCAZYo6wwdWElwRGaWJI7QoZcfAuqPyr7 yanY0PLezT6OA== X-Cc: robin@protonic.nl, o.rempel@pengutronix.de, mkl@pengutronix.de, socketcan@hartkopp.net, kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org, kuba@kernel.org X-In-Reply-To: <20261117103516.535910-1-fuchen.dust@gmail.com> X-sashiko-severity: High 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