From: Binbin Zhou <zhoubinbin@loongson.cn>
To: hyunjungg <hj351016@gmail.com>,
Chong Qiao <qiaochong@loongson.cn>, Lee Jones <lee@kernel.org>
Cc: mfd@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] mfd: ls2kbmc: cancel the reset work before the driver data is freed
Date: Sat, 7 Nov 2026 14:01:02 +0800 [thread overview]
Message-ID: <8ffdb96e-c082-42b6-b895-2badc12285ca@loongson.cn> (raw)
In-Reply-To: <20261107053218.3326443-1-hj351016@gmail.com>
Hi:
On 2026/11/7 13:32, hyunjungg wrote:
> From: Hyunjung Ko <hj351016@gmail.com>
>
> ls2k_bmc_init() INIT_WORK()s ddata->bmc_reset_work (ls2k_bmc_events_fn)
> and requests two device-managed interrupts (ls2k_bmc_interrupt) that
> schedule_work(&ddata->bmc_reset_work). The work handler dereferences
> ddata via container_of().
>
> ddata is devm_kzalloc()'d, so devres frees it when the device is
> unbound. Nothing cancels bmc_reset_work: free_irq() (run by devres)
> only waits for the interrupt handler to finish, not for a work item it
> has already queued. If a BMC reset interrupt fires shortly before
> unbind, the queued ls2k_bmc_events_fn() can run after ddata has been
> freed -> use-after-free.
>
> Register the work for device-managed cancellation with
> devm_work_autocancel(), before the devm_request_irq() calls that arm
> it, so devres (LIFO) frees the interrupts first, then cancels the work,
> and only then frees ddata.
>
> Found by code review; not reproduced (needs Loongson-2K BMC hardware and
> a reset interrupt racing driver unbind).
>
> Fixes: d952bba3fbb5 ("mfd: ls2kbmc: Add Loongson-2K BMC reset function support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
> ---
> drivers/mfd/ls2k-bmc-core.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/ls2k-bmc-core.c b/drivers/mfd/ls2k-bmc-core.c
> index 408056b..c44291e 100644
> --- a/drivers/mfd/ls2k-bmc-core.c
> +++ b/drivers/mfd/ls2k-bmc-core.c
> @@ -12,6 +12,7 @@
> #include <linux/aperture.h>
> #include <linux/bitfield.h>
> #include <linux/delay.h>
> +#include <linux/devm-helpers.h>
> #include <linux/errno.h>
> #include <linux/init.h>
> #include <linux/iopoll.h>
> @@ -371,7 +372,10 @@ static int ls2k_bmc_init(struct ls2k_bmc_ddata *ddata)
>
> ls2k_bmc_save_pci_data(pdev, ddata);
>
> - INIT_WORK(&ddata->bmc_reset_work, ls2k_bmc_events_fn);
> + ret = devm_work_autocancel(ddata->dev, &ddata->bmc_reset_work,
> + ls2k_bmc_events_fn);
> + if (ret)
> + return ret;
Lee had already fixed this issue:
https://lore.kernel.org/all/20261027093306.2812695-4-lee@kernel.org/
>
> ret = devm_request_irq(&pdev->dev, pdev->irq, ls2k_bmc_interrupt,
> IRQF_SHARED | IRQF_TRIGGER_FALLING, "ls2kbmc pcie", ddata);
--
Thanks.
Binbin
prev parent reply other threads:[~2026-11-07 6:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 5:32 hyunjungg
2026-11-07 6:01 ` Binbin Zhou [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=8ffdb96e-c082-42b6-b895-2badc12285ca@loongson.cn \
--to=zhoubinbin@loongson.cn \
--cc=hj351016@gmail.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=qiaochong@loongson.cn \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®