dma-fence: Fix dma_fence_timeline_name() to call get_timeline_name()
PATCH 1/1 dma-fence: Fix dma_fence_timeline_name() to call get_timeline_name()
dma_fence_timeline_name() incorrectly invokes ops->get_driver_name() instead of ops->get_timeline_name(), so every caller receives the driver name where the timeline name was expected.
This is a copy-paste regression that has resurfaced twice. It was originally introduced by commit 62918542b7bf ("dma-fence: Fix sparse warnings due __rcu annotations") when adding the __rcu casts, fixed by commit 033559473dd3 ("dma-fence: Fix safe access wrapper to call timeline name method"), and then accidentally reintroduced by commit e58b4dea9054 ("dma-buf/dma-fence: Add dma_fence_test_signaled_flag()") when both wrappers were refactored to use the new helper.
--- drivers/dma-buf/dma-fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-fence.c +1 -1
@@ -1202,7 +1202,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)) -return (const char __rcu *)ops->get_driver_name (fence); +return (const char __rcu *)ops->get_timeline_name (fence);else return (const char __rcu *)"signaled-timeline" ; }
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Potential NULL pointer dereference in dma_fence_timeline_name() and dma_fence_driver_name() due to a missing ops NULL check when the fence is concurrently signaled without a read memory barrier. --
commit 118120d707b8593d71c08a5c22b1149fdc6d4229
Author: Baineng Shou <[email protected]>
dma-fence: Fix dma_fence_timeline_name() to call get_timeline_name()
This patch fixes a copy-paste error where dma_fence_timeline_name() incorrectly invoked get_driver_name() instead of get_timeline_name().
drivers/dma-buf/dma-fence.c const char __rcu *dma_fence_timeline_name(struct dma_fence *fence) · line 1205
Quoted 10 lines
drivers/dma-buf/dma-fence.c +1
-1@@ -1202,7 +1202,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)) -return (const char __rcu *)ops->get_driver_name (fence); +return (const char __rcu *)ops->get_timeline_name (fence);
[Severity: Critical]
This is a pre-existing issue, but is it possible for ops to be NULL here due to memory reordering?
If dma_fence_signal_timestamp_locked() runs concurrently, it sets DMA_FENCE_FLAG_SIGNALED_BIT (which includes a full memory barrier via test_and_set_bit()) and then sets fence->ops = NULL via RCU_INIT_POINTER().
Since rcu_dereference() and test_bit() inside dma_fence_test_signaled_flag() are independent memory loads without an intervening read memory barrier, could a reader on weakly-ordered architectures experience reordering?
Reader CPU:
1. Loads fence->flags -> 0 (sees not signaled)
2. Loads fence->ops -> NULL (sees new value)
3. !dma_fence_test_signaled_flag(fence) evaluates to true
4. ops->get_timeline_name(fence) dereferences NULL
Would adding a NULL check for ops, or an smp_rmb() between the reads, be necessary to prevent a potential kernel panic if this is reachable via concurrent ioctls like SYNC_IOC_FILE_INFO?
Does dma_fence_driver_name() also share this same structural vulnerability when dereferencing ops->get_driver_name?
Quoted 3 lines
drivers/dma-buf/dma-fence.c +0
-0else return (const char __rcu *)"signaled-timeline" ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
+Cc André
Quoted 12 lines · Baineng Shou
dma_fence_timeline_name()incorrectly invokesops->get_driver_name()instead ofops->get_timeline_name(), so every caller receives the driver name where the timeline name was expected.This is a copy-paste regression that has resurfaced twice. It was originally introduced by commit
62918542b7bf("dma-fence: Fix sparse warnings due__rcuannotations") when adding the__rcucasts, fixed by commit033559473dd3("dma-fence: Fix safe access wrapper to call timeline name method"), and then accidentally reintroduced by commite58b4dea9054("dma-buf/dma-fence: Adddma_fence_test_signaled_flag()") when both wrappers were refactored to use the new helper.
Quoted 1 line
Signed-off-by Baineng Shou <[email protected]>
André has caught this a few days ago already:
https://lore.kernel.org/dri-devel/[email protected]/
To save my honor I want to state that e58b4dea9054 did not actually *do this* change. But merging it must have caused it somehow, since that commit was still based on the old bug. I guess somewhere in conflict resolution somehow tho old code must have entered.
P.
Quoted 17 lines
---
drivers/dma-buf/dma-fence.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/dma-buf/dma-fence.c +1
-1@@ -1202,7 +1202,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)) -return (const char __rcu *)ops->get_driver_name (fence); +return (const char __rcu *)ops->get_timeline_name (fence);else
return (const char__rcu*)"signaled-timeline"; }