Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	linux-can@vger.kernel.org,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>
Subject: Re: [PATCH net 14/14] can: hi311x: drop hi3110_lock before free_irq() on open failure
Date: Thu, 27 Aug 2026 12:10:57 +0000	[thread overview]
Message-ID: <20260827121057.9B6DD1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260826121036.2706424-15-mkl@pengutronix.de>

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

Pre-existing issues:
- [High] Concurrent execution of hi3110_clean() without mutual exclusion can result in a double-free of priv->tx_skb and a data race on priv->tx_busy.
- [High] hi3110_stop() does not cancel pending driver workqueues (priv->restart_work and priv->tx_work), leading to use-after-free, IRQ storms, or hardware access after power off.
--

commit 22aa36b3ba9420685fbf25a2a6f3ce41f336fdb3
Author: Runyu Xiao <runyu.xiao@seu.edu.cn>

can: hi311x: drop hi3110_lock before free_irq() on open failure

hi3110_open() requests a threaded IRQ and then performs hardware setup while
holding priv->hi3110_lock. If setup fails, dropping the lock before calling
free_irq() prevents a deadlock against a pending IRQ thread.

Link: https://patch.msgid.link/20260820020631.316418-1-runyu.xiao@seu.edu.cn

> diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
> index ae90e6716de5b..2be851e8907d0 100644
> --- a/drivers/net/can/spi/hi311x.c
> +++ b/drivers/net/can/spi/hi311x.c
> @@ -787,7 +787,10 @@ static int hi3110_open(struct net_device *net)
>  	return 0;
>  
>   out_free_irq:
> +	priv->force_quit = 1;
> +	mutex_unlock(&priv->hi3110_lock);
>  	free_irq(spi->irq, priv);
> +	mutex_lock(&priv->hi3110_lock);
>  	hi3110_hw_sleep(spi);
>   out_close:
>  	hi3110_power_enable(priv->transceiver, 0);

[Severity: High]
This isn't a bug introduced by this patch, but can concurrent execution of
hi3110_clean() without mutual exclusion result in a double-free of
priv->tx_skb and a data race on priv->tx_busy?

It appears hi3110_do_set_mode() can enter hi3110_clean() unlocked, while
hi3110_tx_work_handler() can enter it locked. If they run concurrently, could
this result in simultaneously invoking dev_kfree_skb() and corrupting the
echo skb state?

drivers/net/can/spi/hi311x.c:hi3110_clean() {
    ...
    dev_kfree_skb(priv->tx_skb);
    if (priv->tx_busy)
        can_free_echo_skb(priv->net, 0, NULL);
    ...
}

[Severity: High]
This is a pre-existing issue, but does hi3110_stop() need to cancel pending
driver workqueues like priv->restart_work and priv->tx_work?

Currently, there is no cancel_work_sync() in hi3110_stop(). Could this lead
to hardware access after power off if hi3110_can_remove() disables main VDD
power before the workqueue is drained?

For instance, if hi3110_restart_work_handler() runs after power off, would
it force execution against powered-off hardware and cause SPI bus faults?

drivers/net/can/spi/hi311x.c:hi3110_restart_work_handler() {
    ...
    if (priv->restart_tx) {
        priv->restart_tx = 0;
        hi3110_hw_reset(spi);
        hi3110_setup(net);
        hi3110_clean(net);
        hi3110_set_normal_mode(spi);
        netif_wake_queue(net);
    }
    ...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260826121036.2706424-1-mkl@pengutronix.de?part=14

      reply	other threads:[~2026-08-27 12:10 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 12:02 [PATCH net 0/14] pull-request: can 2026-08-26 Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 01/14] can: dev: can_dropped_invalid_skb: drop CAN XL frames on non-CAN XL devices Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 02/14] can: convert unreliable ARPHRD_CAN type checks to robust can_get_ml_priv() Marc Kleine-Budde
2026-08-27 12:10   ` sashiko-bot
2026-08-27 12:41     ` Oliver Hartkopp
2026-08-26 12:02 ` [PATCH net 03/14] can: bittiming: fix divide-by-zero in can_calc_bittiming() Marc Kleine-Budde
2026-08-27 12:10   ` sashiko-bot
2026-08-27 19:44   ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 04/14] can: bittiming: fix bitrate error calculation on unsigned operands Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 05/14] can: rockchip_canfd: prevent TX stall on echo skb failure Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 06/14] can: rockchip_canfd: retry the outstanding TX buffer Marc Kleine-Budde
2026-08-27 19:44   ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 07/14] can: rockchip_canfd: serialize TX state and command writes Marc Kleine-Budde
2026-08-27 19:44   ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 08/14] can: skb: make echo skb freeing safe in any IRQ context Marc Kleine-Budde
2026-08-27 12:10   ` sashiko-bot
2026-08-26 12:02 ` [PATCH net 09/14] can: skb: make CAN skb allocation failure paths IRQ-safe Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 10/14] can: dev: can_put_echo_skb(): free skb on invalid echo index Marc Kleine-Budde
2026-08-27 12:10   ` sashiko-bot
2026-08-27 17:01     ` Oliver Hartkopp
2026-08-26 12:02 ` [PATCH net 11/14] can: kvaser_pciefd: fix use-after-free in bec poll timer Marc Kleine-Budde
2026-08-27 12:10   ` sashiko-bot
2026-08-27 12:36     ` Marc Kleine-Budde
2026-08-27 12:55       ` Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 12/14] can: kvaser_usb: validate command format before parsing in hydra receive path Marc Kleine-Budde
2026-08-27 12:10   ` sashiko-bot
2026-08-27 12:57     ` Marc Kleine-Budde
2026-08-27 19:44   ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 13/14] can: usb: f81604: fix struct f81604_int_data size mismatch Marc Kleine-Budde
2026-08-27 12:10   ` sashiko-bot
2026-08-26 12:02 ` [PATCH net 14/14] can: hi311x: drop hi3110_lock before free_irq() on open failure Marc Kleine-Budde
2026-08-27 12:10   ` 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=20260827121057.9B6DD1F00A3A@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