All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH] can: softing: lock card->fw.lock unconditionally in softing_card_shutdown()
Date: Thu, 19 Nov 2026 17:11:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-223645@kernel.org> (raw)
In-Reply-To: <20261119170722.1524088-1-irogers@google.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] can: softing: TOCTOU race on card->fw.up in softing_startstop()
  [1]
--

commit ae72f0f8531d52de45e7b52fa1bdb8f595a10797
Author: Ian Rogers <irogers@google.com>

can: softing: lock card->fw.lock unconditionally in softing_card_shutdown()

This commit replaces mutex_lock_interruptible() with mutex_lock() in
softing_card_shutdown() so that device teardown always acquires
card->fw.lock before clearing card->fw.up and releasing resources.

> diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c
> index 519ab3097f866..d3dfad4f5321c 100644
> --- a/drivers/net/can/softing/softing_main.c
> +++ b/drivers/net/can/softing/softing_main.c
> @@ -448,9 +448,7 @@ static void softing_card_shutdown(struct softing *card)
>  {
>  	int fw_up = 0;
>  
> -	if (mutex_lock_interruptible(&card->fw.lock)) {
> -		/* return -ERESTARTSYS */;
> -	}
> +	mutex_lock(&card->fw.lock);
>  	fw_up = card->fw.up;
>  	card->fw.up = 0;
>  

[Severity: High]
This problem wasn't introduced by this patch, but can softing_startstop()
race with softing_card_shutdown() on card->fw.up [1]?

softing_pdev_remove() runs softing_card_shutdown() before unregistering
the netdevs, and softing_startstop() checks card->fw.up before taking
card->fw.lock without rechecking it under the lock:

drivers/net/can/softing/softing_fw.c:softing_startstop() {
	...
	if (!card->fw.up)
		return -EIO;

	ret = mutex_lock_interruptible(&card->fw.lock);
	if (ret)
		return ret;
	...
	softing_enable_irq(card, 0);
	ret = softing_reset_chip(card);
	...
}

CPU0                                    CPU1 (kworker / netdev)
softing_pdev_remove()                   softing_startstop()
                                          if (!card->fw.up) // sees 1
  softing_card_shutdown()
    mutex_lock(&card->fw.lock)
    card->fw.up = 0
    free_irq(card->irq.nr, card)
    card->pdat->reset(card->pdev, 1)
    mutex_unlock(&card->fw.lock)
                                          mutex_lock_interruptible(...)
                                          softing_reset_chip(card)
                                            <-- loops forever on reset card

When triggered from can_restart_work or a netdev call holding rtnl_lock,
softing_reset_chip() spins indefinitely waiting for softing_fct_cmd() to
succeed on the reset hardware, stalling device removal in
unregister_candev().  Checking card->fw.up after acquiring card->fw.lock
in softing_startstop() would close this race.

[1] https://sashiko.dev/#/bug/linux-f244dc22-af63-40f7-af90-ef6182f497c5

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119170722.1524088-1-irogers@google.com?part=1

  reply	other threads:[~2026-11-19 17:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 17:07 [PATCH] can: softing: lock card->fw.lock unconditionally in softing_card_shutdown() Ian Rogers
2026-11-19 17:11 ` sashiko-bot [this message]
2026-11-19 17:26 ` Oliver Hartkopp
2026-11-19 17:27 ` Marc Kleine-Budde
2026-11-20 17:41   ` Ian Rogers

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-223645@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.