From: Dinh Nguyen <dinguyen@kernel.org>
To: "NG, TZE YEE" <tze.yee.ng@altera.com>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device
Date: Mon, 6 Jul 2026 08:36:26 -0500 [thread overview]
Message-ID: <cd6460b2-7f53-4ac6-8f68-172e7853f63f@kernel.org> (raw)
In-Reply-To: <24a16e2d-205c-4340-87c4-2fe5b57c4791@altera.com>
On 7/6/26 03:36, NG, TZE YEE wrote:
> On 3/7/2026 4:19 pm, sashiko-bot@kernel.org wrote:
>> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>>
>> Pre-existing issues:
>> - [High] The async service layer is torn down before the child platform devices (HWMON and RSU) are unregistered, leading to a Use-After-Free and NULL pointer dereference if a concurrent async call is made.
>> --
>>
>> commit 2c6317a7aef89428e616ea8354fab157b27ff35f
>> Author: Tze Yee Ng <tze.yee.ng@altera.com>
>>
>> firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device
>>
>> Add asynchronous Stratix 10 service layer support for hardware monitor
>> temperature and voltage read commands. Register 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
>> introduce a race condition with module removal?
>>
>> In stratix10_svc_drv_remove(), we tear down the async service layer before
>> the child devices are unregistered:
>>
>> stratix10_svc_async_exit(ctrl);
>> of_platform_depopulate(ctrl->dev);
>> if (svc->stratix10_svc_hwmon)
>> platform_device_unregister(svc->stratix10_svc_hwmon);
>>
>> If a sysfs read for the hwmon device (e.g., temp1_input) races with module
>> unload, could it proceed to stratix10_svc_async_send() because the device
>> is not yet unregistered?
>>
>> If so, it looks like stratix10_svc_async_send() will dereference the achan
>> structure that was already freed:
>>
>> ret = ida_alloc_max(&achan->job_id_pool, MAX_SDM_JOB_IDS,
>> GFP_KERNEL);
>>
>> And later attempt a NULL pointer dereference, as actrl->invoke_fn was set
>> to NULL by stratix10_svc_async_exit():
>>
>> actrl->invoke_fn(actrl, &args, &res);
>>
>> Should the child platform devices be unregistered before
>> stratix10_svc_async_exit() is called?
>>
>>> platform_device_unregister(svc->stratix10_svc_rsu);
>>>
>>> for (i = 0; i < SVC_NUM_CHANNEL; i++) {
>>
>
> Hi,
>
> Agreed with Sashiko's comment. In stratix10_svc_drv_remove(),
> stratix10_svc_async_exit() currently runs before the hwmon and RSU
> platform devices are unregistered. A concurrent sysfs read could still
> reach stratix10_svc_async_send() and use resources already torn down by
> stratix10_svc_async_exit().
>
> This ordering predates the hwmon registration in this series; RSU
> follows the same pattern today. The fix would be to unregister child
> platform devices (and depopulate) before calling stratix10_svc_async_exit().
>
> We can include that reorder in this series, or send it as a separate
> stratix10-svc fix.
>
Please send that as a separate fix.
Thanks,
Dinh
next prev parent reply other threads:[~2026-07-06 13:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 8:08 [PATCH v3 0/2] hwmon: add Altera SoC FPGA hardware monitoring support tze.yee.ng
2026-07-03 8:08 ` [PATCH v3 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device tze.yee.ng
2026-07-03 8:19 ` sashiko-bot
2026-07-06 8:36 ` NG, TZE YEE
2026-07-06 13:36 ` Dinh Nguyen [this message]
2026-07-03 8:08 ` [PATCH v3 2/2] hwmon: add Altera SoC FPGA hardware monitoring driver tze.yee.ng
2026-07-03 8:18 ` sashiko-bot
2026-07-06 8:59 ` NG, TZE YEE
2026-07-06 14:58 ` 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=cd6460b2-7f53-4ac6-8f68-172e7853f63f@kernel.org \
--to=dinguyen@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--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