Skip to contentSkip to conversation

dma-buf/dma-fence: Set better string for dma_fence_driver_name()

PATCH In review Philipp Stanner 3 participants 3 messages Jun 23

Subsystems (3)
lore
Share & tools
lore

Philipp Stanner

author maintainer
#0 lore raw

PATCH 1/1 dma-buf/dma-fence: Set better string for dma_fence_driver_name()

dma_fence_driver_name() reports that a driver whose fence is already signaled is a "detached-driver". This is incorrect, the driver might still be loaded and running.

Rename that string to something more descriptive.

---
Just compile-tested.

---
 drivers/dma-buf/dma-fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-fence.c +1 -1
index c7ea1e75d38a..9c3dfa7b0066 100644
@@ -1173,7 +1173,7 @@ const char __rcu *dma_fence_driver_name(struct dma_fence *fence)
 	if (!dma_fence_test_signaled_flag(fence))
 		return (const char __rcu *)ops->get_driver_name(fence);
 	else
-		return (const char __rcu *)"detached-driver";
+		return (const char __rcu *)"driver-whose-fence-is-signaled";
 }
 EXPORT_SYMBOL(dma_fence_driver_name);
 
Signature · 1 line
2.54.0
#1 lore raw
Quoted 18 lines · Philipp Stanner

dma_fence_driver_name() reports that a driver whose fence is already signaled is a "detached-driver". This is incorrect, the driver might still be loaded and running.

Rename that string to something more descriptive.

---
Just compile-tested.

---
  drivers/dma-buf/dma-fence.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-fence.c +0 -0
index c7ea1e75d38a..9c3dfa7b0066 100644

drivers/dma-buf/dma-fence.c const char __rcu *dma_fence_driver_name(struct dma_fence *fence) · line 1176

Quoted 5 lines
drivers/dma-buf/dma-fence.c +1 -1
@@ -1173,7 +1173,7 @@ const char __rcu *dma_fence_driver_name(struct dma_fence *fence)
  	if (!dma_fence_test_signaled_flag(fence))
  		return (const char __rcu *)ops->get_driver_name(fence);
  	else
-		return (const char __rcu *)"detached-driver";
+		return (const char __rcu *)"driver-whose-fence-is-signaled";

My logic was "driver detached from the fence". :)

Anyway, no strong opinion apart to be mindful on whether some output becomes overly verbose.

Regards,

Tvrtko

Quoted 3 lines
drivers/dma-buf/dma-fence.c +0 -0
  }
  EXPORT_SYMBOL(dma_fence_driver_name);
 
#2 lore raw
In reply to Philipp Stanner
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Critical] ABI breakage in UAPI sync_fence_info and severe string truncation.

Pre-existing issues:
- [Critical] Potential NULL pointer dereference due to unordered reads of fence->ops and fence->flags. --

commit 2d4e0eac87d76c56e73514e9ac37b9db142b0e4f
Author: Philipp Stanner <[email protected]>

dma-buf/dma-fence: Set better string for dma_fence_driver_name()

Rename the "detached-driver" string returned by dma_fence_driver_name() to something more descriptive for signaled fences.

drivers/dma-buf/dma-fence.c const char __rcu *dma_fence_driver_name(struct dma_fence *fence) · line 1172

Quoted 7 lines
drivers/dma-buf/dma-fence.c +0 -0
index b3bfa6943a8e1..4a326d2ba7d19 100644
@@ -1171,7 +1171,7 @@ const char __rcu *dma_fence_driver_name(struct dma_fence *fence)
 	if (!dma_fence_test_signaled_flag(fence))
 		return (const char __rcu *)ops->get_driver_name(fence);

[Severity: Critical]
This is a pre-existing issue, but could this cause a NULL pointer dereference?

In dma_fence_driver_name(), fence->ops and fence->flags are read independently without an smp_rmb() memory barrier. If the CPU reads fence->flags as unsignaled first, and concurrently another CPU signals the fence, dma_fence_signal_timestamp_locked() can set fence->flags to signaled and then set fence->ops to NULL (for fences lacking .release and .wait ops, such as virtgpu_fence or v3d_fence).

The reader CPU might then read fence->ops as NULL, take the if branch (using the cached flags=0), and crash on ops->get_driver_name(fence).

drivers/dma-buf/dma-fence.c const char __rcu *dma_fence_driver_name(struct dma_fence *fence) · line 1176

Quoted 3 lines
drivers/dma-buf/dma-fence.c +1 -1
 	else
-		return (const char __rcu *)"detached-driver";
+		return (const char __rcu *)"driver-whose-fence-is-signaled";

[Severity: Critical]
Does this break the userspace ABI and cause string truncation?

The driver_name field in struct sync_fence_info is exposed to userspace via the SYNC_IOC_FILE_INFO ioctl. Changing this string from "detached-driver" to "driver-whose-fence-is-signaled" breaks userspace tools that rely on the established string to identify decoupled fences.

Also, this formats the UAPI sync_file name into a 32-byte buffer in sync_file_get_name():

drivers/dma-buf/sync_file.c:sync_file_get_name() {
    ...
	snprintf(buf, len, "%s-%s%llu-%lld",
			 rcu_dereference(driver),
			 rcu_dereference(timeline),
			 fence->context,
			 fence->seqno);
    ...
}

The new 30-character driver name consumes almost the entire 32-byte buffer, which truncates the timeline name and all subsequent fence metadata.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1