[SRU][J][PATCH 1/1] dma-buf/dma-resv: check if the new fence is really later
Cengiz Can
cengiz.can at canonical.com
Thu Sep 10 05:03:11 UTC 2026
From: Christian König <ckoenig.leichtzumerken at gmail.com>
Previously when we added a fence to a dma_resv object we always
assumed the the newer than all the existing fences.
With Jason's work to add an UAPI to explicit export/import that's not
necessary the case any more. So without this check we would allow
userspace to force the kernel into an use after free error.
Since the change is very small and defensive it's probably a good
idea to backport this to stable kernels as well just in case others
are using the dma_resv object in the same way.
Signed-off-by: Christian König <christian.koenig at amd.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220810172617.140047-1-christian.koenig@amd.com
Cc: stable at vger.kernel.org # v5.19+
(backported from commit a3f7c10a269d5b77dd5822ade822643ced3057f0)
[bot_kybele: Applied to dma_resv_add_shared_fence (this tree predates the
unified dma_resv_add_fence refactor). No usage/dma_resv_list_entry here; added
dma_fence_is_later(fence, old) to the existing context-match check that uses
"goto replace", preserving the goto-based replace path.]
CVE-2022-49935
Assisted-by: kybele:claude-opus-4.8
Signed-off-by: Cengiz Can <cengiz.can at canonical.com>
---
drivers/dma-buf/dma-resv.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index bcce96d4a753..f29098447fb0 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -256,7 +256,8 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)
old = rcu_dereference_protected(fobj->shared[i],
dma_resv_held(obj));
- if (old->context == fence->context ||
+ if ((old->context == fence->context &&
+ dma_fence_is_later(fence, old)) ||
dma_fence_is_signaled(old))
goto replace;
}
--
2.53.0
More information about the kernel-team
mailing list