Skip to contentSkip to conversation

drm/radeon/sumo: Avoid UAF/double-free on power table parse errors

PATCH New Kery Qi 1 participant 1 message Jan 8

Subsystems (4)
lore
Share & tools
lore

Kery Qi

author
#0 lore raw

PATCH 1/1 drm/radeon/sumo: Avoid UAF/double-free on power table parse errors

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)")
---
 drivers/gpu/drm/radeon/sumo_dpm.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/radeon/sumo_dpm.c +2 -6
index b11f7c5bbcbe..af649b7b2e1a 100644
@@ -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];
Signature · 1 line
2.34.1