From: Chaosheng Qu <quchaosheng000406@163.com>
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>
Cc: kernel@pengutronix.de, linux-can@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH net v7 3/4] can: j1939: drop the message when the reassembled skb is gone
Date: Sun, 08 Nov 2026 09:34:23 +0800 [thread overview]
Message-ID: <179410166346.60581.12668181404057434786@163.com> (raw)
In-Reply-To: <179410166344.60581.3898011861151549156@163.com>
From ba4643113b5f6ad2b53b98dae1c25d5465d4d0c0 Mon Sep 17 00:00:00 2001
From: Chaosheng Qu <quchaosheng000406@163.com>
Date: Sun, 8 Nov 2026 09:22:29 +0800
Subject: [PATCH net v7 3/4] can: j1939: drop the message when the reassembled
skb is gone
j1939_session_completed() takes the skb for the completed message and hands
it to j1939_sk_recv() without checking the result. j1939_session_skb_get()
returns NULL when the offset it computes lands past the end of the queue.
The offset is "pkt.dpo * 7", and pkt.dpo is bounded when an EDPO is
received,
so this should not happen. Guard it anyway: a NULL dereference in the
receive path is a kernel panic, while a dropped message is a lost datagram.
j1939_simple_txnext(), the only other caller of j1939_session_skb_get(),
already checks for NULL.
Signed-off-by: Chaosheng Qu <quchaosheng000406@163.com>
---
net/can/j1939/transport.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index b0e62822b56e..5f05c15114ce 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1269,9 +1269,19 @@ 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);
+
+ /* Defense in depth: pkt.dpo is range checked when an EDPO is
+ * received, so the lookup should always find the skb. Drop the
+ * message rather than hand a NULL skb to j1939_sk_recv() if the
+ * offset arithmetic ever regresses. The only other caller of
+ * j1939_session_skb_get(), j1939_simple_txnext(), already does
+ * this.
+ */
+ if (se_skb) {
+ /* distribute among j1939 receivers */
+ j1939_sk_recv(session->priv, se_skb);
+ consume_skb(se_skb);
+ }
}
j1939_session_deactivate_activate_next(session);
--
2.43.0
next prev parent reply other threads:[~2026-11-11 6:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 1:34 [PATCH net v7 0/4] can: j1939: fix the abort timer and bound EDPO Chaosheng Qu
2026-11-08 1:34 ` [PATCH net v7 4/4] can: j1939: reject a CTS that names more packets than the message has Chaosheng Qu
2026-11-12 21:49 ` netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
2026-11-08 1:34 ` [PATCH net v7 1/4] can: j1939: arm the abort timer under the session list lock Chaosheng Qu
2026-11-12 21:49 ` netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
2026-11-08 1:34 ` Chaosheng Qu [this message]
2026-11-12 21:49 ` [PATCH net v7 3/4] can: j1939: drop the message when the reassembled skb is gone netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
2026-11-13 7:25 ` Oleksij Rempel
2026-11-13 8:54 ` Chaosheng Qu
2026-11-08 1:34 ` [PATCH net v7 2/4] can: j1939: validate the EDPO packet number Chaosheng Qu
2026-11-12 21:49 ` netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
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=179410166346.60581.12668181404057434786@163.com \
--to=quchaosheng000406@163.com \
--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®