Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4434362rwb; Mon, 31 Jul 2023 06:57:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlH6hzwtB4XQpdgsCp2Ch/FGPOr+qZ2VDjSg1w7UHcqKF2AsytcSHMiCXlh6q6WTowTKTiZX X-Received: by 2002:a05:6a20:1450:b0:132:cd2d:16fd with SMTP id a16-20020a056a20145000b00132cd2d16fdmr9605469pzi.38.1690811854958; Mon, 31 Jul 2023 06:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690811854; cv=none; d=google.com; s=arc-20160816; b=Ppxf1cMxjfAdWaKENIi5WmOmCkIzfcyTh88rcllMOqS4pO4ZbXXauk9Lg1OyfHSvMV rgKzoHbKMiQiWxud6jkWjeleEKjzGHytg5SEgomM9Z0bDiMpPeMTuBg7SWBEgsXrPJgV JBplHgKaX2/Xx8FJH3WTr4L3V4fXtYB3Yt6VKtD/EHfX3uvWEuyP6mrdGDhnDCMYB4nE rLDJsSVF/PuCY9xizV4PSSPHQghwODB3yqDP4dQJI/XT+ZK+wYIkQIfn/uq+0X6w8Sd7 1Ip6y9yugA68k+RU6Im7LRZgggkxdlMGKMs4DQ74ImAR2mVJhUW6A8Yev7WR8f/F9gq8 pa5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Dnc2nP1HVaiEDoBVg12zB7TbohL1GVCNMw7SaItQG9I=; fh=EdAFSmIgUzZTC6WCy4Jg1wBZ0/m6m2d/OjiRUJ3BsTI=; b=FRnY9OHV1Bo1Zpflk/nwF0yYm5H6CBkiy3UzhiFp1lIqnJVYZMLYkdCOcj5spo0HG4 3E80drI+nE78c0WNp8n4RNDtrfqx/OZuCe3q4oJiu+JQW0JGoUR0ABz3ss6ewn6Ux7pu TTicN0NTjMMYZKGm/lWBhUnkubklFeSNFqJK0wXF7fgI4PcpXsoRHyg3+i9yPXjo9Z+b ZIWlf2hnFXG3AweFx4s98SOwg6MMg4TSdhs29dzL09tTdGw0gvJe4lw0XWkqFp6GAc7j oVg8eTZDmHzssfA1AYVGvmaWD9J++Wab0eaVnHuLyYvJGrcdu7uYkCtUzxAS2DjqkNLO 75Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fU0j1e3X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a056a0022d500b00680a955d325si4461853pfj.45.2023.07.31.06.57.22; Mon, 31 Jul 2023 06:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fU0j1e3X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232605AbjGaNwr (ORCPT + 99 others); Mon, 31 Jul 2023 09:52:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232067AbjGaNwM (ORCPT ); Mon, 31 Jul 2023 09:52:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C048D19A4; Mon, 31 Jul 2023 06:51:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9FC0961164; Mon, 31 Jul 2023 13:51:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E282C433D9; Mon, 31 Jul 2023 13:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690811506; bh=BgZhQzy1ZDJ87SbUj0QMsK2M0tcAHYl7N7+4HCzYWRs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fU0j1e3XEEFY14TiXG7UZZhtiGdQcVaJOs5YYn0d0HBv9jg++PBGs48EKbfXcM21l 1exa2fzWwz6nswa9PI/q1VsrKV/ioGKoEaCd/wFw46oyOJUtHDM9YcscznSQe1+tmV Yfj/BSODB+YRKETOA9JsiagBphdos9OkeuW+C1ki300H7Mwf1rv3XVT0e5RgzoWJtz QLiQsP1imT8hBwRQQK3J3LXTYOy4ncJHWWogdlfvz1fv9fNGX9pKI3ne5zTbVphfVR BuX9mlgRdBjuQpc+bIVOBRYjRJawSu3BxCF75Ur7aOl7pUy84mCHEyDGUXdad1zdWG 8EpEzINcwQlKA== From: Mark Brown Date: Mon, 31 Jul 2023 14:43:18 +0100 Subject: [PATCH v3 09/36] arm64/mm: Allocate PIE slots for EL0 guarded control stack MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230731-arm64-gcs-v3-9-cddf9f980d98@kernel.org> References: <20230731-arm64-gcs-v3-0-cddf9f980d98@kernel.org> In-Reply-To: <20230731-arm64-gcs-v3-0-cddf9f980d98@kernel.org> To: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=2919; i=broonie@kernel.org; h=from:subject:message-id; bh=BgZhQzy1ZDJ87SbUj0QMsK2M0tcAHYl7N7+4HCzYWRs=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkx7wbr9D6eCginZ3wYzHf56hBuWwZc8mFLlW1vs/8 Z1ZqpFmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZMe8GwAKCRAk1otyXVSH0Hg9B/ 4wMMMHNGtb1FEiUwCCPHCM4Os4PV/T3eljuty2xS5W5ICxaxc76Uh51Yg1vF8LNyZ5GbX6eWv024IZ fPvKbZGSjK/wdcBZASJ5yDb3wMctY0oCPetxvOyGohQyDFm19bO9RLrCRtBQp95FEwQAPCW09YKfcf x7m57z+Ff/Q9vEEsT768+FUHaBidMwawFBpli5YWIA3v0/pQKrfHNZYJZczU3PjIG8qv7cOEUd5Uap +C32Mj1GeQ7KWadnN6L1QSkZ5e0lif5fB2zep4gnKvi4y+3vu0AVtldrsr6qoq9HEE6lN+QPHHRQKV sFJhQkF33qTeiMrVQY/1+8AlF/FBO9 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pages used for guarded control stacks need to be described to the hardware using the Permission Indirection Extension, GCS is not supported without PIE. In order to support copy on write for guarded stacks we allocate two values, one for active GCSs and one for GCS pages marked as read only prior to copy. Since the actual effect is defined using PIE the specific bit pattern used does not matter to the hardware but we choose two values which differ only in PTE_WRITE in order to help share code with non-PIE cases. Signed-off-by: Mark Brown --- arch/arm64/include/asm/pgtable-prot.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index eed814b00a38..b157ae0420ed 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -131,15 +131,23 @@ extern bool arm64_use_ng_mappings; /* 6: PTE_PXN | PTE_WRITE */ /* 7: PAGE_SHARED_EXEC PTE_PXN | PTE_WRITE | PTE_USER */ /* 8: PAGE_KERNEL_ROX PTE_UXN */ -/* 9: PTE_UXN | PTE_USER */ +/* 9: PAGE_GCS_RO PTE_UXN | PTE_USER */ /* a: PAGE_KERNEL_EXEC PTE_UXN | PTE_WRITE */ -/* b: PTE_UXN | PTE_WRITE | PTE_USER */ +/* b: PAGE_GCS PTE_UXN | PTE_WRITE | PTE_USER */ /* c: PAGE_KERNEL_RO PTE_UXN | PTE_PXN */ /* d: PAGE_READONLY PTE_UXN | PTE_PXN | PTE_USER */ /* e: PAGE_KERNEL PTE_UXN | PTE_PXN | PTE_WRITE */ /* f: PAGE_SHARED PTE_UXN | PTE_PXN | PTE_WRITE | PTE_USER */ +#define _PAGE_GCS (_PAGE_DEFAULT | PTE_UXN | PTE_WRITE | PTE_USER) +#define _PAGE_GCS_RO (_PAGE_DEFAULT | PTE_UXN | PTE_USER) + +#define PAGE_GCS __pgprot(_PAGE_GCS) +#define PAGE_GCS_RO __pgprot(_PAGE_GCS_RO) + #define PIE_E0 ( \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_GCS) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_R) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_X_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX) | \ @@ -147,6 +155,8 @@ extern bool arm64_use_ng_mappings; PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW)) #define PIE_E1 ( \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_RW) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_R) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_NONE_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RW) | \ -- 2.30.2