All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maaz Mombasawala" <maaz.mombasawala@broadcom.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7] drm/vmwgfx: Reserve ttm object before resv usage
Date: Tue, 17 Nov 2026 01:24:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-218040@kernel.org> (raw)
In-Reply-To: <20261117005945.806941-2-maaz.mombasawala@broadcom.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/vmwgfx: UAF and NULL deref on guest_memory_bo in
  crc_generate_worker()
- [Low] drm/vmwgfx: missing Fixes trailer and inaccurate TTM type in
  commit message
--

commit 9ec8429beccaa97a3b1b9ddc00c56d85a9cbdb38
Author: Maaz Mombasawala <maaz.mombasawala@broadcom.com>

> drm/vmwgfx: Reserve ttm object before resv usage
> 
> We hit dma_resv_assert_held warnings, reserve the ttm base object when it's
> being used to avoid them.
> 
> Signed-off-by: Maaz Mombasawala <maaz.mombasawala@broadcom.com>

[Severity: Low]
This fixes the unreserved BO map in compute_crc().  Should it include:

  Fixes: 7b0062036c3b ("drm/vmwgfx: Implement virtual crc generation")

Also, surf->res.guest_memory_bo->tbo is a struct ttm_buffer_object rather
than a struct ttm_base_object.

> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
> index 3d0d5dfa869f9..ef163d4b64d1f 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
> @@ -131,6 +131,7 @@ crc_generate_worker(struct work_struct *work)
>  	spin_unlock_irq(&du->vkms.crc_state_lock);
>  
>  	if (surf) {
> +		int ret;
>  		if (vmw_surface_sync(vmw, surf)) {
>  			drm_warn(
>  				crtc->dev,
> @@ -138,7 +139,14 @@ crc_generate_worker(struct work_struct *work)
>  			return;
>  		}
>  
> +		ret = ttm_bo_reserve(&surf->res.guest_memory_bo->tbo, false, false, NULL);
> +		if (ret != 0) {
> +			drm_warn(&vmw->drm, "%s: failed reserve\n", __func__);
> +			goto done;
> +		}
>  		compute_crc(crtc, surf, &crc32);
> +		ttm_bo_unreserve(&surf->res.guest_memory_bo->tbo);

[Severity: High]
Can surf->res.guest_memory_bo become NULL or be freed while
crc_generate_worker() accesses it?

crc_generate_worker() holds a reference on surf, but res->guest_memory_bo
is only stabilized while surf->res is reserved or pinned.  During an
atomic commit, drm_atomic_helper_commit_tail() cleans up and unpins the
old plane state's surface before vmw_atomic_commit_tail() flushes
du->vkms.crc_generator_work.  For a dumb scanout buffer, vmw_dumb_create()
drops the surface's GEM reference on the BO, so once the FB and dumb BO
are destroyed, vmw_bo_free() clears surf->res.guest_memory_bo and frees
the BO even while crc_generate_worker() still holds surf:

CPU0                                  kworker (crc_generate_worker)
----                                  -----------------------------
vmw_atomic_commit_tail()
  drm_atomic_helper_commit_tail()
    ...
      vmw_stdu_primary_plane_cleanup_fb()
        vmw_resource_unpin(&surf->res)
                                      surf = vmw_surface_reference(...)
                                      vmw_surface_sync(vmw, surf)
vmw_bo_free()
  res->guest_memory_bo = NULL
  ...
  kfree(vbo)
                                      ttm_bo_reserve(
                                        &surf->res.guest_memory_bo->tbo, ...)
                                        <-- NULL pointer dereference / UAF

If vmw_bo_free() or vmw_cmd_bind_gb_surface() changes
surf->res.guest_memory_bo between ttm_bo_reserve() and
ttm_bo_unreserve(), re-reading surf->res.guest_memory_bo in
ttm_bo_unreserve() also unlocks the wrong reservation object or
dereferences NULL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117005945.806941-2-maaz.mombasawala@broadcom.com?part=1

      reply	other threads:[~2026-11-17  1:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  0:59 [PATCH v7] drm/vmwgfx: Reserve ttm object before resv usage Maaz Mombasawala
2026-11-17  1:24 ` 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-218040@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=maaz.mombasawala@broadcom.com \
    --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.