Skip to content

Commit 9badc2a

Browse files
multics69rafaeljw
authored andcommitted
PM: EM: Fix NULL pointer dereference when perf domain ID is not found
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: 380ff27 ("PM: EM: Add dump to get-perf-domains in the EM YNL spec") Reported-by: Yi Lai <[email protected]> Closes: https://lore.kernel.org/lkml/aXiySM79UYfk+ytd@ly-workstation/ Signed-off-by: Changwoo Min <[email protected]> Cc: 6.19+ <[email protected]> # 6.19+ [ rjw: Subject and changelog edits ] Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 7aaa804 commit 9badc2a

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

kernel/power/em_netlink.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ int dev_energymodel_nl_get_perf_domains_doit(struct sk_buff *skb,
109109

110110
id = nla_get_u32(info->attrs[DEV_ENERGYMODEL_A_PERF_DOMAIN_PERF_DOMAIN_ID]);
111111
pd = em_perf_domain_get_by_id(id);
112+
if (!pd)
113+
return -EINVAL;
112114

113115
__em_nl_get_pd_size(pd, &msg_sz);
114116
msg = genlmsg_new(msg_sz, GFP_KERNEL);

0 commit comments

Comments
 (0)