From patchwork Tue Mar 7 14:04:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2462702wrd; Tue, 7 Mar 2023 06:31:46 -0800 (PST) X-Google-Smtp-Source: AK7set9mc2FjWocg5xixhLFDTd+K5CB3por3RcjhZXE7oUMwJm0cqH0Io/aUoe5p8WvHZ6XfH+Rg X-Received: by 2002:aa7:9909:0:b0:5a9:fa49:904c with SMTP id z9-20020aa79909000000b005a9fa49904cmr13502937pff.5.1678199506356; Tue, 07 Mar 2023 06:31:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678199506; cv=none; d=google.com; s=arc-20160816; b=CtZT7rJSX95qkvpdR5soLDOFL9WPPOkBR8TC1aX6/K+aGkQX+eOODp9b9zCgmAVZXD NhQyj0p1iNbslgyUUuFLRbl3LgmNd3MLX38ERQ6rsVXHDV225gzCSCXTrrqytD6OW5cQ QaNuNNZ5BFV4aKkpBzPxwoo2MpPXwL4W3BIgfp82DGWyRb5cNIy69I26sWq1RVmSCkM3 DQq72TWrSFCsc/R633e54rredu24V/RAbZFwi/VlrRUhdHpttE7CG/aikY7DZej/gSH1 ddCPl7fd7o5konsW7eSS8mHYh91jbdXez07x3/pjFY+Mz0FXoPQD+vJunf+s2ZqL+Vzj n0hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fCenb9qST1Ct7yRClwL6S7dHyLl/1g//7vCdDMfgZyg=; b=SHX/XXuBZOac9xCoDZSZG5adY7YqXI4QkzcqcykuEtja4FsQf2ttuZ02WywZJcdJT4 9/u/dBGNO1ROQ9dUc7if+lCdnUXsFdedjG/Y7IkiZxbrdjqXqPtycoUaYuTzC5ct4fbl v5rtSsTHBLzDnPRaTu+XY41vHP3cZZ/L+ItXd0mL4zBm1TN6TKQM6DuZVoUhG2jjh/2L h6RKZWWtStswwm9F4zSGS5N6WPSiFncEGbkHR8NQDw9zn1NyKnmUNMXBPhj4sMXvphgw xuQDVoZVGNCfAcNL2ElbpsMJFAcuefG/CTwO2Ssg86maOZ6us3SOmcVJGejzx8xLqr1c PInA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tasMtYwV; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p7-20020a625b07000000b005afdbef35d3si12638225pfb.56.2023.03.07.06.31.33; Tue, 07 Mar 2023 06:31:46 -0800 (PST) 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=tasMtYwV; 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 S229885AbjCGOIP (ORCPT + 99 others); Tue, 7 Mar 2023 09:08:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbjCGOHl (ORCPT ); Tue, 7 Mar 2023 09:07:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 472088ABF9 for ; Tue, 7 Mar 2023 06:07:09 -0800 (PST) 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 B96B761457 for ; Tue, 7 Mar 2023 14:07:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 338C3C433A1; Tue, 7 Mar 2023 14:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678198027; bh=Hq8nHTyQr1XHq5oR1wC0C3a0J3sTD/A+RXL9gidFldA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tasMtYwVLBsYQ2coKtO/UrLuNh5Xk04axrum5aB+CLGXjp2+1xnnfrDABu+WuSdFR sFKVeRhFY/rtzakdiLI9Vx9zHgeju92OdtjnyyWJK9W0lP041NFlw7x5tY9MRtMEVh P45tZmK/0H1DuVTOHtalkzTXpWOAyXQr67p0hNoeXjdshmmlhni9HA8jS+qNWVeFx1 oC+5r5Km1QyyyXZkSaDgc/I5r+SSCvTKxh86NSSTh0fIFG2wmJ35E+RN8ojn5jrVGu TFPUyrz+CMcFWrf3MUW/nRk1HjPHaLaPT+Wudbn63vTeXHaRsssPUhsFNjZw+4ypJ9 riEyjmcFs3NJA== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: [PATCH v3 12/60] arm64: Turn kaslr_feature_override into a generic SW feature override Date: Tue, 7 Mar 2023 15:04:34 +0100 Message-Id: <20230307140522.2311461-13-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307140522.2311461-1-ardb@kernel.org> References: <20230307140522.2311461-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4014; i=ardb@kernel.org; h=from:subject; bh=GSuvLi6RwTLuJqeqKu2UWNgSFMdiiU3kHbNFtROgd2w=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIYXdRWzH1bdWNns5bhsHSbeKR5p8q2/fmdl97PnBHRcbO ufbPlveUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACYincnIsH/u4TUfvh0MmHMg 3nyO8enfLZccfx5cPmtCV/EqdY1d0/4wMvy52bzHzZV3gcT6dyr/T0/dm5SWXOzFmckQ0XEowf3 1V3YA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759719725453251029?= X-GMAIL-MSGID: =?utf-8?q?1759719725453251029?= 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 [ardb: don't apply the override mask to val] 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 | 5 ++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 6bf013fb110d7923..bc10098901808c00 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 @@ -925,6 +927,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 e9a138b7e3b22cc7..88cec6c14743c4c5 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -657,6 +657,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 d833d78a7f313563..434703e4e55cb785 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -138,15 +138,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), {} }, }; @@ -158,7 +154,7 @@ static const struct ftr_set_desc * const regs[] __initconst = { &isar1, &isar2, &smfr0, - &kaslr, + &sw_features, }; static const struct { @@ -175,7 +171,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..abcd996c747b8c97 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,8 @@ 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_NOKASLR)) { pr_info("KASLR disabled on command line\n"); return 0; }