* Re: [PATCH net] can: j1939: fix null-ptr-deref in j1939_session_completed()
2026-11-17 10:35 [PATCH net] can: j1939: fix null-ptr-deref in j1939_session_completed() Xue Boyang
@ 2026-11-20 10:35 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 10:35 UTC (permalink / raw)
To: fuchen.dust
Cc: robin, o.rempel, mkl, socketcan, kernel, linux-can, linux-kernel,
netdev, stable, kuba
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
^ permalink raw reply [flat|nested] 2+ messages in thread