Article View: linux.kernel.netdev
Article #23136[PATCH net v3] can: j1939: reject an out-of-range data packet offset
From: Piyus Kedia
Date: Thu, 26 Nov 2026 15:03
Date: Thu, 26 Nov 2026 15:03
145 lines
16382 bytes
16382 bytes
j1939_xtp_rx_dpo_one() takes the peer's data packet offset and stores it
without checking it against the session:
session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data);
j1939_session_skb_get_by_offset() then looks for a buffered skb at
pkt.dpo * 7, and j1939_xtp_rx_dat_one() copies into the session's skb at
that offset. An offset past the session's packet count has no skb behind
it, so the lookup returns NULL and the copy and the completion run on it.
Reject an offset that is not below session->pkt.total, and look the
completed receive message up at offset 0 rather than at whatever window
the peer's last DPO named.
Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
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>
---
v3: addresses the review of v2
(https://lore.kernel.org/r/sashiko-outbox-233959@kernel.org)
- a second out-of-range DPO no longer leaks the session. Both
findings there are right. j1939_session_cancel() does nothing once
the state is WAITING_ABORT, so on a second bad DPO the
j1939_session_timers_cancel() in front of it cancelled the 500 ms
timeout and nothing restarted it: the session stayed on
priv->active_session_list with no timers, holding its skb and its
netdev references, and unregister_netdevice() hangs behind that.
v3 deactivates the session in that case, the way
j1939_xtp_rx_rts_session_active() already does for a second RTS.
The first bad DPO still cancels and lets the abort go out, so the
change is confined to the session that was already dying.
- an EOMA no longer completes a cancelled session.
j1939_xtp_rx_eoma_one() checks the PGN and the size but not the
state, so an EOMA arriving inside the abort window completed the
session: with v2 looking the message up at offset 0 that handed the
aborted session's data to the receiving sockets and queued a second
J1939_ERRQUEUE_RX_ABORT. The delivery itself predates this series -
j1939_session_completed() always called j1939_sk_recv() - but v2 is
what made it reach a whole message, so the state test belongs here.
v2: rejected the offset instead of tolerating it, and looked the completed
message up at offset 0.
How this was found: an AI-driven fuzzing harness built on syzkaller,
developed jointly by Kapil Vaswani and myself, driving ETP sessions at
j1939 under KASAN on x86_64. The analysis and this changelog were
written with the assistance of a large language model and checked by
hand against the tree; the reproducer and the KASAN report in the v1
posting were produced by us. Both v3 changes come from addressing an
AI-generated review of v2 on the list, and each mechanism it described
was read in the tree before being acted on.
Link: https://lore.kernel.org/all/179553126874.3135.14817947057284289051@kernel.org/
net/can/j1939/transport.c | 49 ++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 8fcfd13e5e6f..54e7ae9a88c3 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1242,10 +1242,15 @@
struct sk_buff *se_skb;
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);
+ /* the whole message, not the window the peer's last DPO
+ * happened to name
+ */
+ se_skb = j1939_session_skb_get_by_offset(session, 0);
+ if (se_skb) {
+ /* distribute among j1939 receivers */
+ j1939_sk_recv(session->priv, se_skb);
+ consume_skb(se_skb);
+ }
}
j1939_session_deactivate_activate_next(session);
@@ -1418,6 +1423,18 @@
netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session);
+ if (session->state >= J1939_SESSION_WAITING_ABORT) {
+ /* This session has been cancelled and is waiting for its abort
+ * to go out. Completing it here would hand its data to the
+ * receiving sockets and queue a second RX_ABORT, so leave it to
+ * the abort path.
+ */
+ netdev_info(session->priv->ndev,
+ "%s: 0x%p: EOMA on a cancelled session\n",
+ __func__, session);
+ return;
+ }
+
session->pkt.tx_acked = session->pkt.total;
j1939_session_timers_cancel(session);
/* transmitted without problems */
@@ -1823,14 +1840,36 @@
struct sk_buff *skb)
{
const u8 *dat = skb->data;
+ unsigned int dpo;
if (j1939_xtp_rx_cmd_bad_pgn(session, skb))
return;
netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session);
+ dpo = j1939_etp_ctl_to_packet(dat);
+ if (dpo >= session->pkt.total) {
+ bool was_dying = session->state >= J1939_SESSION_WAITING_ABORT;
+
+ netdev_info(session->priv->ndev,
+ "%s: 0x%p: data packet offset %u is not below the %u packet(s) of this session\n",
+ __func__, session, dpo, session->pkt.total);
+ j1939_session_timers_cancel(session);
+ j1939_session_cancel(session, J1939_XTP_ABORT_FAULT);
+ if (was_dying)
+ /* The cancel above is a no-op once the state is
+ * WAITING_ABORT, so it does not restart the timeout
+ * this function just cancelled. Deactivate instead,
+ * as j1939_xtp_rx_rts_session_active() does, or the
+ * session stays on the active list with no timers and
+ * holds its skb and netdev references for good.
+ */
+ j1939_session_deactivate_activate_next(session);
+ return;
+ }
+
/* transmitted without problems */
- session->pkt.dpo = j1939_etp_ctl_to_packet(skb->data);
+ session->pkt.dpo = dpo;
session->last_cmd = dat[0];
j1939_tp_set_rxtimeout(session, 750);
--
2.43.0
Technical Details
Message-ID:
<20261126150339.2110025-1-piyus@iiitd.ac.in>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372182-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372182-linux-kernel-netdev=dewy.ru
From: piyus@iiitd.ac.in (Piyus Kedia)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3] can: j1939: reject an out-of-range data packet offset
Date: Thu, 26 Nov 2026 20:33:39 +0530
Organization: Usenet Network
Message-ID: <20261126150339.2110025-1-piyus@iiitd.ac.in>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="492819"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:kZfaeV88Hi5meZUB73zMxTMcB34= sha256:swklQ14WKh0sIYrswO+GCis+mJArEUC4YNBC0FJWqa8=
sha1:a6ln0YdmDUNdM84coQRT+g9S+MY= sha256:dSBQIxIXtTzZwv32ia7SMxRcvP9WfpRcsxTAweN138I=
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 A6A1F125EDC; Thu, 26 Nov 2026 18:04:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.75
X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
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,
URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=neutral
reason="invalid (public key: DNS error: query timed out)"
header.d=iiitd.ac.in
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 OgafLJvq6f9F;
Thu, 26 Nov 2026 18:04:13 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372182-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=iiitd.ac.in
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id C217C125EDF; Thu, 26 Nov 2026 18:03:58 +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 710623729F; Thu, 26 Nov 2026 15:03:50 +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=1795705429;
b=DbRaxxYief1mKSOZcS8ojgRjvxgT7qtLZUf3aWr9ebmNYUng8WpLTyNNSqVRlVB9tGyi
sXJ2nDrjvUPa/Lic+2vRD7OHDk5nEbZFOYhfFonH0Uce/Tq6ili5f1kdYrcIf4ElF2mdQ
9JVWR5uHZqnTmkJGbUVOM55SF0gPMi4y4cHvnZlDb1Ys+tZGmM3gxhJ9wQndmallI4VHS
tow3CsKSSZaDTUJB9JoxCo3f0aotq4nIyM4OeSNPCmnbW7vt8aGpR2+O5fb4wo6r0JXi1
k48whIpmHKoUjzssyBoqHlSC12+POibW2EwMyqJSfV7uiy+urp9K3Ybq+G4ggAD6bzQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795705429;
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=A0nHs2DHN4CrZLg8J552iINpEC7h8BMV5slPOBKdd7I=;
b=UutA99EAlr3c4JtyZLFN/dDV1U+fBiXFi32hDqPe+fbsvJvCs2wMPxi7RL2/RRjRbVSA
nog557d4j+EuUFgRiRK9UKJPEBt9nfK9o4QXigPV76yZYQgZz0XYMVEWJoqGKsQeusmMX
cggsqrgUCC0/FhyiO2w7lkO+Gyl8c7m94GjFXIW3H7YbwA2qnmnWY0feaZwVyWUzzW5b3
Mk2YMDGNcgZbLEOG4nNYk0pNuvpsmY4mXHJyF12kkaoefNuo9O682/Llur71KAzf8ZxMD
7k9RPn3OOpEps4yg4oPjL+lRY9LMHcfzCbvzy6h7iMf3UtmVnJksuK+psHHsxFShfxA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=XwK+P0aQ;
dmarc=none header.from=iiitd.ac.in;
spf=pass smtp.mailfrom=iiitd.ac.in;
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 880FD606A332;
Thu, 26 Nov 2026 15:03:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (1024-bit key) header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=XwK+P0aQ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.180
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795705428;
b=yGQYpw0Mtj4qVKH0zvoTVNyiDfHMcyHFRjW4xdh8ynrmfOlsK/rCx1oxRvxkSgw6fIes
iXu9BdXQNsZTpYWId8NyW6MF4WJJ3lc1QktVa3QIX0P/Fe0GNa5/PDenmdxS0uN3+X23S
IBmaF73eyodzz+X5XZCAyccKivIRS6WYEZ6RJHfG4/15EBOIBXeGgCguxL6U5KoMqoNmP
6l1bGOZ5fC95abIxNo7H8UBJdQMqRga1RBRPo7bWcaWpQ2L4iwvL7+TqGYD2nGFxdeyy5
FehDMxACLfwVX1+l0SJ4OvkMYfITwSmdzi6DBiNdPrLyssWwCXei4eDnJWe/385QxyQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795705428;
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=A0nHs2DHN4CrZLg8J552iINpEC7h8BMV5slPOBKdd7I=;
b=Oj8SzN1yFd7UDuzM0BLdMjq5gvTcmllKGSzXU61se4669Z/pdrC+1+Me0NikF9uAegFC
uzxJO30mj0342MFBxElGX/4YCT8DOhQf5P5bc5WmAPoprkJCOGHG2k4/W30egAImrD+9k
j76DFJN4aLh9HFf6O3TlsgQ/PCcNuZ3MkjRsIhjD0Q14wAt2wZgQgkD4+xfQUm1e4gVxe
IrZo/ehgbSb5+sQbcvqpV+30dPtXig3A32DfU0SAzkXQevKyvx2DnEabZF/xrXrMoCpJJ
orVwH8bE5wwn243IFQe0JOcGYCj9/RDOL72hXjR6ir4+zHtirgg1sM0Vhxukvq1iA5g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=none header.from=iiitd.ac.in;
spf=pass smtp.mailfrom=iiitd.ac.in;
dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=XwK+P0aQ;
arc=none smtp.remote-ip=209.85.214.180
X-Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180])
(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 E4505606A31C
for <netdev@vger.kernel.org>; Thu, 26 Nov 2026 15:03:46 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4505606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in
X-Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2f052ae3c86so38844845ad.1
for <netdev@vger.kernel.org>; Thu, 26 Nov 2026 07:03:46 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=iiitd.ac.in; s=google; t=1795705426; x=1796310226; 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=A0nHs2DHN4CrZLg8J552iINpEC7h8BMV5slPOBKdd7I=;
b=XwK+P0aQ+Rp31QXWvDcqbUfM+HK9MCbbBjOXaSxSKoyI+MU00NKDs5WBIOGhY9E1qp
EQaDUBnD/jk83Laus9blkljVsfUxthsfTXpsawPmCTmqWaqq+z1pcENJFmGbgjGKmZBf
3xH6J79M17d0C0BMBT7JtlujhM+d3f0uXi0G4=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795705426; x=1796310226;
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=A0nHs2DHN4CrZLg8J552iINpEC7h8BMV5slPOBKdd7I=;
b=VIoiKGd9TrEoXEDVsG7Q++mspqf2OpLDBkcypZFHV1BnFEG2P0bOJE1OuM5F5fVbzX
HdA/PMLQh+wJdRXZzdOvBjAGEqYKpPQq6M/l79jlNcwYWXR8dKUa/C1ysLjp8l/982qJ
MAf145/Bg+9jyJqmmWygXyx5v1XgyLJ9EVq0VDbUXFfvUqTESCsRzFoxoZP8/QwhoeTm
Lf+0Q1nWjYTiYedpphNDNb7e/9pX42BEDtkcrjJazFfSbhfQgleoJqFQmlumj5mIAPnB
4GE9r4SXf5ziQhpCp5amMpcAjTj3a7gFQXMLP4W5mq3+VIeWfIoU8PN06AiqyX4CLlyg
r3kQ==
X-Forwarded-Encrypted: i=1; AL+hErH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.28.1795705426236;
Thu, 26 Nov 2026 07:03:46 -0800 (PST)
X-Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160])
by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f0c42b1sm104226565ad.17.2026.11.26.07.03.42
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 26 Nov 2026 07:03:45 -0800 (PST)
X-Cc: kernel@pengutronix.de,
netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
kapil@presceralabs.ai
X-Mailer: git-send-email 2.34.1
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