From patchwork Fri Aug 11 13:12:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9895823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5750560236 for ; Fri, 11 Aug 2017 13:14:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 469EE23B32 for ; Fri, 11 Aug 2017 13:14:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A99C26BE9; Fri, 11 Aug 2017 13:14:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB51523B32 for ; Fri, 11 Aug 2017 13:14:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dg9jh-0008IC-3V; Fri, 11 Aug 2017 13:12:21 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dg9jf-0008I2-7y for xen-devel@lists.xenproject.org; Fri, 11 Aug 2017 13:12:19 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 58/CC-03406-23DAD895; Fri, 11 Aug 2017 13:12:18 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrEIsWRWlGSWpSXmKPExsXS6fjDS9dwbW+ kwfMHNhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aX9resBdeFKvavTW9gXMLTxcjJISSQJ/Hr +WJmEJtXwE5iXtt0VhBbQsBQ4vTCmywgNouAqsTEhl1sIDabgLpE27PtQDUcHCICBhLnjiaBm MwC+hLb1oFVCwv4SUzZep0NYrqdxK0VN5lASngFBCX+7hAGCTMLaEk8/HWLBcLWlli28DUzxB RpieX/OCYw8s5CaJiFpGEWkoZZCA0LGFlWMWoUpxaVpRbpGhrpJRVlpmeU5CZm5ugaGpjp5aY WFyemp+YkJhXrJefnbmIEhhcDEOxgvLwx4BCjJAeTkihvgk9vpBBfUn5KZUZicUZ8UWlOavEh RhkODiUJ3tTVQDnBotT01Iq0zBxgoMOkJTh4lER4N4OkeYsLEnOLM9MhUqcYdTleTfj/jUmIJ S8/L1VKnHc6SJEASFFGaR7cCFjUXWKUlRLmZQQ6SoinILUoN7MEVf4VozgHo5Iw7xeQKTyZeS Vwm14BHcEEdESfD9gRJYkIKakGxs0MWi0+LZtFxcQW3S7dUZijozBlkX/ueS1BHdmb6Uu5vtX 8esvSasVotOaasKHYGdPdKx80n+z6tcM+/MP66c8tdfco/MviOfV+HUfjpJivEsqnlgTueyXV 4zZN9VPVztd9ygb7zhzcvGfVtWdq567w53G3fKrbb+e1Zeu8y7dFdn2sjetUqVBiKc5INNRiL ipOBAChUSIVtQIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1502457136!77355343!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46747 invoked from network); 11 Aug 2017 13:12:17 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-15.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Aug 2017 13:12:17 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 11 Aug 2017 07:12:15 -0600 Message-Id: <598DC94F020000780016EDE0@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.2 Date: Fri, 11 Aug 2017 07:12:15 -0600 From: "Jan Beulich" To: "xen-devel" References: <598DC94F020000780016EDE0@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Cc: Andrew Cooper Subject: [Xen-devel] [PATCH v2] x86: check for allocation errors in modify_xen_mappings() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reported-by: Julien Grall Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- v2: Comment the pl2e related ASSERT(). --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5903,7 +5903,7 @@ int modify_xen_mappings(unsigned long s, { l3_pgentry_t *pl3e = virt_to_xen_l3e(v); - if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) + if ( !pl3e || !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { /* Confirm the caller isn't trying to create new mappings. */ ASSERT(!(nf & _PAGE_PRESENT)); @@ -5931,6 +5931,8 @@ int modify_xen_mappings(unsigned long s, /* PAGE1GB: shatter the superpage and fall through. */ pl2e = alloc_xen_pagetable(); + if ( !pl2e ) + return -ENOMEM; for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(pl2e + i, l2e_from_pfn(l3e_get_pfn(*pl3e) + @@ -5951,7 +5953,11 @@ int modify_xen_mappings(unsigned long s, free_xen_pagetable(pl2e); } - pl2e = virt_to_xen_l2e(v); + /* + * The L3 entry has been verified to be present, and we've dealt with + * 1G pages as well, so the L2 table cannot require allocation. + */ + pl2e = l3e_to_l2e(*pl3e) + l2_table_offset(v); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { @@ -5980,6 +5986,8 @@ int modify_xen_mappings(unsigned long s, { /* PSE: shatter the superpage and try again. */ pl1e = alloc_xen_pagetable(); + if ( !pl1e ) + return -ENOMEM; for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&pl1e[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, @@ -6003,7 +6011,11 @@ int modify_xen_mappings(unsigned long s, { l1_pgentry_t nl1e; - /* Ordinary 4kB mapping. */ + /* + * Ordinary 4kB mapping: The L2 entry has been verified to be + * present, and we've dealt with 2M pages as well, so the L1 table + * cannot require allocation. + */ pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(v); /* Confirm the caller isn't trying to create new mappings. */