Skip to contentSkip to conversation

drm/radeon: fix memory leak in radeon_ring_restore() on lock failure

PATCH Applied Yuho Choi 2 participants 3 messages Apr 16 – Apr 17

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 drm/radeon: fix memory leak in radeon_ring_restore() on lock failure

radeon_ring_restore() takes ownership of the data buffer allocated by radeon_ring_backup(). The caller (radeon_gpu_reset()) only frees it in the non-restore branch; in the restore branch it relies on radeon_ring_restore() to free it.

If radeon_ring_lock() fails, the function returned early without calling kvfree(data), leaking the ring backup buffer on every GPU reset that fails at the lock stage. During repeated GPU resets this causes cumulative kernel memory exhaustion.

Free data before returning the error.

Fixes 55d7c22192be ("drm/radeon: implement ring saving on reset v4")
---
 drivers/gpu/drm/radeon/radeon_ring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_ring.c +3 -1
index 581ae20c46e4b..a5dff072c1ac0 100644
@@ -356,8 +356,10 @@ int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
 
 	/* restore the saved ring content */
 	r = radeon_ring_lock(rdev, ring, size);
-	if (r)
+	if (r) {
+		kvfree(data);
 		return r;
+	}
 
 	for (i = 0; i < size; ++i) {
 		radeon_ring_write(ring, data[i]);
Signature · 1 line
2.50.1 (Apple Git-155)
Applied
#1 lore raw

Applied. Thanks!

Quoted 38 lines · Yuho Choi

radeon_ring_restore() takes ownership of the data buffer allocated by radeon_ring_backup(). The caller (radeon_gpu_reset()) only frees it in the non-restore branch; in the restore branch it relies on radeon_ring_restore() to free it.

If radeon_ring_lock() fails, the function returned early without calling kvfree(data), leaking the ring backup buffer on every GPU reset that fails at the lock stage. During repeated GPU resets this causes cumulative kernel memory exhaustion.

Free data before returning the error.

Fixes 55d7c22192be ("drm/radeon: implement ring saving on reset v4")
---
 drivers/gpu/drm/radeon/radeon_ring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_ring.c +3 -2
index 581ae20c46e4b..a5dff072c1ac0 100644
@@ -356,8 +356,10 @@ int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
 
        /* restore the saved ring content */
        r = radeon_ring_lock(rdev, ring, size);
-       if (r)
+       if (r) {
+               kvfree(data);
                return r;
+       }
 
        for (i = 0; i < size; ++i) {
                radeon_ring_write(ring, data[i]);
--

2.50.1 (Apple Git-155)

author
#2 lore raw

Dear Alex,

Thank you for applying the patch.

Best regards,
Yuho Choi

Quoted 42 lines · Alex Deucher

Applied. Thanks!

Quoted 38 lines · Yuho Choi

radeon_ring_restore() takes ownership of the data buffer allocated by radeon_ring_backup(). The caller (radeon_gpu_reset()) only frees it in the non-restore branch; in the restore branch it relies on radeon_ring_restore() to free it.

If radeon_ring_lock() fails, the function returned early without calling kvfree(data), leaking the ring backup buffer on every GPU reset that fails at the lock stage. During repeated GPU resets this causes cumulative kernel memory exhaustion.

Free data before returning the error.

Fixes 55d7c22192be ("drm/radeon: implement ring saving on reset v4")
---
 drivers/gpu/drm/radeon/radeon_ring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_ring.c +3 -2
index 581ae20c46e4b..a5dff072c1ac0 100644
@@ -356,8 +356,10 @@ int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
 
        /* restore the saved ring content */
        r = radeon_ring_lock(rdev, ring, size);
-       if (r)
+       if (r) {
+               kvfree(data);
                return r;
+       }
 
        for (i = 0; i < size; ++i) {
                radeon_ring_write(ring, data[i]);
--

2.50.1 (Apple Git-155)