Skip to contentSkip to conversation

drm/vmwgfx: Fix memory leak in vmw_mksstat_add_ioctl()

PATCH In review Rafael Mendonca 2 participants 2 messages Sep 16, 2022 – Sep 17, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vmwgfx: Fix memory leak in vmw_mksstat_add_ioctl()

If the copy of the description string from userspace fails, then the page for the instance descriptor doesn't get freed before returning -EFAULT, which leads to a memleak.

Fixes 7a7a933edd6c ("drm/vmwgfx: Introduce VMware mks-guest-stats")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +1 -0
index 2aceac7856e2..089046fa21be 100644
@@ -1076,6 +1076,7 @@ int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
 
 	if (desc_len < 0) {
 		atomic_set(&dev_priv->mksstat_user_pids[slot], 0);
+		__free_page(page);
 		return -EFAULT;
 	}
 
Signature · 1 line
2.34.1
Reviewed-by Martin Krastev on v1 1/1
#1 lore raw

Thank you for the catch!

Regards,

Martin

Quoted 22 lines · Rafael Mendonca

If the copy of the description string from userspace fails, then the page for the instance descriptor doesn't get freed before returning -EFAULT, which leads to a memleak.

Fixes 7a7a933edd6c ("drm/vmwgfx: Introduce VMware mks-guest-stats")
---
  drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +1 -0
index 2aceac7856e2..089046fa21be 100644
@@ -1076,6 +1076,7 @@ int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
 
  	if (desc_len < 0) {
  		atomic_set(&dev_priv->mksstat_user_pids[slot], 0);
+		__free_page(page);
  		return -EFAULT;
  	}