On 12/2/2026 12:07 AM, Haoxiang Li wrote:
init_powernv_pstates() allocates hash entries to build the P-state
reverse map. These entries are leaked if allocation fails partway
through initialization, if subsequent chip initialization or cpufreq
driver registration fails, or when the module is unloaded.

Add a helper to free the reverse map and call it on all relevant
initialization failure paths and during module exit.

Fixes: 332f0a01f0dd ("powernv-cpufreq: Fix pstate_to_idx() to handle non-continguous 
pstates")
Signed-off-by: Haoxiang Li <[email protected]>


The leak fix itself looks correct to me.

This is a pre-existing UAF: work_fn(powernv_cpufreq_work_fn()) sends
throttle_check() via an async IPI (wait=0), which can run after
clean_chip_info() frees chips[]. d0a72efac89d added cancel_work_sync(),
but that does not wait for the IPI, so the fix is incomplete.

It seems that this patch slightly widens it: a late IPI that races with
free_pstate_revmap() can now also touch a freed revmap entry. It might
make sense to fix the IPI issue first (maybe using wait=1, though that
needs to be checked) and put it before this patch.

Please consider if we can fix it first (maybe using wait=1, need to
check) as patch 1/2 with this patch as 2/2.


---
  drivers/cpufreq/powernv-cpufreq.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)

diff --git a/drivers/cpufreq/powernv-cpufreq.c 
b/drivers/cpufreq/powernv-cpufreq.c
index 9dee341b407e..b32cccd27b5c 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -1108,6 +1108,18 @@ static inline void unregister_all_notifiers(void)
        unregister_reboot_notifier(&powernv_cpufreq_reboot_nb);
  }
+static void free_pstate_revmap(void)
+{
+       struct pstate_idx_revmap_data *entry;
+       struct hlist_node *tmp;
+       unsigned int bucket;
+
+       hash_for_each_safe(pstate_revmap, bucket, tmp, entry, hentry) {
+               hash_del(&entry->hentry);
+               kfree(entry);
+       }
+}
+
  static int __init powernv_cpufreq_init(void)
  {
        int rc = 0;
@@ -1142,6 +1154,7 @@ static int __init powernv_cpufreq_init(void)
  cleanup:
        clean_chip_info();
  out:
+       free_pstate_revmap();
        pr_info("Platform driver disabled. System does not support PState 
control\n");
        return rc;
  }
@@ -1152,6 +1165,7 @@ static void __exit powernv_cpufreq_exit(void)
        cpufreq_unregister_driver(&powernv_cpufreq_driver);
        unregister_all_notifiers();
        clean_chip_info();
+       free_pstate_revmap();
  }
  module_exit(powernv_cpufreq_exit);


--
Thx and BRs,
Zhongqiu Han

Reply via email to