All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Philipp Stanner" <phasta@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference
Date: Mon, 29 Jun 2026 08:05:44 +0000	[thread overview]
Message-ID: <20260629080545.204691F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260629075636.2513214-2-phasta@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Replacing the signaled-bit check with an `ops` null-check causes driver callbacks to be executed on signaled fences, violating the dma-fence contract and leading to a Use-After-Free.
--

commit f3771b2534b5990287b2b373aaf5a26b9dea2923
Author: Philipp Stanner <phasta@kernel.org>

dma-buf: dma-fence: Fix potential NULL pointer dereference

The patch removes the signaled-bit check in dma_fence_timeline_name() and
dma_fence_driver_name(), replacing it with a check for a non-NULL ops pointer
to prevent potential out-of-order execution issues.

> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> index c7ea1e75d38a2..0a025dfdf131e 100644
> --- a/drivers/dma-buf/dma-fence.c
> +++ b/drivers/dma-buf/dma-fence.c
> @@ -1170,7 +1170,7 @@ const char __rcu *dma_fence_driver_name(struct dma_fence *fence)
>  
>  	/* RCU protection is required for safe access to returned string */
>  	ops = rcu_dereference(fence->ops);
> -	if (!dma_fence_test_signaled_flag(fence))
> +	if (ops)

[Severity: High]
Does this expose a use-after-free for signaled fences?

If a fence has a .release or .wait callback,
dma_fence_signal_timestamp_locked() does not set fence->ops to NULL. For
those fences, ops will remain non-NULL indefinitely even after they are
signaled.

By removing the signaled-bit check, won't ops->get_driver_name(fence) be
called on signaled fences? The dma-fence contract states that backing data
can be freed after an RCU grace period once the fence is signaled, so calling
this callback could access freed memory.

>  		return (const char __rcu *)ops->get_driver_name(fence);
>  	else
>  		return (const char __rcu *)"detached-driver";
> @@ -1203,7 +1203,7 @@ const char __rcu *dma_fence_timeline_name(struct dma_fence *fence)
>  
>  	/* RCU protection is required for safe access to returned string */
>  	ops = rcu_dereference(fence->ops);
> -	if (!dma_fence_test_signaled_flag(fence))
> +	if (ops)

[Severity: High]
Could this lead to the same use-after-free as above?

Since ops can remain non-NULL for signaled fences that provide a .release
or .wait callback, this allows the ops callback to be executed after the
fence is signaled and its backing data is potentially freed.

>  		return (const char __rcu *)ops->get_driver_name(fence);
>  	else
>  		return (const char __rcu *)"signaled-timeline";

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260629075636.2513214-2-phasta@kernel.org?part=1

  reply	other threads:[~2026-06-29  8:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29  7:56 [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference Philipp Stanner
2026-06-29  8:05 ` sashiko-bot [this message]
2026-06-29  8:41 ` Boris Brezillon
2026-06-29  8:49 ` Christian König
2026-06-29 10:43   ` Philipp Stanner
2026-06-29 11:25     ` Christian König
2026-06-29  9:10 ` Danilo Krummrich

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=20260629080545.204691F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=phasta@kernel.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.