Skip to content

Commit e4ca018

Browse files
Oleksandr Andrushchenkogregkh
authored andcommitted
xen/gntdev: Fix dmabuf import with non-zero sgt offset
commit 5fa4e6f upstream. 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: bf8dc55 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0fc9dd0 commit e4ca018

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

drivers/xen/gntdev-dmabuf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev,
641641
goto fail_detach;
642642
}
643643

644+
/* Check that we have zero offset. */
645+
if (sgt->sgl->offset) {
646+
ret = ERR_PTR(-EINVAL);
647+
pr_debug("DMA buffer has %d bytes offset, user-space expects 0\n",
648+
sgt->sgl->offset);
649+
goto fail_unmap;
650+
}
651+
644652
/* Check number of pages that imported buffer has. */
645653
if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) {
646654
ret = ERR_PTR(-EINVAL);

0 commit comments

Comments
 (0)