[PATCH net v9 3/4] can: j1939: drop the message when the reassembled skb is gone
From: Chaosheng Qu
Date: Wed Nov 11 2026 - 05:46:45 EST
From: Chaosheng Qu <quchaosheng000406@xxxxxxx>
Check the skb that j1939_session_completed() hands to j1939_sk_recv(),
which dereferences oskb->sk. A NULL here is the last step of the EDPO
out-of-range sequence fixed by the previous patch; the bounds check makes
the lookup succeed, but the dereference should not depend on that.
Drop the message instead, which is what the other caller of
j1939_session_skb_get(), j1939_simple_txnext(), already does.
Assisted-by: LLM
Signed-off-by: Chaosheng Qu <quchaosheng000406@xxxxxxx>
---
net/can/j1939/transport.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 258009182..fc2840f33 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1281,9 +1281,17 @@ 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.
+ */
+ 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