* [PATCH] can: softing: lock card->fw.lock unconditionally in softing_card_shutdown()
@ 2026-11-19 17:07 Ian Rogers
2026-11-19 17:11 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Ian Rogers @ 2026-11-19 17:07 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol
Cc: linux-can, linux-kernel, llvm, Elkin Cruz, Ian Rogers
softing_card_shutdown() calls mutex_lock_interruptible(&card->fw.lock)
with an empty if-body ('{ /* return -ERESTARTSYS */; }'). Because
softing_pdev_remove() invokes softing_card_shutdown() before
unregistering netdevs or removing sysfs attributes, a pending signal
while card->fw.lock is contended causes mutex_lock_interruptible() to
return -EINTR without acquiring the lock. Execution then proceeds unlocked
through IRQ and DPRAM teardown and calls mutex_unlock(&card->fw.lock) on a
mutex not owned by the current task.
Use mutex_lock(&card->fw.lock) in softing_card_shutdown().
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
-Wextra-semi-stmt enabled; fix and changelog drafted with an AI coding
assistant. Build-tested under LLVM=1 W=1 (-Werror) and -Wextra-semi-stmt;
not tested on Softing CAN hardware.
Fixes: 03fd3cf5a179 ("can: add driver for Softing card")
Fixes: 47fa0336c1b7 ("can: softing: softing_card_shutdown(): add braces around empty body in an 'if' statement")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/net/can/softing/softing_main.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c
index 519ab3097f86..d3dfad4f5321 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;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] can: softing: lock card->fw.lock unconditionally in softing_card_shutdown()
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
2026-11-19 17:26 ` Oliver Hartkopp
2026-11-19 17:27 ` Marc Kleine-Budde
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-19 17:11 UTC (permalink / raw)
To: Ian Rogers
Cc: linux-can, Marc Kleine-Budde, Oliver Hartkopp, Vincent Mailhol,
Oleksij Rempel
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: softing: lock card->fw.lock unconditionally in softing_card_shutdown()
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
@ 2026-11-19 17:26 ` Oliver Hartkopp
2026-11-19 17:27 ` Marc Kleine-Budde
2 siblings, 0 replies; 5+ messages in thread
From: Oliver Hartkopp @ 2026-11-19 17:26 UTC (permalink / raw)
To: Ian Rogers, Marc Kleine-Budde, Vincent Mailhol
Cc: linux-can, linux-kernel, llvm, Elkin Cruz
Hi Ian,
the PCMCIA Softing CANcard2 is discontinued since 2013 and the latest
Windows drivers date back to Windows 7/8.
The Softing CANcard driver is to be removed as there's no known user and
we lack the access to this at least 25 y/o hardware for 10 years now:
https://lore.kernel.org/linux-can/20261118092955.1283165-11-mkl@pengutronix.de/
So thanks for your patch but unfortunately too late.
Btw. beware of Sashiko bot reviews for this obsolete patch that will
make you rework the entire driver :-D
Best regards,
Oliver
On 19.11.26 18:07, Ian Rogers wrote:
> softing_card_shutdown() calls mutex_lock_interruptible(&card->fw.lock)
> with an empty if-body ('{ /* return -ERESTARTSYS */; }'). Because
> softing_pdev_remove() invokes softing_card_shutdown() before
> unregistering netdevs or removing sysfs attributes, a pending signal
> while card->fw.lock is contended causes mutex_lock_interruptible() to
> return -EINTR without acquiring the lock. Execution then proceeds unlocked
> through IRQ and DPRAM teardown and calls mutex_unlock(&card->fw.lock) on a
> mutex not owned by the current task.
>
> Use mutex_lock(&card->fw.lock) in softing_card_shutdown().
>
> Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
> -Wextra-semi-stmt enabled; fix and changelog drafted with an AI coding
> assistant. Build-tested under LLVM=1 W=1 (-Werror) and -Wextra-semi-stmt;
> not tested on Softing CAN hardware.
>
> Fixes: 03fd3cf5a179 ("can: add driver for Softing card")
> Fixes: 47fa0336c1b7 ("can: softing: softing_card_shutdown(): add braces around empty body in an 'if' statement")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> drivers/net/can/softing/softing_main.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c
> index 519ab3097f86..d3dfad4f5321 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;
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: softing: lock card->fw.lock unconditionally in softing_card_shutdown()
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
2026-11-19 17:26 ` Oliver Hartkopp
@ 2026-11-19 17:27 ` Marc Kleine-Budde
2026-11-20 17:41 ` Ian Rogers
2 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2026-11-19 17:27 UTC (permalink / raw)
To: Ian Rogers; +Cc: Vincent Mailhol, linux-can, linux-kernel, llvm, Elkin Cruz
[-- Attachment #1: Type: text/plain, Size: 1557 bytes --]
On 19.11.2026 09:07:22, Ian Rogers wrote:
> softing_card_shutdown() calls mutex_lock_interruptible(&card->fw.lock)
> with an empty if-body ('{ /* return -ERESTARTSYS */; }'). Because
> softing_pdev_remove() invokes softing_card_shutdown() before
> unregistering netdevs or removing sysfs attributes, a pending signal
> while card->fw.lock is contended causes mutex_lock_interruptible() to
> return -EINTR without acquiring the lock. Execution then proceeds unlocked
> through IRQ and DPRAM teardown and calls mutex_unlock(&card->fw.lock) on a
> mutex not owned by the current task.
>
> Use mutex_lock(&card->fw.lock) in softing_card_shutdown().
>
> Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
> -Wextra-semi-stmt enabled; fix and changelog drafted with an AI coding
> assistant. Build-tested under LLVM=1 W=1 (-Werror) and -Wextra-semi-stmt;
> not tested on Softing CAN hardware.
>
> Fixes: 03fd3cf5a179 ("can: add driver for Softing card")
> Fixes: 47fa0336c1b7 ("can: softing: softing_card_shutdown(): add braces around empty body in an 'if' statement")
> Signed-off-by: Ian Rogers <irogers@google.com>
The driver is being removed in net-next.
https://lore.kernel.org/all/20260815103428.117201-1-socketcan@hartkopp.net/
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: softing: lock card->fw.lock unconditionally in softing_card_shutdown()
2026-11-19 17:27 ` Marc Kleine-Budde
@ 2026-11-20 17:41 ` Ian Rogers
0 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2026-11-20 17:41 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: Vincent Mailhol, linux-can, linux-kernel, llvm, Elkin Cruz
On Thu, Nov 19, 2026 at 9:27 AM Marc Kleine-Budde <mkl@pengutronix.de> wrote:
>
> On 19.11.2026 09:07:22, Ian Rogers wrote:
> > softing_card_shutdown() calls mutex_lock_interruptible(&card->fw.lock)
> > with an empty if-body ('{ /* return -ERESTARTSYS */; }'). Because
> > softing_pdev_remove() invokes softing_card_shutdown() before
> > unregistering netdevs or removing sysfs attributes, a pending signal
> > while card->fw.lock is contended causes mutex_lock_interruptible() to
> > return -EINTR without acquiring the lock. Execution then proceeds unlocked
> > through IRQ and DPRAM teardown and calls mutex_unlock(&card->fw.lock) on a
> > mutex not owned by the current task.
> >
> > Use mutex_lock(&card->fw.lock) in softing_card_shutdown().
> >
> > Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
> > -Wextra-semi-stmt enabled; fix and changelog drafted with an AI coding
> > assistant. Build-tested under LLVM=1 W=1 (-Werror) and -Wextra-semi-stmt;
> > not tested on Softing CAN hardware.
> >
> > Fixes: 03fd3cf5a179 ("can: add driver for Softing card")
> > Fixes: 47fa0336c1b7 ("can: softing: softing_card_shutdown(): add braces around empty body in an 'if' statement")
> > Signed-off-by: Ian Rogers <irogers@google.com>
>
> The driver is being removed in net-next.
>
> https://lore.kernel.org/all/20260815103428.117201-1-socketcan@hartkopp.net/
Thanks for the heads-up, Oliver and Marc - please ignore this patch!
Best regards,
Ian
> regards,
> Marc
>
> --
> Pengutronix e.K. | Marc Kleine-Budde |
> Embedded Linux | https://www.pengutronix.de |
> Vertretung Nürnberg | Phone: +49-5121-206917-129 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-20 17:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-19 17:26 ` Oliver Hartkopp
2026-11-19 17:27 ` Marc Kleine-Budde
2026-11-20 17:41 ` Ian Rogers
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.