Skip to contentSkip to conversation

drm/nouveau/vm: fix memory corruption when pgt allocation fails

PATCH In review Marcin Slusarz 1 participant 2 messages Dec 20, 2012 – Dec 24, 2012 1 message not in the archive

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

PATCH 1/1 drm/nouveau/vm: fix memory corruption when pgt allocation fails

If we return freed vm, nouveau_drm_open will happily call nouveau_cli_destroy, which will try to free it again.

---
 drivers/gpu/drm/nouveau/core/subdev/vm/base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/core/subdev/vm/base.c +3 -1
index 082c11b..77c67fc 100644
@@ -352,7 +352,7 @@ nouveau_vm_create(struct nouveau_vmmgr *vmm, u64 offset, u64 length,
 	u64 mm_length = (offset + length) - mm_offset;
 	int ret;
 
-	vm = *pvm = kzalloc(sizeof(*vm), GFP_KERNEL);
+	vm = kzalloc(sizeof(*vm), GFP_KERNEL);
 	if (!vm)
 		return -ENOMEM;
 
@@ -376,6 +376,8 @@ nouveau_vm_create(struct nouveau_vmmgr *vmm, u64 offset, u64 length,
 		return ret;
 	}
 
+	*pvm = vm;
+
 	return 0;
 }
 
Signature · 1 line
1.8.0.2

A message that is not in the archive (sent off-list or not yet received): 1356043034-25739-2-git-send-email-marcin.slusarz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 6 lines · Marcin Slusarz

If we return freed vm, nouveau_drm_open will happily call nouveau_cli_destroy, which will try to free it again.

---

BTW, this fixes https://bugs.freedesktop.org/show_bug.cgi?id=58087

Quoted 26 lines
 drivers/gpu/drm/nouveau/core/subdev/vm/base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/core/subdev/vm/base.c +3 -2
index 082c11b..77c67fc 100644
@@ -352,7 +352,7 @@ nouveau_vm_create(struct nouveau_vmmgr *vmm, u64 offset, u64 length,
 	u64 mm_length = (offset + length) - mm_offset;
 	int ret;
 
-	vm = *pvm = kzalloc(sizeof(*vm), GFP_KERNEL);
+	vm = kzalloc(sizeof(*vm), GFP_KERNEL);
 	if (!vm)
 		return -ENOMEM;
 
@@ -376,6 +376,8 @@ nouveau_vm_create(struct nouveau_vmmgr *vmm, u64 offset, u64 length,
 		return ret;
 	}
 
+	*pvm = vm;
+
 	return 0;
 }
 
--