Skip to contentSkip to conversation

drm/amdkfd: Fix NULL pointer dereference in svm_migrate_to_ram()

PATCH In review Yang Li 2 participants 2 messages Oct 25, 2022

Subsystems (3)
lore
Share & tools
lore

Yang Li

author
#0 lore raw

PATCH 1/1 drm/amdkfd: Fix NULL pointer dereference in svm_migrate_to_ram()

./drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:985:58-62: ERROR: p is NULL but dereferenced.

---
 drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +2 -1
index cddf259875c0..405dd51521dc 100644
@@ -981,7 +981,8 @@ static vm_fault_t svm_migrate_to_ram(struct vm_fault *vmf)
 out_mmput:
 	mmput(mm);
 
-	pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);
+	if (p)
+		pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);
 
 	return r ? VM_FAULT_SIGBUS : 0;
 }
Signature · 1 line
2.20.1.7.g153144c
maintainer
#1 lore raw

Am 2022-10-25 um 03:28 schrieb Yang Li:

Quoted 14 lines

./drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:985:58-62: ERROR: p is NULL but dereferenced.

---
  drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +0 -0
index cddf259875c0..405dd51521dc 100644

drivers/gpu/drm/amd/amdkfd/kfd_migrate.c static vm_fault_t svm_migrate_to_ram(struct vm_fault *vmf) · line 985

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +2 -1
@@ -981,7 +981,8 @@ static vm_fault_t svm_migrate_to_ram(struct vm_fault *vmf)
  out_mmput:
  	mmput(mm);
 
-	pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);
+	if (p)
+		pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);

Thank you for catching and reporting this problem. I think the correct solution would be to move the pr_debug up before the kfd_unref_process call. That way you're sure that the pointer is initialized and that it represents a valid reference to the kfd_process structure.

Regards,
  Felix

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +0 -0
  	return r ? VM_FAULT_SIGBUS : 0;
  }