From patchwork Tue May 14 12:21:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164152 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2552219ili; Tue, 14 May 2019 05:23:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyXkTWdaZibwHrPcWC6Zd4ykiuAr666Um/PjlV+dCt4ENK/RsC1z8DblkPlfHN2zwBD1bH X-Received: by 2002:a6b:37c2:: with SMTP id e185mr18345683ioa.143.1557836594996; Tue, 14 May 2019 05:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557836594; cv=none; d=google.com; s=arc-20160816; b=lxXmAzG/2V1LOUwMWNPAc4K5w3nJcfPGHNCXkyomdRG+HAZ5CfQUtgIK9TlrqiY5u/ eKtuY0t39aMcIV1HCdJziqHrE0yXLGeQ+7oTKPxLCoMMkjRXgvS3N7/wEvRbuaMKc4Fs IZCHPSVwuxHSs9/PFQbsD+0U3j+ttOwvjRgxST6YvahlOrajztS9ojf5csNIvzeI/SnA 3kCNSRxNhi4gnxid1NUERBkZpbbRPhlRDeWnM0PZPXe3s1CvYrveTcRJE5iluqxDKqwP /PqtAQYty2hXHrs0P86eguILje/HZD8ukIioiFmGtafHrC9ApuTG+ffHAjUYgXGovRju e2jw== 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=tN5Yqon0TvcY8L5oulE0OwGKguEuAO/Bhro5wpg1RBrnS0FpPEiAQ7/MY8xW8nmP9V mhNpuvTeavO8v2CmdQ8R2SADF9B6643U/xV7GIIlFJ0LmwPnNjdjWHNfUQ39uGlN3haO LBESMLcT5pR/x0Sv9XYS02C0EROXa6I6XO+2Rax3jGWQMNqjIVg3gXvE9SXd/nouMBWc DjMZrNbvNvIfSzBesqWH68NXI313jxkweSHrWYQCHZM6Fsfa+ZKYFRpI/5zMjrP1bhOk TMiEibTMEdJLBGu14WZTmQ4BoKEnUaoQXkQLs3+63pQAMj1hw1VbaqB3NQlF4MbkUz7G DJyQ== 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 h133si1414047ith.107.2019.05.14.05.23.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:23:14 -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 1hQWRp-0000PG-Or; Tue, 14 May 2019 12:22:21 +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 1hQWRo-0000Lt-2L for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:22:20 +0000 X-Inumbo-ID: ea935614-7642-11e9-bb29-ff42585fbcaf Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id ea935614-7642-11e9-bb29-ff42585fbcaf; Tue, 14 May 2019 12:22:18 +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 881C4341; Tue, 14 May 2019 05:22:18 -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 781CD3F71E; Tue, 14 May 2019 05:22:17 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:21:33 +0100 Message-Id: <20190514122136.28215-25-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514122136.28215-1-julien.grall@arm.com> References: <20190514122136.28215-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART2 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 --- 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; }