Skip to contentSkip to conversation

drm/amdkfd: fix a potential NULL pointer dereference

PATCH In review Allen Pais 2 participants 2 messages Sep 18, 2019 – Sep 19, 2019

Subsystems (3)
lore
Share & tools
lore

Allen Pais

author
#0 lore raw

PATCH 1/1 drm/amdkfd: fix a potential NULL pointer dereference

alloc_workqueue is not checked for errors and as a result, a potential NULL dereference could occur.

---
 drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +5 -0
index c56ac47..caa82a8 100644
@@ -62,6 +62,11 @@ int kfd_interrupt_init(struct kfd_dev *kfd)
 	}
 
 	kfd->ih_wq = alloc_workqueue("KFD IH", WQ_HIGHPRI, 1);
+	if (unlikely(!kfd->ih_wq)) {
+		fifo_free(&kfd->ih_fifo);
+		dev_err(kfd_chardev(), "Failed to allocate KFD IH workqueue\n");
+		return kfd->ih_wq;
+	}
 	spin_lock_init(&kfd->interrupt_lock);
 
 	INIT_WORK(&kfd->interrupt_work, interrupt_wq);
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 13 lines · Allen Pais

alloc_workqueue is not checked for errors and as a result, a potential NULL dereference could occur.

---
  drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +0 -0
index c56ac47..caa82a8 100644

drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c int kfd_interrupt_init(struct kfd_dev *kfd) · line 66

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +2 -0
@@ -62,6 +62,11 @@ int kfd_interrupt_init(struct kfd_dev *kfd)
  	}
 
  	kfd->ih_wq = alloc_workqueue("KFD IH", WQ_HIGHPRI, 1);
+	if (unlikely(!kfd->ih_wq)) {
+		fifo_free(&kfd->ih_fifo);

This does not compile. I think this should be kfifo_free.

drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c int kfd_interrupt_init(struct kfd_dev *kfd) · line 68

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +2 -0
+		dev_err(kfd_chardev(), "Failed to allocate KFD IH workqueue\n");
+		return kfd->ih_wq;

This throws a compiler warning "return makes integer from pointer without a cast". What's worse, kfd->ih_wq is NULL here and kfd_interrupt_init returns 0 to mean success, so returning a NULL pointer is definitely not what you want here. This function should return a negative error code on failure. I propose -ENOMEM.

I'm going to apply your patch with those fixes.

Regards,
  Felix

drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c int kfd_interrupt_init(struct kfd_dev *kfd) · line 72

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +1 -0
+	}
  	spin_lock_init(&kfd->interrupt_lock);
 
  	INIT_WORK(&kfd->interrupt_work, interrupt_wq);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel