Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: tze.yee.ng@altera.com
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device
Date: Mon, 29 Jun 2026 07:42:44 +0000	[thread overview]
Message-ID: <20260629074244.7101B1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <d8a647b3873f8e1ee6b3efb22b5aa34c34146ea5.1782715159.git.tze.yee.ng@altera.com>

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

Pre-existing issues:
- [High] Child devices (hwmon, RSU, and OF-populated devices) are unregistered after the async controller is torn down, leading to a Use-After-Free if a child driver accesses transactions while the parent driver is being removed.
--

commit 34dda5913b8cf85802a76938265cc19235241f5c
Author: Tze Yee Ng <tze.yee.ng@altera.com>

firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device

This commit adds asynchronous read support for hardware monitor temperature
and voltage commands in the Stratix 10 service layer. It also registers a
socfpga-hwmon platform device when hardware monitor support is enabled.

> diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c
> index c24ca5823078f..716b58f5a6170 100644
> --- a/drivers/firmware/stratix10-svc.c
> +++ b/drivers/firmware/stratix10-svc.c
[ ... ]
> @@ -2050,6 +2087,9 @@ static void stratix10_svc_drv_remove(struct platform_device *pdev)
>  
>  	of_platform_depopulate(ctrl->dev);
>  
> +	if (svc->stratix10_svc_hwmon)
> +		platform_device_unregister(svc->stratix10_svc_hwmon);
> +

[Severity: High]
This is a pre-existing issue, but does unregistering the child devices here
lead to a use-after-free if a user is actively accessing them?

Looking at stratix10_svc_drv_remove() in drivers/firmware/stratix10-svc.c,
stratix10_svc_async_exit(ctrl) is called before the child devices are
unregistered:

static void stratix10_svc_drv_remove(struct platform_device *pdev)
{
	...
	stratix10_svc_async_exit(ctrl);

	of_platform_depopulate(ctrl->dev);

	if (svc->stratix10_svc_hwmon)
		platform_device_unregister(svc->stratix10_svc_hwmon);
	...
}

If a user is actively reading a hwmon sysfs attribute during driver
unbind, the child driver could be blocked waiting or polling in
socfpga_hwmon_async_read().

Because stratix10_svc_async_exit() forcefully frees all pending
transaction handlers, and the child endpoints are still active at this point,
the polling child thread could wake up and call stratix10_svc_async_poll()
or stratix10_svc_async_done() using the now-freed transaction handler,
triggering a use-after-free.

Could we unregister the child devices before tearing down the async
controller to avoid this?

>  	platform_device_unregister(svc->stratix10_svc_rsu);
>  
>  	for (i = 0; i < SVC_NUM_CHANNEL; i++) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1782715159.git.tze.yee.ng@altera.com?part=1

  reply	other threads:[~2026-06-29  7:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29  7:24 [PATCH v2 0/2] hwmon: add Altera SoC FPGA hardware monitoring support tze.yee.ng
2026-06-29  7:24 ` [PATCH v2 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device tze.yee.ng
2026-06-29  7:42   ` sashiko-bot [this message]
2026-06-29  7:24 ` [PATCH v2 2/2] hwmon: add Altera SoC FPGA hardware monitoring driver tze.yee.ng
2026-06-29  7:42   ` sashiko-bot
2026-07-03  6:56     ` NG, TZE YEE
2026-07-01 14:07 ` [PATCH v2 0/2] hwmon: add Altera SoC FPGA hardware monitoring support Guenter Roeck

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=20260629074244.7101B1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tze.yee.ng@altera.com \
    /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