[next] drm/amdkfd: fix null pointer dereference on dev

Submitted by Colin King on May 29, 2019, 3:07 p.m.

Details

Message ID 20190529150734.18120-1-colin.king@canonical.com
State New
Headers show
Series "drm/amdkfd: fix null pointer dereference on dev" ( rev: 1 ) in DRI devel

Not browsing as part of any series.

Commit Message

Colin King May 29, 2019, 3:07 p.m.
From: Colin Ian King <colin.king@canonical.com>

The pointer dev is set to null yet it is being dereferenced when
checking dev->dqm->sched_policy.  Fix this by performing the check
on dev->dqm->sched_policy after dev has been assigned and null
checked.  Also remove the redundant null assignment to dev.

Addresses-Coverity: ("Explicit null dereference")
Fixes: 1a058c337676 ("drm/amdkfd: New IOCTL to allocate queue GWS")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index aab2aa6c1dee..ea82828fdc76 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1572,10 +1572,9 @@  static int kfd_ioctl_alloc_queue_gws(struct file *filep,
 {
 	int retval;
 	struct kfd_ioctl_alloc_queue_gws_args *args = data;
-	struct kfd_dev *dev = NULL;
+	struct kfd_dev *dev;
 
-	if (!hws_gws_support ||
-		dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
+	if (!hws_gws_support)
 		return -EINVAL;
 
 	dev = kfd_device_by_id(args->gpu_id);
@@ -1583,6 +1582,8 @@  static int kfd_ioctl_alloc_queue_gws(struct file *filep,
 		pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
 		return -EINVAL;
 	}
+	if (dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
+		return -EINVAL;
 
 	mutex_lock(&p->mutex);
 	retval = pqm_set_gws(&p->pqm, args->queue_id, args->num_gws ? dev->gws : NULL);

Comments

On 2019-05-29 11:07 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>

>

> The pointer dev is set to null yet it is being dereferenced when

> checking dev->dqm->sched_policy.  Fix this by performing the check

> on dev->dqm->sched_policy after dev has been assigned and null

> checked.  Also remove the redundant null assignment to dev.

>

> Addresses-Coverity: ("Explicit null dereference")

> Fixes: 1a058c337676 ("drm/amdkfd: New IOCTL to allocate queue GWS")

> Signed-off-by: Colin Ian King <colin.king@canonical.com>


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


Thanks!

   Felix

> ---

>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 7 ++++---

>   1 file changed, 4 insertions(+), 3 deletions(-)

>

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

> index aab2aa6c1dee..ea82828fdc76 100644

> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

> @@ -1572,10 +1572,9 @@ static int kfd_ioctl_alloc_queue_gws(struct file *filep,

>   {

>   	int retval;

>   	struct kfd_ioctl_alloc_queue_gws_args *args = data;

> -	struct kfd_dev *dev = NULL;

> +	struct kfd_dev *dev;

>   

> -	if (!hws_gws_support ||

> -		dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)

> +	if (!hws_gws_support)

>   		return -EINVAL;

>   

>   	dev = kfd_device_by_id(args->gpu_id);

> @@ -1583,6 +1582,8 @@ static int kfd_ioctl_alloc_queue_gws(struct file *filep,

>   		pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);

>   		return -EINVAL;

>   	}

> +	if (dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)

> +		return -EINVAL;

>   

>   	mutex_lock(&p->mutex);

>   	retval = pqm_set_gws(&p->pqm, args->queue_id, args->num_gws ? dev->gws : NULL);