From patchwork Fri Nov 11 17:11:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040633 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 E930DC4332F for ; Fri, 11 Nov 2022 17:20:47 +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=Lltd5r4zumHiK60aBx+8+1UDU6YQGc5H7o7NxhC0f6w=; b=apE/agDNa8qpil MXExBDP0EOvie6ZfSSaKyNS2dcNXOv4KNLTOvE91pQS8UyfUxjwJA49pNejhl0ecnNJAHWCGOjGE2 kuDmmVgjajc0d7DZ6A+eIwXo0Sk8nUxEU/ksF9m5P+UwVFPlood7O8OYNdboYx0FaxsfdvDAsqihw oB8HE9Kkz2EQBUoCoMEZLz+EmGhGRK79KzbKu/rnaal5DJfqIa255uBUPfIHAMErui76I2t9x4lUK Jdhy1lZk+vE0L+C/jovaTb8csR9I7jTCrUuhYivojUsmYeDMiHnOIrHJrqZp1iCC+34Q1QtcDI0Ut yVLonRJGF3UHGbKTQJXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXgj-00HBZt-JO; Fri, 11 Nov 2022 17:19:33 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXaF-00H7kU-0a for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:12:52 +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 ams.source.kernel.org (Postfix) with ESMTPS id A7AC3B8266E; Fri, 11 Nov 2022 17:12:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77E4EC433C1; Fri, 11 Nov 2022 17:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186768; bh=tv21gCt/gFkvZkigToTDT5JLM8WfuFUkfUZ5nWhYLXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dinqIf/nG+37+pF4CUHSIWL6u/7GOIdwZWZzOb3D0vKGYyHYmIPS1JkJXp1+f4KG6 gLmCS+m//gpHBIfyVeRsZZ0WM6AoLaGD1jS3/O13ywJYdxBMd7sX/GAh6TCB3e71XN 2fBU/+DpteOpfFJo+O4Qp93p0UKoh5s7gUpkH4GdPXIuoHpJCJlcieYGpgCj8WJfWQ JuYoh0PHpEkQ5qNtC1CG6ezGO5/5cklG76o3tYXBZi/X3Iq088HVrdeQ2jnrUPbcU6 ZwMDUE6amqWTmC8yEcuAQWfVsN8Doo7FXoTmV10W/9ojX9NeHorIUBOXyM5x9OV9+Q HOQfiZRFkKOEg== 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 13/33] arm64: idreg-override: Avoid parameq() and parameqn() Date: Fri, 11 Nov 2022 18:11:41 +0100 Message-Id: <20221111171201.2088501-14-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=2747; i=ardb@kernel.org; h=from:subject; bh=tv21gCt/gFkvZkigToTDT5JLM8WfuFUkfUZ5nWhYLXo=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjboI+dOahBhNM9UQBAnuMW8F7dmZyoCFjb8ojNQcX t/QIO6iJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CPgAKCRDDTyI5ktmPJOKSC/ 40vxbVwj7gUovb5P/U7O/wVn9PDXoXpYacRxJTpYrh4htF0iRjcTFvr/plEMGnrPpKy7ws581TpM9r bZa5dDXNyB0cJSDgpVLC8gO+i3BB9LKBkXZGnWaJPCXBcHhamMqdh4OM4Qvey1Guz8IfB5Zr9Q3c1F yn3zTBvJ8eeQ03nPE+EYrd24EGZai88zWVdfQsV7/BWWBfpbxglT0C24v2yaBuZ30xduftabvczZWz X49INSfpfkhzAVhrxK11L0oSpaNZKtBVf1OGq8UG/3kSsuLilOITbbXYjBFa7CSCDt/KPZmiRRQvO9 /F6umJ1jnQYWaCHPSw4TROzre2RDLkzHjBcQI6TbgYQ6GdDjlWsZBH8M+iDN7JlZH8Yzzkudo45jdt zkEntHU7vbupuwznuqfkoIi5+5IR116U+zjnt/VQXSA5fFBIpAg0SLX5qutpAtcJ0R741wVtdwMwoG 5Ks9YstPJrh109fHqEUejlukm5t7RD0Kl0/YZrZYkdLTk= 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_091251_401100_F458EC9B X-CRM114-Status: GOOD ( 18.87 ) 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 only way parameq() and parameqn() deviate from the ordinary string and memory routines is that they ignore the difference between dashes and underscores. Since we copy each command line argument into a buffer before passing it to parameq() and parameqn() numerous times, let's just convert all dashes to underscores just once, and update the alias array accordingly. This also helps reduce the dependency on kernel APIs that are no longer available once we move this code into the early mini C runtime. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/idreg-override.c | 26 ++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index 01eed0eaba7c1cdd..b3288e827a6bbec3 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -153,8 +153,8 @@ static const struct { char alias[FTR_ALIAS_NAME_LEN]; char feature[FTR_ALIAS_OPTION_LEN]; } aliases[] __initconst = { - { "kvm-arm.mode=nvhe", "id_aa64mmfr1.vh=0" }, - { "kvm-arm.mode=protected", "id_aa64mmfr1.vh=0" }, + { "kvm_arm.mode=nvhe", "id_aa64mmfr1.vh=0" }, + { "kvm_arm.mode=protected", "id_aa64mmfr1.vh=0" }, { "arm64.nosve", "id_aa64pfr0.sve=0 id_aa64pfr1.sme=0" }, { "arm64.nosme", "id_aa64pfr1.sme=0" }, { "arm64.nobti", "id_aa64pfr1.bt=0" }, @@ -175,7 +175,7 @@ static int __init find_field(const char *cmdline, len = snprintf(opt, ARRAY_SIZE(opt), "%s.%s=", reg->name, reg->fields[f].name); - if (!parameqn(cmdline, opt, len)) + if (memcmp(cmdline, opt, len)) return -1; return kstrtou64(cmdline + len, 0, v); @@ -235,23 +235,29 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) cmdline = skip_spaces(cmdline); - for (len = 0; cmdline[len] && !isspace(cmdline[len]); len++); + /* terminate on "--" appearing on the command line by itself */ + if (cmdline[0] == '-' && cmdline[1] == '-' && isspace(cmdline[2])) + return; + + for (len = 0; cmdline[len] && !isspace(cmdline[len]); len++) { + if (len >= sizeof(buf) - 1) + break; + if (cmdline[len] == '-') + buf[len] = '_'; + else + buf[len] = cmdline[len]; + } if (!len) return; - len = min(len, ARRAY_SIZE(buf) - 1); - strncpy(buf, cmdline, len); buf[len] = 0; - if (strcmp(buf, "--") == 0) - return; - cmdline += len; match_options(buf); for (i = 0; parse_aliases && i < ARRAY_SIZE(aliases); i++) - if (parameq(buf, aliases[i].alias)) + if (!memcmp(buf, aliases[i].alias, len + 1)) __parse_cmdline(aliases[i].feature, false); } while (1); }