All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jesse Zhang" <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH V2 1/2] drm/amdgpu: reject userptr BOs as userqueue write pointers
Date: Mon, 30 Nov 2026 06:51:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-240529@kernel.org> (raw)
In-Reply-To: <20261130062604.1921479-1-Jesse.Zhang@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: userptr check bypass via zero addr in
  amdgpu_ttm_tt_is_userptr()
--

commit 49d56b1a7c36fe3478f82185ee8e35956c14e164
Author: Jesse Zhang <Jesse.Zhang@amd.com>

drm/amdgpu: reject userptr BOs as userqueue write pointers

This commit rejects userptr BOs in amdgpu_userq_fence_read_wptr() and
mes_userq_create_wptr_mapping() using amdgpu_ttm_tt_is_userptr().

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> index 614599ba5455a..443a00514035f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> @@ -401,6 +401,12 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_device *adev,
>  	}
>  
>  	bo = mapping->bo_va->base.bo;
> +	/* Userptr pages may not be populated when reading the WPTR. */
> +	if (amdgpu_ttm_tt_is_userptr(bo->tbo.ttm)) {
> +		ret = -EINVAL;
> +		goto lock_error;
> +	}
> +
>  	ret = amdgpu_bo_kmap(bo, (void **)&ptr);
>  	if (ret) {
>  		DRM_ERROR("Failed mapping the userqueue wptr bo");
> diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> index 7abb9d95ef59a..3d4bc3a902a32 100644
> --- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> @@ -73,7 +73,9 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
>  	}
>  
>  	wptr_obj->obj = amdgpu_bo_ref(wptr_mapping->bo_va->base.bo);
> -	if (wptr_obj->obj->tbo.base.size > PAGE_SIZE) {
> +	/* Userptr pages cannot be obtained by ttm_bo_validate(). */
> +	if (wptr_obj->obj->tbo.base.size > PAGE_SIZE ||
> +	    amdgpu_ttm_tt_is_userptr(wptr_obj->obj->tbo.ttm)) {
>  		ret = -EINVAL;
>  		goto fail_map;
>  	}

[Severity: High]
Can a userptr BO created with addr == 0 bypass both of these
amdgpu_ttm_tt_is_userptr() checks?

amdgpu_gem_userptr_ioctl() permits args->addr == 0 (for example with
AMDGPU_GEM_USERPTR_READONLY and without AMDGPU_GEM_USERPTR_VALIDATE),
which leaves gtt->userptr == 0, sets TTM_TT_FLAG_EXTERNAL, and leaves
ttm->pages unpopulated.  Because amdgpu_ttm_tt_is_userptr() tests
!gtt->userptr rather than gtt->usertask:

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:amdgpu_ttm_tt_is_userptr() {
	struct amdgpu_ttm_tt *gtt = ttm_to_amdgpu_ttm_tt(ttm);

	if (gtt == NULL || !gtt->userptr)
		return false;

	return true;
}

it returns false when gtt->userptr == 0.  Calling amdgpu_bo_kmap() on that
BO in amdgpu_userq_fence_read_wptr() then reaches ttm_bo_kmap_ttm() with
ttm->pages[0] == NULL, and validating it into GTT in
mes_userq_create_wptr_mapping() reaches amdgpu_ttm_backend_bind() with
gtt->gobj->import_attach == NULL, both causing a NULL pointer
dereference.

Checking gtt->usertask (as amdgpu_ttm_tt_get_usermm() does) in
amdgpu_ttm_tt_is_userptr() would catch userptr BOs regardless of address.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130062604.1921479-1-Jesse.Zhang@amd.com?part=1

      parent reply	other threads:[~2026-11-30  6:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  6:25 [PATCH V2 1/2] drm/amdgpu: reject userptr BOs as userqueue write pointers Jesse Zhang
2026-11-30  6:25 ` [PATCH V2 2/2] drm/amdgpu: validate the WPTR BO before handing its address to the MES Jesse Zhang
2026-11-30  6:47   ` sashiko-bot
2026-11-30  6:51 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-240529@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Jesse.Zhang@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.