Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexander Hölzl" <alexander.hoelzl@gmx.net>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	linux-can@vger.kernel.org, "Vincent Mailhol" <mailhol@kernel.org>
Subject: Re: [PATCH v2] can: j1939: fix potential race condition in BAM segmentation
Date: Sun, 11 Oct 2026 15:26:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-167300@kernel.org> (raw)
In-Reply-To: <20261011151216.118932-1-alexander.hoelzl@gmx.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] can: j1939: session reference leak in j1939_xtp_rx_rts on spoofed loopback
--

commit b1f46ca54f92cbc040e1810933f35ac82b494289
Author: Alexander Hölzl <alexander.hoelzl@gmx.net>

can: j1939: fix potential race condition in BAM segmentation

This patch resolves a race condition in segmented messages using the BAM
protocol by rescheduling the tx timer when the tx ack is received. It ensures
that consecutive data frames aren't sent without delay if they are stuck in the
controller.

> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c

[ ... ]

> @@ -1806,8 +1814,12 @@ static void j1939_xtp_rx_rts(struct j1939_priv *priv, struct sk_buff *skb,
>  	session->last_cmd = cmd;
>  
>  	if (cmd == J1939_TP_CMD_BAM) {
> -		if (!session->transmission)
> +		if (!session->transmission) {
>  			j1939_tp_set_rxtimeout(session, 750);
> +		} else {
> +			j1939_tp_schedule_txtimer(session, J1939_TP_BAM_FRAME_SPACING_MS);
> +			j1939_tp_set_rxtimeout(session, J1939_TP_BAM_ECHO_TIMEOUT_MS);
> +		}

[Severity: Medium]
Does this code leak a struct j1939_session reference if the timer was already
active?

If a BAM RTS transmission fails with -ENOBUFS (e.g., due to the CAN TX queue
being full), j1939_tp_txtimer() schedules session->txtimer to retry.

If a spoofed BAM loopback packet is received from the network during this
window, j1939_xtp_rx_rts() is called with transmitter = true.

Because it is the first received RTS for this session (session->last_cmd == 0),
it bypasses the active session abort check, processes the loopback, and calls
j1939_tp_schedule_txtimer() directly.

Since hrtimer_start() inside j1939_tp_schedule_txtimer() silently overwrites
the pending retry timer, could this abandon the session reference taken when
the retry timer was originally scheduled?

Should there be a call to j1939_session_txtimer_cancel(session) before
scheduling the new timer, similar to the one added in j1939_xtp_rx_dat_one()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261011151216.118932-1-alexander.hoelzl@gmx.net?part=1

  reply	other threads:[~2026-10-11 15:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 15:11 [PATCH v2] can: j1939: fix potential race condition in BAM segmentation Alexander Hölzl
2026-10-11 15:26 ` sashiko-bot [this message]
2026-10-13  4:38 ` netdev-bot+sashiko

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=sashiko-outbox-167300@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexander.hoelzl@gmx.net \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --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