From patchwork Tue Jan 23 14:53:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13527721 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 C421BC48260 for ; Tue, 23 Jan 2024 16:01:09 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=812OOAinciTrjIgqjf6dd38hFsLexU31AelH4EIgYOg=; b=RsR9teLNhATR7FjWul2knNSV7u vKYEqgEj0OP3seyZ7K3B4ENOxErvU0nDuyFBmXG0NjsOwjtS7zARnbRYoK9stTW/XvpFidiqbteIF K4tyxRv5dR7HeaASMhzYIhL8xrnKtSORjZ1jEHGBjl6U5qk6KnmzxYtxD1MyE4Mgk7gJrbclSxjW5 OqGHiPYwb1trSxeALcegCcQHaXbtdLl/h45rgFpoBQVeTRNPtJksXPomlZapx+3d3g/Jzx0Ex/kXn sQTwHwDm/QtBrnAa4KVtoQ3Dkhnl4cEwldIIydhwClZ6+4Zw9b/X/KGG8J98vXnhpUAhs2w/+g3wF t9LEKXlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSJCU-00HAsz-00; Tue, 23 Jan 2024 16:00:34 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSIB7-00GtuP-1Q for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 14:55:11 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc221fad8c7so6312672276.3 for ; Tue, 23 Jan 2024 06:55:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706021704; x=1706626504; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=g+IjSAC2BSuOeuAquyaNlWu8DV5TXu9d/4vrOJzH/bQ=; b=c8i2xOFfktrwejX6nSIBkqGqUeTRnkCbWSpu749+g5vFsQ/OYeK3KIqvyhIkNvnvMc YVKTu50WveOf8L6Sx8fe4IHxwNtCl3s3qUMFAhscfQVMgMX6UiIGyWBRFoeGNqDkb82S R/gnK4LWsESYHdmjovQAcwnXjQielRueNU6bQwOCBSCJ2FK/erTsLSS0vIWMY735DnOw podMzERNjxPkoznrLRnMIIQjmg3o8cYhRBG/ur4YwHu2d/AizHIyzn8sC9pW1kzFkC4m Uxa7eIdxaicb+LWsQWpZwrzqsQ9NwvTqkn9n8VFqWugq9USxjYj17rerIfmQkcPa3ecq gwGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706021704; x=1706626504; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g+IjSAC2BSuOeuAquyaNlWu8DV5TXu9d/4vrOJzH/bQ=; b=LabPsWAKxmJjVyVmImlvoxJVJDX23TDrXiXo99PSZx96tZQwC/jrkME1n3OOIBOtBv 82l3xh45qtzlZ+ITZxxqJNUErK6fFXIk/WDTJh90gKb8oSSYJxqyzZYTojoLMgId5hFP h0e3DauQvVa+fLJJ2KCoAJijGJSGQ01Zk2DxFpLJZ/MLSdc9l33Du4dTQvVPzCh9f2D5 7gtiod9ve6R6pi+iWUXW/MqaiLMP2Wy+a54MGYA07pJzdRvSx3W69ce4qblzfB/D0Uam Np5axiLV37IPB+tePU+GecfMUUQbFN/FJxUnJvvQOQc1TnolWebFUxwam1YrqvKONa4b Wljw== X-Gm-Message-State: AOJu0YxntJMaX4tG3nDH2q/uRfwKc+TYQNigjHf6K8Ck6zOfscSe//jS CGuS2SjvSPUbZvzAorgnB2cseallC8WZ9OOZxwtK+mVBKX1yLn+A7n2wsF4Y4q2dtG4198BzB9n 0ZlVcDoR4PRcgsbhQMKquVpH0SrCVhj6lbjaIqvkRnODwl1v3gOFJFD5Ru2dONQjXRt4KbYgGug L2lubLtlOwrUAMC9K3dO5xfFoSK+EPZB4SBGhbKMjP X-Google-Smtp-Source: AGHT+IFuWrHvZQ/qn4ttHLipfvTc4z2YBFHqgJmC+GNDB2rDiNQF+0TOD0ENAitWVe4l5JbJh28Qb0Os X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:68e:b0:dc2:354a:f191 with SMTP id i14-20020a056902068e00b00dc2354af191mr2712280ybt.10.1706021704112; Tue, 23 Jan 2024 06:55:04 -0800 (PST) Date: Tue, 23 Jan 2024 15:53:17 +0100 In-Reply-To: <20240123145258.1462979-52-ardb+git@google.com> Mime-Version: 1.0 References: <20240123145258.1462979-52-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3267; i=ardb@kernel.org; h=from:subject; bh=5WW9MiuhQ59pNWgySa0oqX7tr/bTl6pkykpfUXS9Mz8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXX9pXtarLMfSX61+7OV23iB95EtXW21nra2vzZ1G/jKt e9YekCoo5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEwkypbhf4nSZO/s+veu4V3z Wz7nej2oqNH5xqd0f825Pd0vFv8SzmBkeK7M0/FtR1GO8qv1CdOmv7zOYiC0TIelWd219kFQZ2M ZGwA= X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123145258.1462979-70-ardb+git@google.com> Subject: [PATCH v7 18/50] arm64: kaslr: Use feature override instead of parsing the cmdline again From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_065505_501503_5E810E17 X-CRM114-Status: GOOD ( 15.70 ) 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: Ard Biesheuvel The early kaslr code open codes the detection of 'nokaslr' on the kernel command line, and this is no longer necessary now that the feature detection code, which also looks for the same string, executes before this code. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpufeature.h | 5 ++ arch/arm64/kernel/kaslr.c | 4 +- arch/arm64/kernel/pi/kaslr_early.c | 53 +------------------- 3 files changed, 7 insertions(+), 55 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index acd8f4949583..e309255b7f04 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -954,6 +954,11 @@ static inline bool arm64_test_sw_feature_override(int feat) &arm64_sw_feature_override); } +static inline bool kaslr_disabled_cmdline(void) +{ + return arm64_test_sw_feature_override(ARM64_SW_FEATURE_OVERRIDE_NOKASLR); +} + u32 get_kvm_ipa_limit(void); void dump_cpu_features(void); diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index 12c7f3c8ba76..1da3e25f9d9e 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -16,9 +16,7 @@ bool __ro_after_init __kaslr_is_enabled = false; void __init kaslr_init(void) { - if (cpuid_feature_extract_unsigned_field(arm64_sw_feature_override.val & - arm64_sw_feature_override.mask, - ARM64_SW_FEATURE_OVERRIDE_NOKASLR)) { + if (kaslr_disabled_cmdline()) { pr_info("KASLR disabled on command line\n"); return; } diff --git a/arch/arm64/kernel/pi/kaslr_early.c b/arch/arm64/kernel/pi/kaslr_early.c index 167081b30a15..f2305e276ec3 100644 --- a/arch/arm64/kernel/pi/kaslr_early.c +++ b/arch/arm64/kernel/pi/kaslr_early.c @@ -16,57 +16,6 @@ #include #include -/* taken from lib/string.c */ -static char *__init __strstr(const char *s1, const char *s2) -{ - size_t l1, l2; - - l2 = strlen(s2); - if (!l2) - return (char *)s1; - l1 = strlen(s1); - while (l1 >= l2) { - l1--; - if (!memcmp(s1, s2, l2)) - return (char *)s1; - s1++; - } - return NULL; -} -static bool __init cmdline_contains_nokaslr(const u8 *cmdline) -{ - const u8 *str; - - str = __strstr(cmdline, "nokaslr"); - return str == cmdline || (str > cmdline && *(str - 1) == ' '); -} - -static bool __init is_kaslr_disabled_cmdline(void *fdt) -{ - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { - int node; - const u8 *prop; - - node = fdt_path_offset(fdt, "/chosen"); - if (node < 0) - goto out; - - prop = fdt_getprop(fdt, node, "bootargs", NULL); - if (!prop) - goto out; - - if (cmdline_contains_nokaslr(prop)) - return true; - - if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) - goto out; - - return false; - } -out: - return cmdline_contains_nokaslr(CONFIG_CMDLINE); -} - static u64 __init get_kaslr_seed(void *fdt) { static char const chosen_str[] __initconst = "chosen"; @@ -92,7 +41,7 @@ asmlinkage u64 __init kaslr_early_init(void *fdt) { u64 seed, range; - if (is_kaslr_disabled_cmdline(fdt)) + if (kaslr_disabled_cmdline()) return 0; seed = get_kaslr_seed(fdt);