From patchwork Wed Feb 5 13:16:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11366317 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 819671395 for ; Wed, 5 Feb 2020 13:17:17 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68B2E217BA for ; Wed, 5 Feb 2020 13:17:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68B2E217BA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1izKXZ-0005JS-He; Wed, 05 Feb 2020 13:16:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1izKXX-0005J7-Lb for xen-devel@lists.xenproject.org; Wed, 05 Feb 2020 13:16:23 +0000 X-Inumbo-ID: b47b73c8-4819-11ea-90f7-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b47b73c8-4819-11ea-90f7-12813bfff9fa; Wed, 05 Feb 2020 13:16:23 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7A08EAC69; Wed, 5 Feb 2020 13:16:22 +0000 (UTC) From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <730add36-bfa0-e1bb-e2cb-b5570540688c@suse.com> Message-ID: <4cf07838-40ff-a941-159a-263c9305b89d@suse.com> Date: Wed, 5 Feb 2020 14:16:29 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: <730add36-bfa0-e1bb-e2cb-b5570540688c@suse.com> Content-Language: en-US Subject: [Xen-devel] [PATCH 4/6] sysctl: use xmalloc_array() for XEN_SYSCTL_page_offline_op X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Wilk , George Dunlap , Andrew Cooper , Ilja Van Sprundel , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This is more robust than the raw xmalloc_bytes(). Also add a sanity check on the input page range. Signed-off-by: Jan Beulich --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -187,13 +187,17 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe 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");