From: Mario Limonciello <mario.limonciello@amd.com>
To: "Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "open list:AMD HETERO CORE HARDWARE FEEDBACK DRIVER"
<platform-driver-x86@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Mario Limonciello <mario.limonciello@amd.com>,
<stable@vger.kernel.org>
Subject: [PATCH 1/3] platform/x86/amd: hfi: Fix a use-after-free when unloading the driver
Date: Mon, 21 Sep 2026 12:04:09 -0500 [thread overview]
Message-ID: <20260921170411.1149960-2-mario.limonciello@amd.com> (raw)
In-Reply-To: <20260921170411.1149960-1-mario.limonciello@amd.com>
amd_hfi_probe() registers CPU hotplug callbacks with
cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, ...) and schedules the static
sched_amd_hfi_itmt_work work item, but amd_hfi_remove() tears down
neither. The dynamically assigned hotplug state returned by
cpuhp_setup_state() is discarded, so cpuhp_remove_state() can never be
called, and the pending work is never cancelled.
After the module is unloaded and its memory is freed, any subsequent CPU
hotplug event or execution of the scheduled work dereferences the stale
callback and work function pointers, resulting in a use-after-free and
kernel panic.
Store the hotplug state returned by cpuhp_setup_state() and, on removal,
call cpuhp_remove_state() to unregister the callbacks and
cancel_work_sync() to flush the scheduled work before the module memory
goes away.
Cc: stable@vger.kernel.org
Fixes: bb20421c05fc ("platform/x86: hfi: Add online and offline callback support")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/platform/x86/amd/hfi/hfi.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index e0ebcb0c4acde..e1c776b71f3e6 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -76,6 +76,8 @@ struct amd_hfi_data {
struct amd_shmem_info *shmem;
struct dentry *dbgfs_dir;
+
+ int cpuhp_state;
};
/**
@@ -244,6 +246,8 @@ static void amd_hfi_remove(struct platform_device *pdev)
{
struct amd_hfi_data *dev = platform_get_drvdata(pdev);
+ cpuhp_remove_state(dev->cpuhp_state);
+ cancel_work_sync(&sched_amd_hfi_itmt_work);
debugfs_remove_recursive(dev->dbgfs_dir);
}
@@ -494,6 +498,7 @@ static int amd_hfi_probe(struct platform_device *pdev)
amd_hfi_online, amd_hfi_offline);
if (ret < 0)
return ret;
+ amd_hfi_data->cpuhp_state = ret;
schedule_work(&sched_amd_hfi_itmt_work);
--
2.55.0
next prev parent reply other threads:[~2026-09-21 17:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 17:04 [PATCH 0/3] Fix a few Sashiko flagged issues on AMD_HFI Mario Limonciello
2026-09-21 17:04 ` Mario Limonciello [this message]
2026-09-21 17:26 ` [PATCH 1/3] platform/x86/amd: hfi: Fix a use-after-free when unloading the driver Mario Limonciello
2026-09-21 17:04 ` [PATCH 2/3] platform/x86/amd: hfi: Fix out-of-bounds reads when parsing ranking data Mario Limonciello
2026-09-21 17:27 ` Mario Limonciello
2026-09-21 17:04 ` [PATCH 3/3] platform/x86/amd: hfi: Rely on ACPI enumeration instead of a dummy device Mario Limonciello
2026-09-21 17:27 ` Mario Limonciello
2026-09-21 17:10 ` [PATCH 0/3] Fix a few Sashiko flagged issues on AMD_HFI Ilpo Järvinen
2026-09-21 17:13 ` Mario Limonciello
2026-09-21 17:22 ` Ilpo Järvinen
2026-09-21 17:26 ` Mario Limonciello
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=20260921170411.1149960-2-mario.limonciello@amd.com \
--to=mario.limonciello@amd.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--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®