[-next] drm/amdkfd: Fix NULL pointer dereference in svm_migrate_to_ram()

Message ID 20221026020054.57114-1-yang.lee@linux.alibaba.com
State New
Headers
Series [-next] drm/amdkfd: Fix NULL pointer dereference in svm_migrate_to_ram() |

Commit Message

Yang Li Oct. 26, 2022, 2 a.m. UTC
  ./drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:985:58-62: ERROR: p is NULL but dereferenced.

Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=2549
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---

change in v2:
According to Felix's suggestion, move the pr_debug up before the kfd_unref_process 
call. 

 drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
  

Comments

Felix Kuehling Oct. 26, 2022, 8:37 p.m. UTC | #1
On 2022-10-25 22:00, Yang Li wrote:
> ./drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:985:58-62: ERROR: p is NULL but dereferenced.
>
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=2549
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>

The patch is

Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>

I applied to our amd-staging-drm-next branch.

Thanks,
   Felix


> ---
>
> change in v2:
> According to Felix's suggestion, move the pr_debug up before the kfd_unref_process
> call.
>
>   drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> index 20d6b2578927..b9c8d29d95aa 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> @@ -978,12 +978,10 @@ static vm_fault_t svm_migrate_to_ram(struct vm_fault *vmf)
>   out_unlock_svms:
>   	mutex_unlock(&p->svms.lock);
>   out_unref_process:
> +	pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);
>   	kfd_unref_process(p);
>   out_mmput:
>   	mmput(mm);
> -
> -	pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);
> -
>   	return r ? VM_FAULT_SIGBUS : 0;
>   }
>
  

Patch

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
index 20d6b2578927..b9c8d29d95aa 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
@@ -978,12 +978,10 @@  static vm_fault_t svm_migrate_to_ram(struct vm_fault *vmf)
 out_unlock_svms:
 	mutex_unlock(&p->svms.lock);
 out_unref_process:
+	pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);
 	kfd_unref_process(p);
 out_mmput:
 	mmput(mm);
-
-	pr_debug("CPU fault svms 0x%p address 0x%lx done\n", &p->svms, addr);
-
 	return r ? VM_FAULT_SIGBUS : 0;
 }