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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] can: j1939: session reference leak on concurrent txtimer scheduling
--

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

can: j1939: fix potential race condition in BAM segmentation

This patch addresses a race condition in segmented BAM messages by moving
the tx timer scheduling such that it is scheduled when the tx ack is
received. This aims to prevent session stalls when a BAM frame is stuck and
fixes the behavior for consecutive data frames.

> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> index 8fcfd13e5e6f8..c61a021880c01 100644
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
[ ... ]
> @@ -1961,6 +1974,12 @@ static void j1939_xtp_rx_dat_one(struct j1939_session *session,
>  	} else if (remain) {
>  		if (!session->transmission)
>  			j1939_tp_set_rxtimeout(session, 750);
> +		else if (j1939_cb_is_broadcast(&session->skcb)) {
> +			/* cancel the txtimer to avoid leaking session references */
> +			j1939_session_txtimer_cancel(session);
> +			j1939_tp_schedule_txtimer(session, J1939_TP_BAM_FRAME_SPACING_MS);
> +			j1939_tp_set_rxtimeout(session, J1939_TP_BAM_ECHO_TIMEOUT_MS);
> +		}
>  	} else if (do_cts_eoma) {
>  		j1939_tp_set_rxtimeout(session, 1250);
>  		if (!session->transmission)
>  			j1939_tp_schedule_txtimer(session, 0);

[Severity: High]
Does this do_cts_eoma path leak session references when multiple packets are
processed rapidly?

When a receiver session processes data packets in j1939_xtp_rx_dat_one(), it
evaluates do_cts_eoma = true if pkt.rx >= pkt.last. Because pkt.last is
initialized to 0 and never updated for receiver sessions, this condition is
true for every data packet.

Consequently, j1939_tp_schedule_txtimer(session, 0) is called for every
packet without first cancelling any pending timer.

Since j1939_tp_schedule_txtimer() unconditionally calls
j1939_session_get(session) before starting the timer, calling it multiple
times before the timer fires (e.g. in a NAPI batch) will re-arm the timer
and leak the extra references, as the timer callback only drops a single
reference.

Should this path also call j1939_session_txtimer_cancel(session) first,
similar to the new block added above for remain?

>  	} else {

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

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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 15:31 [PATCH v3] can: j1939: fix potential race condition in BAM segmentation Alexander Hölzl
2026-10-11 15:48 ` sashiko-bot [this message]
2026-10-12  7:39   ` Hölzl, Alexander
2026-10-13  4:56 ` netdev-bot+sashiko
2026-10-13  9:35   ` Hölzl, Alexander
2026-10-13 10:36     ` Oleksij Rempel

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-167306@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