All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Adam Lewis" <adam.j.lewis@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/vmwgfx: release imported dma-buf when the BO is freed
Date: Tue, 29 Sep 2026 21:16:58 +0000	[thread overview]
Message-ID: <20260929211659.18E5E1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929205928.230301-1-adam.j.lewis@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/vmwgfx: null pointer dereference and double-free in DMA unmap on prime import teardown
--

commit 5e0534afee105a8ad6c4fdcc95d44acdb11a1c6c
Author: Adam Lewis <adam.j.lewis@gmail.com>

drm/vmwgfx: release imported dma-buf when the BO is freed

vmw_prime_import_sg_table() creates a BO for a foreign dma-buf through
drm_gem_prime_import_dev(), which attaches to the dma-buf, maps the
attachment and takes a reference on it.  vmw_bo_free() never undoes
this, so each foreign import leaks the attachment, its sg table and the
dma-buf reference.

> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> index 9c7a73c0b0dc3..f226b32312387 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
[ ... ]
> @@ -69,6 +70,8 @@ static void vmw_bo_free(struct ttm_buffer_object *bo)
>  		vmw_surface_unreference(&vbo->dumb_surface);
>  	}
>  	WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
> +	if (drm_gem_is_imported(&vbo->tbo.base))
> +		drm_prime_gem_destroy(&vbo->tbo.base, vbo->tbo.sg);

[Severity: High]
Does this trigger a null pointer dereference and double-free during DMA unmap?

For imported dma-bufs, ttm_bo_release() first calls
ttm_bo_cleanup_memtype_use(), which calls vmw_ttm_unmap_dma():

drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c:vmw_ttm_unmap_dma() {
    ...
	case vmw_dma_map_bind:
	case vmw_dma_map_populate:
		vmw_ttm_unmap_from_dma(vmw_tt);
		sg_free_table(vmw_tt->vsgt.sgt);
		vmw_tt->vsgt.sgt = NULL;
		break;
    ...
}

This frees the exporter's sg_table arrays using sg_free_table(), setting
sgt->sgl to NULL but leaving sgt->nents intact.

Later, vmw_bo_free() calls drm_prime_gem_destroy(), prompting the exporter
to call dma_unmap_sgtable(). The unmap function passes sgt->sgl (which is now
NULL) to dma_unmap_sg_attrs(), resulting in a guaranteed null pointer
dereference when iterating over the scatterlist.

>  	drm_gem_object_release(&vbo->tbo.base);
>  	WARN_ON(vbo->dirty);
>  	kfree(vbo);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260929205928.230301-1-adam.j.lewis@gmail.com?part=1

  reply	other threads:[~2026-09-29 21:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 20:59 [PATCH] drm/vmwgfx: release imported dma-buf when the BO is freed Adam Lewis
2026-09-29 21:16 ` sashiko-bot [this message]
2026-10-01 22:16 ` Adam Lewis

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=20260929211659.18E5E1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=adam.j.lewis@gmail.com \
    --cc=dri-devel@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.