From 7ad2164e922ebd7ee1543ba76f971cce22c27dc2 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 18 Feb 2020 17:52:10 +0100 Subject: [PATCH] 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 --- 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"); -- 2.39.5