From patchwork Wed Oct 16 10:53:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 176450 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp6995879ocf; Wed, 16 Oct 2019 03:54:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxUqQXO6sA/rO3ZmEcytx+frfR//+c7uCf7m+tFqBFqU5ez0h+L+5Uxpa/aD5zhNQ06uK8 X-Received: by 2002:a5e:cb0a:: with SMTP id p10mr9169200iom.148.1571223273999; Wed, 16 Oct 2019 03:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571223273; cv=none; d=google.com; s=arc-20160816; b=KsrgImhWgKzRdLMHJKprCudz3TlqLZYizhcc6mA3eGPJ7JPgi5zdHGZq8RVLyJ5Z2G eIZF3+vd94BHWZaVWPhTZWgSWCSSfLXP7B0OgNZkINz7xMy7kezzq0mFaE7Jk4cpTsZK Y6OYgEqgXyX6ig27qfIx4J9a/72qo5eC8ISqHMwffDcXr+TBgVt4D1zSuM+e1sWwZiu5 CptjXY2sYzSkCWFkYiwP1UnadwN+pNs6f4QP+jzAIwFLrN5G24yZG6w1rHgT038tMg7B S3Eoo7ZNw/c/EkWBvKCQumPNN78t7w6+aGiu2zk1FYHug8q9UfGSwXi/JhlkeLmGpUDN opgw== 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:message-id:date:to:from; bh=zl/DVaZwQFPDniY9P51KOFHrVz1Z/m6I/K0yQDXB754=; b=tew3OVcVcCMFyp7roK6Y+ES0LlmzoZGqM9haWneJFvhqLCA0IJeepBGb7TnHsYPpo0 AFuHZUZFdpXytqx7bUzyb0lxFlluUUqOid61J0ZKtXNIn341Au3D47WLJDEW5z2OYjbs MxZ2A1L64kOrt81z/XvRCqrzW652CF20v1RIHPUc4YCVA6BreeFNEpWjanrh8uAUjtZv rRtdEea04xkWc5HqLXQGCKuR/Lmx9F9hkkSEkIOewbbl1sDnOBK4RyGUSn/qaIUhDg7g avlEKV04yPogcw2MHhUGKQePRyw0CZddOCxV2h5yZOKFtcjy7waSNp6sN6pwxi4lp1ex wxtg== 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 191si37421806jad.65.2019.10.16.03.54.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Oct 2019 03:54:33 -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 1iKgvX-0002lf-9G; Wed, 16 Oct 2019 10:53:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iKgvW-0002lW-2J for xen-devel@lists.xenproject.org; Wed, 16 Oct 2019 10:53:10 +0000 X-Inumbo-ID: 241df2a6-f003-11e9-8aca-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 241df2a6-f003-11e9-8aca-bc764e2007e4; Wed, 16 Oct 2019 10:53:09 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 04BEA28; Wed, 16 Oct 2019 03:53:09 -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 259B63F6C4; Wed, 16 Oct 2019 03:53:07 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 16 Oct 2019 11:53:03 +0100 Message-Id: <20191016105303.21948-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH for-4.13 v2] xen/arm: Don't use _end in is_xen_fixed_mfn() 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: Juergen Gross , Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" virt_to_maddr() is using the hardware page-table walk instructions to translate a virtual address to physical address. The function should only be called on virtual address mapped. _end points past the end of Xen binary and may not be mapped when the binary size is page-aligned. This means virt_to_maddr() will not be able to do the translation and therefore crash Xen. Note there is also an off-by-one issue in this code, but the panic will trump that. Both issues can be fixed by using _end - 1 in the check. Signed-off-by: Julien Grall Release-acked-by: Juergen Gross Reviewed-by: Stefano Stabellini --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu x86 seems to be affected by the off-by-one issue. Jan, Andrew? This could be reached by a domain via XEN_SYSCTL_page_offline_op. However, the operation is not security supported (see XSA-77). So we are fine here. Changes in v2: - Cast _end to vaddr_t to prevent UB. - Add Juergen's released-acked-by --- xen/include/asm-arm/mm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 262d92f18d..333efd3a60 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -153,7 +153,7 @@ extern unsigned long xenheap_base_pdx; #define is_xen_fixed_mfn(mfn) \ ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) && \ - (mfn_to_maddr(mfn) <= virt_to_maddr(&_end))) + (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1))) #define page_get_owner(_p) (_p)->v.inuse.domain #define page_set_owner(_p,_d) ((_p)->v.inuse.domain = (_d))