Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Vincent Mailhol" <mailhol@kernel.org>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	linux-can@vger.kernel.org
Subject: Re: [PATCH] can: isotp: fix timer drain order, wakeup handling and tx_gen ordering
Date: Mon, 20 Jul 2026 11:23:29 +0000	[thread overview]
Message-ID: <20260720112329.8F1A21F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260720110830.111709-1-socketcan@hartkopp.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Signal interruption in wait_tx_done unconditionally resets socket state, potentially clobbering a concurrent transfer.
--

--- Patch [1]: [PATCH] can: isotp: fix timer drain order, wakeup handling and tx_gen ordering ---
commit cdb0b283760f7e72e982cd4e81ec76ef6a8a011d
Author: Oliver Hartkopp <socketcan@hartkopp.net>

can: isotp: fix timer drain order, wakeup handling and tx_gen ordering

This patch addresses several issues found in the CAN ISOTP protocol.
It fixes timer drain ordering, wakeup handling on socket release, and
ensures tx_gen is incremented before state transitions to avoid timeout
stamp races.

> diff --git a/net/can/isotp.c b/net/can/isotp.c
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
[ ... ]
> @@ -1246,15 +1261,18 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
>  	spin_lock_bh(&so->rx_lock);
>  	goto err_out_drop_locked;
>  err_event_drop:
> -	/* interrupted waiting on our own transfer - drain its timers */
> +	/* interrupted or shut down while waiting on our own transfer */
>  	spin_lock_bh(&so->rx_lock);
>  	hrtimer_cancel(&so->txfrtimer);
>  	hrtimer_cancel(&so->txtimer);
>  	hrtimer_cancel(&so->echotimer);
>  err_out_drop_locked:
>  	/* release the claim; so->rx_lock still held from above */
> -	so->cfecho = 0;
> -	so->tx.state = ISOTP_IDLE;
> +	WRITE_ONCE(so->cfecho, 0);
> +
> +	/* only claim to IDLE if isotp_release() has not taken over */
> +	if (READ_ONCE(so->tx.state) != ISOTP_SHUTDOWN)
> +		WRITE_ONCE(so->tx.state, ISOTP_IDLE);

[Severity: High]
This is a pre-existing issue, but can this error path clobber a concurrent
transfer?

If Thread A calls isotp_sendmsg() with CAN_ISOTP_WAIT_TX_DONE and is
interrupted by a signal, wait_event_interruptible() evaluates to false and
returns -ERESTARTSYS.

Before Thread A can acquire so->rx_lock at err_event_drop, its transfer
might complete normally. The RX path would set so->tx.state to ISOTP_IDLE
and wake up a concurrently blocked Thread B.

If Thread B then claims the socket, increments so->tx_gen, and starts its
own transfer, Thread A would eventually resume, acquire so->rx_lock, and
blindly cancel timers and reset tx.state to ISOTP_IDLE, corrupting Thread B's
new transfer.

Should this error path verify that so->tx_gen still matches the thread's own
generation before resetting the state, similar to how it is checked in
isotp_tx_timeout()?

>  	spin_unlock_bh(&so->rx_lock);
>  	wake_up_interruptible(&so->wait);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720110830.111709-1-socketcan@hartkopp.net?part=1

      reply	other threads:[~2026-07-20 11:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 11:08 [PATCH] can: isotp: fix timer drain order, wakeup handling and tx_gen ordering Oliver Hartkopp
2026-07-20 11:23 ` sashiko-bot [this message]

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=20260720112329.8F1A21F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --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