[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PULL 06/21] hw/xen: Validate grant copy segments against the page size



From: David Woodhouse <dwmw@xxxxxxxxxxxx>

Reject a grant copy segment whose offset and length reach beyond the
granted page, matching Xen's GNTST_bad_copy_arg behaviour, in both the
emulated gnttab backend and the libxengnttab fallback. The only current
caller, xen-block, already bounds its segments to a single page.

Fixes: b08d88e30f06 ("hw/xen: Add emulated implementation of grant table 
operations")
Fixes: c412ba47b2ec ("hw/xen: Add gnttab operations to allow redirection to 
internal emulation")
Reported-by: Hui Peng <benquike@xxxxxxxxx>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Reviewed-by: Paul Durrant <paul@xxxxxxx>
Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
 hw/i386/kvm/xen_gnttab.c | 10 ++++++++++
 hw/xen/xen-operations.c  | 11 +++++++++++
 2 files changed, 21 insertions(+)

diff --git a/hw/i386/kvm/xen_gnttab.c b/hw/i386/kvm/xen_gnttab.c
index 26d1febac4..6e0038b22f 100644
--- a/hw/i386/kvm/xen_gnttab.c
+++ b/hw/i386/kvm/xen_gnttab.c
@@ -473,6 +473,16 @@ static int xen_be_gnttab_copy(struct xengntdev_handle 
*xgt, bool to_domain,
         void *page;
         uint32_t ref = to_domain ? seg->dest.foreign.ref :
             seg->source.foreign.ref;
+        off_t offset = to_domain ? seg->dest.foreign.offset :
+            seg->source.foreign.offset;
+
+        if (offset < 0 || offset > XEN_PAGE_SIZE ||
+            seg->len > XEN_PAGE_SIZE - offset) {
+            if (errp) {
+                error_setg(errp, "grant copy segment out of page bounds");
+            }
+            return -EINVAL;
+        }
 
         page = xen_be_gnttab_map_refs(xgt, 1, domid, &ref, prot);
         if (!page) {
diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c
index e00983ec44..bf0ec040bc 100644
--- a/hw/xen/xen-operations.c
+++ b/hw/xen/xen-operations.c
@@ -50,6 +50,17 @@ static int libxengnttab_fallback_grant_copy(xengnttab_handle 
*xgt,
 
     for (i = 0; i < nr_segs; i++) {
         XenGrantCopySegment *seg = &segs[i];
+        off_t offset = to_domain ? seg->dest.foreign.offset :
+            seg->source.foreign.offset;
+
+        if (offset < 0 || offset > XEN_PAGE_SIZE ||
+            seg->len > XEN_PAGE_SIZE - offset) {
+            if (errp) {
+                error_setg(errp, "grant copy segment out of page bounds");
+            }
+            rc = -EINVAL;
+            goto done;
+        }
 
         refs[i] = to_domain ? seg->dest.foreign.ref :
             seg->source.foreign.ref;
-- 
2.55.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.