From: Kery Qi <qikeyu2017@gmail.com>
To: christian.koenig@amd.com
Cc: netdev@vger.kernel.org, Kery Qi <qikeyu2017@gmail.com>
Subject: [PATCH] drm/radeon/sumo: Avoid UAF/double-free on power table parse errors
Date: Fri, 9 Jan 2026 02:48:23 +0800 [thread overview]
Message-ID: <20260108184823.1795-1-qikeyu2017@gmail.com> (raw)
sumo_parse_power_table() allocates rdev->pm.dpm.ps and then allocates a
per-state sumo_ps (ps_priv) for each entry. On error, it currently frees
rdev->pm.dpm.ps in two places:
- if (!rdev->pm.power_state[i].clock_info) { kfree(rdev->pm.dpm.ps); ... }
- if (ps == NULL) { kfree(rdev->pm.dpm.ps); ... }
However, when sumo_parse_power_table() fails during the load/init path,
the driver later unwinds and calls the corresponding fini path, which
dereferences rdev->pm.dpm.ps[i].ps_priv and then frees rdev->pm.dpm.ps.
Freeing rdev->pm.dpm.ps inside sumo_parse_power_table() leaves a dangling
pointer that the unwind/fini path will both dereference and free again,
resulting in a use-after-free and a double-free.
Fix this by removing the local kfree(rdev->pm.dpm.ps) from the error
returns in sumo_parse_power_table() and letting the common unwind/fini
path perform the cleanup.
Fixes: 80ea2c129c76 ("drm/radeon/kms: add dpm support for sumo asics (v2)")
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
drivers/gpu/drm/radeon/sumo_dpm.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/radeon/sumo_dpm.c b/drivers/gpu/drm/radeon/sumo_dpm.c
index b11f7c5bbcbe..af649b7b2e1a 100644
--- a/drivers/gpu/drm/radeon/sumo_dpm.c
+++ b/drivers/gpu/drm/radeon/sumo_dpm.c
@@ -1491,15 +1491,11 @@ static int sumo_parse_power_table(struct radeon_device *rdev)
non_clock_array_index = power_state->v2.nonClockInfoIndex;
non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
&non_clock_info_array->nonClockInfo[non_clock_array_index];
- if (!rdev->pm.power_state[i].clock_info) {
- kfree(rdev->pm.dpm.ps);
+ if (!rdev->pm.power_state[i].clock_info)
return -EINVAL;
- }
ps = kzalloc(sizeof(struct sumo_ps), GFP_KERNEL);
- if (ps == NULL) {
- kfree(rdev->pm.dpm.ps);
+ if (ps == NULL)
return -ENOMEM;
- }
rdev->pm.dpm.ps[i].ps_priv = ps;
k = 0;
idx = (u8 *)&power_state->v2.clockInfoIndex[0];
--
2.34.1
reply other threads:[~2026-01-08 18:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260108184823.1795-1-qikeyu2017@gmail.com \
--to=qikeyu2017@gmail.com \
--cc=christian.koenig@amd.com \
--cc=netdev@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