]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PM: EM: Fix NULL pointer dereference when perf domain ID is not found
authorChangwoo Min <changwoo@igalia.com>
Sun, 29 Mar 2026 07:36:15 +0000 (16:36 +0900)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 30 Mar 2026 19:43:51 +0000 (21:43 +0200)
dev_energymodel_nl_get_perf_domains_doit() calls
em_perf_domain_get_by_id() but does not check the return value before
passing it to __em_nl_get_pd_size(). When a caller supplies a
non-existent perf domain ID, em_perf_domain_get_by_id() returns NULL,
and __em_nl_get_pd_size() immediately dereferences pd->cpus
(struct offset 0x30), causing a NULL pointer dereference.

The sister handler dev_energymodel_nl_get_perf_table_doit() already
handles this correctly via __em_nl_get_pd_table_id(), which returns
NULL and causes the caller to return -EINVAL. Add the same NULL check
in the get-perf-domains do handler.

Fixes: 380ff27af25e ("PM: EM: Add dump to get-perf-domains in the EM YNL spec")
Reported-by: Yi Lai <yi1.lai@linux.intel.com>
Closes: https://lore.kernel.org/lkml/aXiySM79UYfk+ytd@ly-workstation/
Signed-off-by: Changwoo Min <changwoo@igalia.com>
Cc: 6.19+ <stable@vger.kernel.org> # 6.19+
[ rjw: Subject and changelog edits ]
Link: https://patch.msgid.link/20260329073615.649976-1-changwoo@igalia.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/em_netlink.c

index 5a611d3950fd51a01834e3b0a3b1ebfa807142a5..4d4fd29bd2be9c7f2f57b5116573352a246ac0ec 100644 (file)
@@ -109,6 +109,8 @@ int dev_energymodel_nl_get_perf_domains_doit(struct sk_buff *skb,
 
        id = nla_get_u32(info->attrs[DEV_ENERGYMODEL_A_PERF_DOMAIN_PERF_DOMAIN_ID]);
        pd = em_perf_domain_get_by_id(id);
+       if (!pd)
+               return -EINVAL;
 
        __em_nl_get_pd_size(pd, &msg_sz);
        msg = genlmsg_new(msg_sz, GFP_KERNEL);