]> git.baikalelectronics.ru Git - kernel.git/commitdiff
xen/gntdev: Fix dmabuf import with non-zero sgt offset
authorOleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Thu, 13 Aug 2020 06:21:09 +0000 (09:21 +0300)
committerJuergen Gross <jgross@suse.com>
Thu, 13 Aug 2020 10:50:22 +0000 (12:50 +0200)
It is possible that the scatter-gather table during dmabuf import has
non-zero offset of the data, but user-space doesn't expect that.
Fix this by failing the import, so user-space doesn't access wrong data.

Fixes: bf8dc55b1358 ("xen/gntdev: Implement dma-buf import functionality")
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Acked-by: Juergen Gross <jgross@suse.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200813062113.11030-2-andr2000@gmail.com
Signed-off-by: Juergen Gross <jgross@suse.com>
drivers/xen/gntdev-dmabuf.c

index 75d3bb948bf33c63dffd8db94f80be2208694b59..b1b6eebafd5deade7d2d689b54ee819a1208414f 100644 (file)
@@ -613,6 +613,14 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev,
                goto fail_detach;
        }
 
+       /* Check that we have zero offset. */
+       if (sgt->sgl->offset) {
+               ret = ERR_PTR(-EINVAL);
+               pr_debug("DMA buffer has %d bytes offset, user-space expects 0\n",
+                        sgt->sgl->offset);
+               goto fail_unmap;
+       }
+
        /* Check number of pages that imported buffer has. */
        if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) {
                ret = ERR_PTR(-EINVAL);