<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 10, 2022 at 12:26 PM Christian König <<a href="mailto:ckoenig.leichtzumerken@gmail.com">ckoenig.leichtzumerken@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Previously when we added a fence to a dma_resv object we always<br>
assumed the the newer than all the existing fences.<br>
<br>
With Jason's work to add an UAPI to explicit export/import that's not<br>
necessary the case any more. So without this check we would allow<br>
userspace to force the kernel into an use after free error.<br>
<br>
Since the change is very small and defensive it's probably a good<br>
idea to backport this to stable kernels as well just in case others<br>
are using the dma_resv object in the same way.<br></blockquote><div><br></div><div>Especially in the new world of dma_resv being a "bag of fences", I think this makes a lot of sense.</div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@collabora.com">jason.ekstrand@collabora.com</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Signed-off-by: Christian König <<a href="mailto:christian.koenig@amd.com" target="_blank">christian.koenig@amd.com</a>><br>
---<br>
 drivers/dma-buf/dma-resv.c | 3 ++-<br>
 1 file changed, 2 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c<br>
index 205acb2c744d..e3885c90a3ac 100644<br>
--- a/drivers/dma-buf/dma-resv.c<br>
+++ b/drivers/dma-buf/dma-resv.c<br>
@@ -295,7 +295,8 @@ void dma_resv_add_fence(struct dma_resv *obj, struct dma_fence *fence,<br>
                enum dma_resv_usage old_usage;<br>
<br>
                dma_resv_list_entry(fobj, i, obj, &old, &old_usage);<br>
-               if ((old->context == fence->context && old_usage >= usage) ||<br>
+               if ((old->context == fence->context && old_usage >= usage &&<br>
+                    dma_fence_is_later(fence, old)) ||<br>
                    dma_fence_is_signaled(old)) {<br>
                        dma_resv_list_set(fobj, i, fence, usage);<br>
                        dma_fence_put(old);<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>