Skip to content

Commit 5fa4e6f

Browse files
Oleksandr Andrushchenkojgross1
authored andcommitted
xen/gntdev: Fix dmabuf import with non-zero sgt offset
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 <[email protected]> Acked-by: Juergen Gross <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent f2e39e8 commit 5fa4e6f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/xen/gntdev-dmabuf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,14 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev,
613613
goto fail_detach;
614614
}
615615

616+
/* Check that we have zero offset. */
617+
if (sgt->sgl->offset) {
618+
ret = ERR_PTR(-EINVAL);
619+
pr_debug("DMA buffer has %d bytes offset, user-space expects 0\n",
620+
sgt->sgl->offset);
621+
goto fail_unmap;
622+
}
623+
616624
/* Check number of pages that imported buffer has. */
617625
if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) {
618626
ret = ERR_PTR(-EINVAL);

0 commit comments

Comments
 (0)