From patchwork Fri Nov 11 17:11:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B1F4C433FE for ; Fri, 11 Nov 2022 17:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6Nl3S5TDd0Ulld8pkucbVvgbManzKsfrobxaoltUkuE=; b=F5DBPo869D8fy4 7pvuIV1gV80mV2RvqFnHXv6YqrVzYD8VDK7cLeMceEC1COVoBkLSb/5QmJj6ATgzOFQ111Mdd5P7l ZVp3AzXWIzfCfvIPsDX/erVu4lOz9+RyDEf0u1xhQVbRSHXYgMpu12ZK/G5Y+d625MAivRdMTQYl4 gXsJEH3DnjDq3FpL0RI6Z/us8rqHK+aPDobg1fWDFdcQSnn8nNnuryMZlNRfnGRxwcLzCkdZ25kUk BtPcAuY1yqXnpGnlKMhSN17tPaRWV7rcmcJ+T1nEy/GXw0NAnToS0UVYdyON3yG3kvC8r0nfdtmbU Aq4Rnchz4o6heMob0P0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXds-00H9oI-HY; Fri, 11 Nov 2022 17:16:36 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXa4-00H7dX-6m for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:12:42 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B5112618C9; Fri, 11 Nov 2022 17:12:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 493DBC43143; Fri, 11 Nov 2022 17:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186759; bh=2eyf0AIH+GQWjsvMONvdga33hzdAa7BsuLR5uQfzhHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ff92znWUdwjGJA67aLvuc0sp98Yfd78oUldRjy4Pl3AwuvFvBDtA/rpEz0shn7tfM L1pMyqabHNIYB4fDhgEZkVDlO2Ip/YEWFpivJYGkJGOULaB1oYFl+QLsMmJzNpL8sQ dwZEvZVmyoanNd5S7ROT37u8q/Fa9u5z61/9sRszGUtnNy9/3Kf1ABPXW/dWISXl8r rZah/up98ZJ2RqdkMVCtMXp6X05ElmRdjGyqAzrtNpicnsnaL24JVDaeMlmi5GA73t BQ93HjPoITtse9NaKMfpaSAy10+CzlcQQy+61tZJqHAcNP69sbPB98LN2LFo0hNBQG 1QnoMMx01vdCA== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual Subject: [PATCH v7 09/33] arm64: Turn kaslr_feature_override into a generic SW feature override Date: Fri, 11 Nov 2022 18:11:37 +0100 Message-Id: <20221111171201.2088501-10-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221111171201.2088501-1-ardb@kernel.org> References: <20221111171201.2088501-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4011; i=ardb@kernel.org; h=from:subject; bh=WNLURScLXYyJdWXNxGhOyTkTvnJfPC+J8gCSCf8ggFc=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboI36cmSGybTSxkDQY2jwqNasRcjQjmdyjSDDNUi NiFbkyiJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CNwAKCRDDTyI5ktmPJMlkC/ sH6vempL5KyeXvJnxOrImpVVL27N0vvrrWyGdTxUqAafzoBL9G3+83G0D999BkwvV3Ewq8+gNMauzQ L/AyVzqxIkhJPcJnZJ4jywmWFS0XbxB1iditiYB/6zv9zScU9VHvG5AQDZUTUjeMJZ82GKG0kfRgnN 7KxzEUs9/J/P+swPqVkWXamvuoR4C7RvRmH2HxlE0Xlmlofmf/nkd9Xlhjb1eddjJ15u+0HHEDLb4M u40T8koOLklhmHROanaUl/kR0kAEUj+UhCaq3IwRNmbhMzAWMHDuiZC7VtKf22DIsedo1Q9GJZEiWv zIdDXSrSd+a4HlX8HfRFcxpyJWjQh7hSdEA6CHZMcQHdWUZGJqzmAGoTWUlUwgIcMoUwRGN/OsbYvj OJ4SixswGnQ1UHjWJ1mZchMCn/nnzNLls5Cm2+47sUoH2iqI1B5lu3+0Fa10hRCB52Ol1Pq7hjaiqt mPd7WMeAgcBsPJITeChYkBBLi4BLErLOr4Z1WwtFdn5fk= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221111_091240_390714_14367342 X-CRM114-Status: GOOD ( 17.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Marc Zyngier Disabling KASLR from the command line is implemented as a feature override. Repaint it slightly so that it can further be used as more generic infrastructure for SW override purposes. Signed-off-by: Marc Zyngier Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpufeature.h | 4 ++++ arch/arm64/kernel/cpufeature.c | 2 ++ arch/arm64/kernel/idreg-override.c | 16 ++++++---------- arch/arm64/kernel/kaslr.c | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index f73f11b5504254be..f44a7860636fd411 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -15,6 +15,8 @@ #define MAX_CPU_FEATURES 128 #define cpu_feature(x) KERNEL_HWCAP_ ## x +#define ARM64_SW_FEATURE_OVERRIDE_NOKASLR 0 + #ifndef __ASSEMBLY__ #include @@ -914,6 +916,8 @@ extern struct arm64_ftr_override id_aa64smfr0_override; extern struct arm64_ftr_override id_aa64isar1_override; extern struct arm64_ftr_override id_aa64isar2_override; +extern struct arm64_ftr_override arm64_sw_feature_override; + u32 get_kvm_ipa_limit(void); void dump_cpu_features(void); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index fdbae2320b466d98..ebd8cabffb105e15 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -644,6 +644,8 @@ struct arm64_ftr_override __ro_after_init id_aa64smfr0_override; struct arm64_ftr_override __ro_after_init id_aa64isar1_override; struct arm64_ftr_override __ro_after_init id_aa64isar2_override; +struct arm64_ftr_override arm64_sw_feature_override; + static const struct __ftr_reg_entry { u32 sys_id; struct arm64_ftr_reg *reg; diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index 95133765ed29a0e4..4e8ef5e05db7a424 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -137,15 +137,11 @@ static const struct ftr_set_desc smfr0 __initconst = { }, }; -extern struct arm64_ftr_override kaslr_feature_override; - -static const struct ftr_set_desc kaslr __initconst = { - .name = "kaslr", -#ifdef CONFIG_RANDOMIZE_BASE - .override = &kaslr_feature_override, -#endif +static const struct ftr_set_desc sw_features __initconst = { + .name = "arm64_sw", + .override = &arm64_sw_feature_override, .fields = { - FIELD("disabled", 0, NULL), + FIELD("nokaslr", ARM64_SW_FEATURE_OVERRIDE_NOKASLR, NULL), {} }, }; @@ -157,7 +153,7 @@ static const struct ftr_set_desc * const regs[] __initconst = { &isar1, &isar2, &smfr0, - &kaslr, + &sw_features, }; static const struct { @@ -174,7 +170,7 @@ static const struct { "id_aa64isar1.api=0 id_aa64isar1.apa=0 " "id_aa64isar2.gpa3=0 id_aa64isar2.apa3=0" }, { "arm64.nomte", "id_aa64pfr1.mte=0" }, - { "nokaslr", "kaslr.disabled=1" }, + { "nokaslr", "arm64_sw.nokaslr=1" }, }; static int __init find_field(const char *cmdline, diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index e7477f21a4c9d062..5d4ce7f5f157bb3f 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -23,8 +23,6 @@ u64 __ro_after_init module_alloc_base; u16 __initdata memstart_offset_seed; -struct arm64_ftr_override kaslr_feature_override __initdata; - static int __init kaslr_init(void) { u64 module_range; @@ -36,7 +34,9 @@ static int __init kaslr_init(void) */ module_alloc_base = (u64)_etext - MODULES_VSIZE; - if (kaslr_feature_override.val & kaslr_feature_override.mask & 0xf) { + if (cpuid_feature_extract_unsigned_field(arm64_sw_feature_override.val & + arm64_sw_feature_override.mask, + ARM64_SW_FEATURE_OVERRIDE_NOKASLR)) { pr_info("KASLR disabled on command line\n"); return 0; }