Skip to contentSkip to conversation

drm: Fix possible UAF in drm_addmap_core

PATCH New Yi Yang 1 participant 1 message Nov 17, 2022

Subsystems (2)
lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH 1/1 drm: Fix possible UAF in drm_addmap_core

smatch report warning as follows:

drivers/gpu/drm/drm_bufs.c:365 drm_addmap_core() warn:
'&list->head' not removed from list

If drm_map_handle() fails in drm_addmap_core(), the list will be freed, but the list->head will not be removed from dev->maplist, then list traversal may cause UAF.

Fix by removeing it from list->head before free().

Fixes 9a298b2acd77 ("drm: Remove memory debugging infrastructure.")
---
 drivers/gpu/drm/drm_bufs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_bufs.c +1 -0
index fcca21e8efac..e739e577902c 100644
@@ -362,6 +362,7 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset,
 		if (map->type == _DRM_REGISTERS)
 			iounmap(map->handle);
 		kfree(map);
+		list_del(&list->head);
 		kfree(list);
 		mutex_unlock(&dev->struct_mutex);
 		return ret;
Signature · 1 line
2.17.1