Skip to content

Commit 429aec2

Browse files
srishanmalexdeucher
authored andcommitted
drm/amdkfd: Fix NULL pointer check order in kfd_ioctl_create_process
In kfd_ioctl_create_process(), the pointer 'p' is used before checking if it is NULL. The code accesses p->context_id before validating 'p'. This can lead to a possible NULL pointer dereference. Move the NULL check before using 'p' so that the pointer is validated before access. Fixes the below: drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_chardev.c:3177 kfd_ioctl_create_process() warn: variable dereferenced before check 'p' (see line 3174) Fixes: cc6b66d ("amdkfd: introduce new ioctl AMDKFD_IOC_CREATE_PROCESS") Cc: Zhu Lingshan <lingshan.zhu@amd.com> Cc: Felix Kuehling <felix.kuehling@amd.com> Cc: Christian König <christian.koenig@amd.com> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 19d4149)
1 parent 9da4f99 commit 429aec2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,11 +3170,11 @@ static int kfd_ioctl_create_process(struct file *filep, struct kfd_process *p, v
31703170
struct kfd_process *process;
31713171
int ret;
31723172

3173-
/* Each FD owns only one kfd_process */
3174-
if (p->context_id != KFD_CONTEXT_ID_PRIMARY)
3173+
if (!filep->private_data || !p)
31753174
return -EINVAL;
31763175

3177-
if (!filep->private_data || !p)
3176+
/* Each FD owns only one kfd_process */
3177+
if (p->context_id != KFD_CONTEXT_ID_PRIMARY)
31783178
return -EINVAL;
31793179

31803180
mutex_lock(&kfd_processes_mutex);

0 commit comments

Comments
 (0)