The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference
@ 2026-06-29  7:56 Philipp Stanner
  2026-06-29  8:41 ` Boris Brezillon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-06-29  7:56 UTC (permalink / raw)
  To: Sumit Semwal, Christian König, Boris Brezillon,
	Tvrtko Ursulin, André Draszik, Danilo Krummrich, Gary Guo,
	Paul E . McKenney, Boqun Feng
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel,
	Philipp Stanner, stable

The commit mentioned in the fixes tag below introduced a mechanism
through which fence producers can fully decouple from fence consumers.
This, desirable, mechanism is based on the fence's signaled-bit as the
"decoupling point".

A sophisticated interaction between RCU and atomic instructions attempts
to ensure that fence consumers can still interact with fence producers
through the dma_fence_ops (callback pointers into the producer).

This is the desired behavior: to check for decoupling, the signaled-bit
is first checked. If it's not yet signaled, RCU ensures that the ops
pointer cannot yet be NULL.

Hereby, dma_fence_signal_timestamp_locked() first sets the signaled-bit,
and then sets the ops pointer to NULL. Readers first load the ops
pointer, and then check through the signaled-bit whether the pointer can
legally be accessed.

These set and load operations could occur out of order on weakly ordered
platforms. This problem can be solved very elegantly by using the ops
pointer itself as the synchronization point. The pointer is either NULL,
or cannot become NULL while it is being used thanks to RCU.

Replace the signaled-bit check in dma_fence_timeline_name() and
dma_fence_driver_name().

Cc: stable@vger.kernel.org
Fixes: f4cc3ab824d6 ("dma-buf: protected fence ops by RCU v8")
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
Changes since v1:
  - Use ops pointer instead of memory barriers. (Christian)
  - Rephrase commit message.
---
 drivers/dma-buf/dma-fence.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index c7ea1e75d38a..0a025dfdf131 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)
 		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)
 		return (const char __rcu *)ops->get_driver_name(fence);
 	else
 		return (const char __rcu *)"signaled-timeline";

base-commit: cdeb2ccd993ed8647adbbda2c3b103aa717fd6f7
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference
  2026-06-29  7:56 [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference Philipp Stanner
@ 2026-06-29  8:41 ` Boris Brezillon
  2026-06-29  8:49 ` Christian König
  2026-06-29  9:10 ` Danilo Krummrich
  2 siblings, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2026-06-29  8:41 UTC (permalink / raw)
  To: Philipp Stanner
  Cc: Sumit Semwal, Christian König, Tvrtko Ursulin,
	André Draszik, Danilo Krummrich, Gary Guo, Paul E . McKenney,
	Boqun Feng, linux-media, dri-devel, linaro-mm-sig, linux-kernel,
	stable

On Mon, 29 Jun 2026 09:56:37 +0200
Philipp Stanner <phasta@kernel.org> wrote:

> The commit mentioned in the fixes tag below introduced a mechanism
> through which fence producers can fully decouple from fence consumers.
> This, desirable, mechanism is based on the fence's signaled-bit as the
> "decoupling point".
> 
> A sophisticated interaction between RCU and atomic instructions attempts
> to ensure that fence consumers can still interact with fence producers
> through the dma_fence_ops (callback pointers into the producer).
> 
> This is the desired behavior: to check for decoupling, the signaled-bit
> is first checked. If it's not yet signaled, RCU ensures that the ops
> pointer cannot yet be NULL.
> 
> Hereby, dma_fence_signal_timestamp_locked() first sets the signaled-bit,
> and then sets the ops pointer to NULL. Readers first load the ops
> pointer, and then check through the signaled-bit whether the pointer can
> legally be accessed.
> 
> These set and load operations could occur out of order on weakly ordered
> platforms. This problem can be solved very elegantly by using the ops
> pointer itself as the synchronization point. The pointer is either NULL,
> or cannot become NULL while it is being used thanks to RCU.
> 
> Replace the signaled-bit check in dma_fence_timeline_name() and
> dma_fence_driver_name().
> 
> Cc: stable@vger.kernel.org
> Fixes: f4cc3ab824d6 ("dma-buf: protected fence ops by RCU v8")
> Signed-off-by: Philipp Stanner <phasta@kernel.org>

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>

> ---
> Changes since v1:
>   - Use ops pointer instead of memory barriers. (Christian)
>   - Rephrase commit message.
> ---
>  drivers/dma-buf/dma-fence.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> index c7ea1e75d38a..0a025dfdf131 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)
>  		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)
>  		return (const char __rcu *)ops->get_driver_name(fence);
>  	else
>  		return (const char __rcu *)"signaled-timeline";
> 
> base-commit: cdeb2ccd993ed8647adbbda2c3b103aa717fd6f7


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference
  2026-06-29  7:56 [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference Philipp Stanner
  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  9:10 ` Danilo Krummrich
  2 siblings, 1 reply; 6+ messages in thread
From: Christian König @ 2026-06-29  8:49 UTC (permalink / raw)
  To: Philipp Stanner, Sumit Semwal, Boris Brezillon, Tvrtko Ursulin,
	André Draszik, Danilo Krummrich, Gary Guo, Paul E . McKenney,
	Boqun Feng
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel, stable

On 6/29/26 09:56, Philipp Stanner wrote:
> The commit mentioned in the fixes tag below introduced a mechanism
> through which fence producers can fully decouple from fence consumers.
> This, desirable, mechanism is based on the fence's signaled-bit as the
> "decoupling point".
> 
> A sophisticated interaction between RCU and atomic instructions attempts
> to ensure that fence consumers can still interact with fence producers
> through the dma_fence_ops (callback pointers into the producer).
> 
> This is the desired behavior: to check for decoupling, the signaled-bit
> is first checked. If it's not yet signaled, RCU ensures that the ops
> pointer cannot yet be NULL.
> 
> Hereby, dma_fence_signal_timestamp_locked() first sets the signaled-bit,
> and then sets the ops pointer to NULL. Readers first load the ops
> pointer, and then check through the signaled-bit whether the pointer can
> legally be accessed.
> 
> These set and load operations could occur out of order on weakly ordered
> platforms. This problem can be solved very elegantly by using the ops
> pointer itself as the synchronization point. The pointer is either NULL,
> or cannot become NULL while it is being used thanks to RCU.
> 
> Replace the signaled-bit check in dma_fence_timeline_name() and
> dma_fence_driver_name().
> 
> Cc: stable@vger.kernel.org
> Fixes: f4cc3ab824d6 ("dma-buf: protected fence ops by RCU v8")
> Signed-off-by: Philipp Stanner <phasta@kernel.org>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
> Changes since v1:
>   - Use ops pointer instead of memory barriers. (Christian)
>   - Rephrase commit message.
> ---
>  drivers/dma-buf/dma-fence.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> index c7ea1e75d38a..0a025dfdf131 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)
>  		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)
>  		return (const char __rcu *)ops->get_driver_name(fence);
>  	else
>  		return (const char __rcu *)"signaled-timeline";
> 
> base-commit: cdeb2ccd993ed8647adbbda2c3b103aa717fd6f7


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference
  2026-06-29  7:56 [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference Philipp Stanner
  2026-06-29  8:41 ` Boris Brezillon
  2026-06-29  8:49 ` Christian König
@ 2026-06-29  9:10 ` Danilo Krummrich
  2 siblings, 0 replies; 6+ messages in thread
From: Danilo Krummrich @ 2026-06-29  9:10 UTC (permalink / raw)
  To: Philipp Stanner
  Cc: Sumit Semwal, Christian König, Boris Brezillon,
	Tvrtko Ursulin, André Draszik, Gary Guo, Paul E . McKenney,
	Boqun Feng, linux-media, dri-devel, linaro-mm-sig, linux-kernel,
	stable

On 6/29/26 9:56 AM, Philipp Stanner wrote:
> The commit mentioned in the fixes tag below introduced a mechanism
> through which fence producers can fully decouple from fence consumers.
> This, desirable, mechanism is based on the fence's signaled-bit as the
> "decoupling point".
> 
> A sophisticated interaction between RCU and atomic instructions attempts
> to ensure that fence consumers can still interact with fence producers
> through the dma_fence_ops (callback pointers into the producer).
> 
> This is the desired behavior: to check for decoupling, the signaled-bit
> is first checked. If it's not yet signaled, RCU ensures that the ops
> pointer cannot yet be NULL.
> 
> Hereby, dma_fence_signal_timestamp_locked() first sets the signaled-bit,
> and then sets the ops pointer to NULL. Readers first load the ops
> pointer, and then check through the signaled-bit whether the pointer can
> legally be accessed.
> 
> These set and load operations could occur out of order on weakly ordered
> platforms. This problem can be solved very elegantly by using the ops
> pointer itself as the synchronization point. The pointer is either NULL,
> or cannot become NULL while it is being used thanks to RCU.
> 
> Replace the signaled-bit check in dma_fence_timeline_name() and
> dma_fence_driver_name().
> 
> Cc: stable@vger.kernel.org
> Fixes: f4cc3ab824d6 ("dma-buf: protected fence ops by RCU v8")
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference
  2026-06-29  8:49 ` Christian König
@ 2026-06-29 10:43   ` Philipp Stanner
  2026-06-29 11:25     ` Christian König
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Stanner @ 2026-06-29 10:43 UTC (permalink / raw)
  To: Christian König, Philipp Stanner, Sumit Semwal,
	Boris Brezillon, Tvrtko Ursulin, André Draszik,
	Danilo Krummrich, Gary Guo, Paul E . McKenney, Boqun Feng
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel, stable

On Mon, 2026-06-29 at 10:49 +0200, Christian König wrote:
> On 6/29/26 09:56, Philipp Stanner wrote:
> > Cc: stable@vger.kernel.org
> > Fixes: f4cc3ab824d6 ("dma-buf: protected fence ops by RCU v8")
> > Signed-off-by: Philipp Stanner <phasta@kernel.org>
> 
> Reviewed-by: Christian König <christian.koenig@amd.com>

As the maintainer you push that one, don't you Christian?

Regards
P.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference
  2026-06-29 10:43   ` Philipp Stanner
@ 2026-06-29 11:25     ` Christian König
  0 siblings, 0 replies; 6+ messages in thread
From: Christian König @ 2026-06-29 11:25 UTC (permalink / raw)
  To: phasta, Sumit Semwal, Boris Brezillon, Tvrtko Ursulin,
	André Draszik, Danilo Krummrich, Gary Guo, Paul E . McKenney,
	Boqun Feng
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel, stable

On 6/29/26 12:43, Philipp Stanner wrote:
> On Mon, 2026-06-29 at 10:49 +0200, Christian König wrote:
>> On 6/29/26 09:56, Philipp Stanner wrote:
>>> Cc: stable@vger.kernel.org
>>> Fixes: f4cc3ab824d6 ("dma-buf: protected fence ops by RCU v8")
>>> Signed-off-by: Philipp Stanner <phasta@kernel.org>
>>
>> Reviewed-by: Christian König <christian.koenig@amd.com>
> 
> As the maintainer you push that one, don't you Christian?

Already done so, but you based the patch on the wrong branch and I had to manually rebase it to drm-misc-fixes.

Christian.

> 
> Regards
> P.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-06-29 11:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29  7:56 [PATCH v2] dma-buf: dma-fence: Fix potential NULL pointer dereference Philipp Stanner
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox