]> xenbits.xensource.com Git - people/dwmw2/xen.git/commitdiff
sysctl: use xmalloc_array() for XEN_SYSCTL_page_offline_op
authorJan Beulich <jbeulich@suse.com>
Tue, 18 Feb 2020 16:52:10 +0000 (17:52 +0100)
committerJulien Grall <julien@xen.org>
Wed, 19 Feb 2020 12:35:36 +0000 (12:35 +0000)
This is more robust than the raw xmalloc_bytes().

Also add a sanity check on the input page range, to avoid returning
the less applicable -ENOMEM in such cases (and trying the allocation in
the first place).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
xen/common/sysctl.c

index f88a285e7f263b4bf1cf5ca14230bf6f42eea0d0..1c6a817476ba2008735e842bdc85ed546c6b2faa 100644 (file)
@@ -187,13 +187,17 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         uint32_t *status, *ptr;
         mfn_t mfn;
 
+        ret = -EINVAL;
+        if ( op->u.page_offline.end < op->u.page_offline.start )
+            break;
+
         ret = xsm_page_offline(XSM_HOOK, op->u.page_offline.cmd);
         if ( ret )
             break;
 
-        ptr = status = xmalloc_bytes( sizeof(uint32_t) *
-                                (op->u.page_offline.end -
-                                  op->u.page_offline.start + 1));
+        ptr = status = xmalloc_array(uint32_t,
+                                     (op->u.page_offline.end -
+                                      op->u.page_offline.start + 1));
         if ( !status )
         {
             dprintk(XENLOG_WARNING, "Out of memory for page offline op\n");