From patchwork Fri Nov 11 17:11:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040643 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 24F60C433FE for ; Fri, 11 Nov 2022 17:29:56 +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=AoiUZ5R1nyfspTPoGzxXkJ1KUcE6CzOiSxL8a/QIWdo=; b=iDynUc6lX2oQpB xTDzXMlBDjBbhXfsM7KKAQzdTbBYZYQ0ZJSoOq0PmbeDnSCgdAtSUbZTfzxeRR3t2V1kEO60uh2DO fLszctco4wtALXs8Do07w8kSb+5/mKbyZWNeIfhP44Vi1RmtPpTBgCzzPHJHLV/n6oRtzqomGUGTj 40x4EyzNeG2VS2ZZCIRCAphuOqoHL0fVIwG1vZ7yA0XgVcgsLRAM/cb0bINpV/vQhEQ0Tk8YpPtF/ IAnWoVro9lFcd1XkKy/mlhnuI/g/4mGcRvyDjBB9EmmRtNAoZjGey0v98rj6xHQnd4V4bKO6yLixN QetOw8/Y7u4rbWZpu5cA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXpe-00HGCE-6A; Fri, 11 Nov 2022 17:28:47 +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 1otXaa-00H7xc-CU for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:13:15 +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 D79C66206E; Fri, 11 Nov 2022 17:13:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A211C433C1; Fri, 11 Nov 2022 17:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186791; bh=UwSljH0yp9SP2lFi4DpK22SZSHyqwcwbbyDeK8R76ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GSNhnEquh52jFrYFjwCphP6Xq6aGfTY/C6FPvcM5XtX6j74PRF6MkF89xWeKK0waf c6Emzqye1AsgZbaJFmrwGxl4lCaT9fmkcqgYwnbn6R9A93jdWutHS9nGZZ9euLhgwH YRXMMMCvb7plfjhq0NQJ4FtXLdTy89ImN+qcwT90jN6yrfJY3+h/y3TGd+qoMD1kSi hooPR+is3ipG2MM0khqVj3dl31xKxHwi1BuZLW0nO9h/YvOSzdMKWhYyynI6TotU+i BntWwpeG33G7uii1KlDDPYaurq5b9Ne9kKKfJHfw+8eA8vZhIRBX/HOtXtRD1BeVsz mFxPterRa9ZRg== 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 23/33] arm64: kaslr: Use feature override instead of parsing the cmdline again Date: Fri, 11 Nov 2022 18:11:51 +0100 Message-Id: <20221111171201.2088501-24-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=2146; i=ardb@kernel.org; h=from:subject; bh=UwSljH0yp9SP2lFi4DpK22SZSHyqwcwbbyDeK8R76ak=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboJPgthlMhrmuyg2e+OWD/9rgP5uAAAl42jx7mLo RDeCXROJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CTwAKCRDDTyI5ktmPJLayC/ 48FIP4j2hq90coaOxh9HIr+6tGzrCfwWrRph6Og1vCHBz8595jd0UhiPoK9NcBJ6JWuUjKJLUgdaHK uKs3MKJ50UHMiQHo/hN6NteUkwwmLO+44Csxjs5pmwQRlq/Cmi4FJi/qhKmQHba4QXF6tXZc9oCYC2 w4B7H4GxPytO/zyUnxHUa6YAMahunGB33cR54E4TOEG/4Z3h8HOEZb+jfA8coUTJdhphcpwD2+97y1 zzRAw6C9nZGiQfkJtjtR9D7Gxg58MIuhbqadgFvrXa21NCjmG3sl5jKSwmvQui1SZYTmsjvLObCKnR RVYLNZZmaaOYMopGy8gXcr23yjc6KZ7mD0L1cgyhC6fIjqDO864aC51cR9vosbGAiAoH20P448SyKX ZavoLiqh2VPDcCZ6Q7iB01TbEkZujw1NjpXwKpVxoFDEZpGVmcPJ3wVCoCPaCFi+szxMmG0uDNZRGf wcfoAm29tay7W6rBC3u8081KMooFLUK3kYXnTNlnZh1Dg= 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_091312_590008_A9852E81 X-CRM114-Status: GOOD ( 14.83 ) 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 The early kaslr code open codes the detection of 'nokaslr' on the kernel command line, which 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/kernel/pi/kaslr_early.c | 54 +------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/arch/arm64/kernel/pi/kaslr_early.c b/arch/arm64/kernel/pi/kaslr_early.c index 86ae0273c95016c6..934e95fbd4278d0b 100644 --- a/arch/arm64/kernel/pi/kaslr_early.c +++ b/arch/arm64/kernel/pi/kaslr_early.c @@ -15,57 +15,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"; @@ -91,7 +40,8 @@ asmlinkage u64 __init kaslr_early_init(void *fdt) { u64 seed; - if (is_kaslr_disabled_cmdline(fdt)) + if (cpuid_feature_extract_unsigned_field(arm64_sw_feature_override.val, + ARM64_SW_FEATURE_OVERRIDE_NOKASLR)) return 0; seed = get_kaslr_seed(fdt);