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

[Xen-changelog] [xen staging] sysctl: use xmalloc_array() for XEN_SYSCTL_page_offline_op



commit 7ad2164e922ebd7ee1543ba76f971cce22c27dc2
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Feb 18 17:52:10 2020 +0100
Commit:     Julien Grall <julien@xxxxxxx>
CommitDate: Wed Feb 19 12:35:36 2020 +0000

    sysctl: use xmalloc_array() for XEN_SYSCTL_page_offline_op
    
    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@xxxxxxxx>
---
 xen/common/sysctl.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c
index f88a285e7f..1c6a817476 100644
--- a/xen/common/sysctl.c
+++ b/xen/common/sysctl.c
@@ -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");
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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