From patchwork Tue May 14 12:24:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164187 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2555195ili; Tue, 14 May 2019 05:26:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxA9X178SL3IBvABXgoht0ChVDgUH/u98vugXvCE3f+TSZsbFOxNditb9BtFdC/Yudmi31W X-Received: by 2002:a05:660c:1282:: with SMTP id s2mr3253865ita.47.1557836778914; Tue, 14 May 2019 05:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557836778; cv=none; d=google.com; s=arc-20160816; b=XHYgkomWiPCCCtTBKfk9LahVIjDj8TOxXR1DnmgVV7WpiiAIxRB+AiPpjBTNF8gXve RveKjpTqwfZcSrWgDuYFgU3Md2EaWEm3KKcNjqfRo+2elJF6hNlQ/h9Q3xMtcN3a2rNG LTZtWq5+bmyaS3Cmp2s/EGY+j9TtCLDsKi8+iCLHAUpnVtSVmQ0cvnP0uFxn0hbkYnm3 P/z94GaSq3YaNjAj7pUWdDj4ZMNyt+Bgn93Ac0gzLjjkoQkp4XkhH2KQBaf3v1ap0QCj KbgUPvRxpoyk45YjYkARQOldDAL4KVA9HcbDLHgtruXf3+QjTJsDMZn43R8dlK1vq7c2 bOPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=b8pUgsBkjgmcNr3jm0+cfqB5BNuu57xPBzSveDyZutQ=; b=06i/22waSuwl17La+VNuGEaHwFz328imEOd/C98tilVwc71b4fmP8GtaVzunBCWFP2 rF3sukIESNwGkRQRfBbec0r9J/KIO6ro8mil9ojdE0LQiTMit2Gag4su50jnONt0qrCm N9Pxj2bNuv2USHUOLRfC6Leq2j8+1BGZSBgg0lT9w3fO70KBdw4Gb1oKIuoK671OJ+Hi Ffci16vU6BrEC9NzAFUHlo1k2u2Lt0Ryp6i2X9Wh0QRzDZYNdg2Vn3lizVXz6UMBHuMP 08Q54jiZpvpwMuGFN/mvTJJQsB0pBpmVVEkLoctVyY3dmKH/PyvpjLofwMwZhSPue9R0 o5Zw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p130si1361390itp.103.2019.05.14.05.26.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:26:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1hQWUq-0002xK-AV; Tue, 14 May 2019 12:25:28 +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 1hQWUo-0002uU-Uh for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:25:26 +0000 X-Inumbo-ID: 5a3a3ae6-7643-11e9-ac14-47d38e703330 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 5a3a3ae6-7643-11e9-ac14-47d38e703330; Tue, 14 May 2019 12:25:26 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D434F15AB; Tue, 14 May 2019 05:25:25 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C49993F720; Tue, 14 May 2019 05:25:24 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:24:53 +0100 Message-Id: <20190514122456.28559-17-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514122456.28559-1-julien.grall@arm.com> References: <20190514122456.28559-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART2 RESEND v2 16/19] xen/arm: mm: Protect Xen page-table update with a spinlock 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii_Anisov@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The function create_xen_entries() may be called concurrently. For instance, while the vmap allocation is protected by a spinlock, the mapping is not. The implementation create_xen_entries() contains quite a few TOCTOU races such as when allocating the 3rd-level page-tables. Thankfully, they are pretty hard to reach as page-tables are allocated once and never released. Yet it is possible, so we need to protect with a spinlock to avoid corrupting the page-tables. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v2: - Rework the commit message --- xen/arch/arm/mm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 9a5f2e1c3f..7502a14760 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -974,6 +974,8 @@ enum xenmap_operation { RESERVE }; +static DEFINE_SPINLOCK(xen_pt_lock); + static int create_xen_entries(enum xenmap_operation op, unsigned long virt, mfn_t mfn, @@ -985,6 +987,8 @@ static int create_xen_entries(enum xenmap_operation op, lpae_t pte, *entry; lpae_t *third = NULL; + spin_lock(&xen_pt_lock); + for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1)) { entry = &xen_second[second_linear_offset(addr)]; @@ -1059,6 +1063,8 @@ out: */ flush_xen_tlb_range_va(virt, PAGE_SIZE * nr_mfns); + spin_unlock(&xen_pt_lock); + return rc; }