From patchwork Fri Nov 11 17:11:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13040636 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 9D8EAC4332F for ; Fri, 11 Nov 2022 17:23:54 +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=WRYZTZrEKvPlP5pY2UUd3oWWJ15nXi4fCYjSnAWw3ss=; b=kP5cZEADqogL/k PXVpDi5dSnhdLmv/m2jCyo4h/A8kdfBWgWPH7GFCm/5/Y3s/uAi1xkdvLYj7H/YmSe2Zf/ByMpr7p voFhsyqz+9td6h48O1722Hc8baXj3/xov3UsMua8NJnnfh6fb8bUdebFGxpz3mA9v/mp5egZUReMd PIEtzZpZpeEzrnEIIIwhU1U0aSPpPcjzIuv7yNVvW3Z8ST4bBBCdLwD9pgmk6ME7W4XZOtCaAk4rF 20PbjgzJsf3PjA+GLPLKOgdTLRZEkbp53O5J/ZLdhe46ZSPVGyn1+yNfsXBXHy7/wvZUddYX7YAYi fyEHMDE+uJwE2fKc3oDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otXjs-00HDAm-9w; Fri, 11 Nov 2022 17:22:48 +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 1otXaM-00H7oQ-29 for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 17:12:59 +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 7B92EB8267B; Fri, 11 Nov 2022 17:12:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CA38C433C1; Fri, 11 Nov 2022 17:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668186775; bh=VCaBjaBSC69cfWOYCCxx7f+EfeKrpKSYJMoitiDgIDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OgN6usmTCkJ6AqjsWDcHgS1AK9rAe0uJVmY40hjz0k3pRinIHdz0iNMM0Ced0vXN2 YIkEpFPMNVG74UPjruV1woaoElcLH7oUYLA8Hu07vPRCjTigqPrASPYMknRCSVDwp9 suXcKqf0JM8f7GOsIYWcnT3Zozkm0mHmfhg+g+vQPl/zICDXv3yuRqNnSVXfEV6UmP VBVldYCwaOKVOvSIErg8/36mPhklHTHVz4xJjUJhBm96YsmY+VXiZqJck4Gj4h1L6m b7qLXw7EwKnnvtW2BEIeQhNYQJF2W3Ws5H0Z7Uns4AZlKjjYrOzs7yuUT8ZinbKFca 6ej9AthUs4K6Q== 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 16/33] arm64: idreg_override: Avoid kstrtou64() to parse a single hex digit Date: Fri, 11 Nov 2022 18:11:44 +0100 Message-Id: <20221111171201.2088501-17-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=1909; i=ardb@kernel.org; h=from:subject; bh=VCaBjaBSC69cfWOYCCxx7f+EfeKrpKSYJMoitiDgIDQ=; b=owEB7AET/pANAwAKAcNPIjmS2Y8kAcsmYgBjboJDkEBpVOUEwT7POU7JhiS2ERXH8fhMDAgvE2tx mBAKaZiJAbIEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY26CQwAKCRDDTyI5ktmPJBgPC/ ivYlw4KiQxxoTqTdTmmbHReZbDF6B/3T/Hb/heZ+ovJA5e6njAiqvnUwnVnzHhR1gR2Teh4CB/0FN5 M9dDeXWQNWsGEmK97fnjS58xm2tT6e7yyWICwPk0GRLag6zGWn3+k7tKMmRSixCWMnnaxTGxsWIOdf 8FEwclJGJiZ/ELNcqBzTsbuUcp19ydtFF2GtH4ZpM5c+C5GC6M8Ap4E6N5H8y70j3UBfA30c2XGuBD DF8tKQSuj7YusKXNhG8D9a6MXY7UlY517+koPuJAAfZtr5PcuxV03biGVJ3rCYgTH9M7QtS41NKy/7 tAhD8JuCsVJOdMNy8RLT1/WK6/TtvY+qsVJsAEJ7XnJkzonP30ibz0KIkyBfRAZJSt7k8+VlPT7DBi 0ydeE591t8spR7D0V/p4d40YOjdSfKY6v+r/Kn0p2NxqTZPfx2va01iMvMDuKDal6Kt//m2XKJ1Opr KiJihvWc0opSx/8EHP9S0yUCB30+3Yi9zv1PGPg5G7+A== 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_091258_460633_350027C6 X-CRM114-Status: GOOD ( 17.42 ) 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 All ID register value overrides are =0 with the exception of the nokaslr pseudo feature which uses =1. In order to remove the dependency on kstrtou64(), which is part of the core kernel and no longer usable once we move idreg-override into the early mini C runtime, let's just parse a single hex digit (with optional leading 0x) and set the output value accordingly. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/idreg-override.c | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index a5299aa1d1711adc..7e3eb48f5c83d539 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -170,6 +170,7 @@ static int __init find_field(const char *cmdline, char *opt, int len, const struct ftr_set_desc *reg, int f, u64 *v) { int flen = strlen(reg->fields[f].name); + const char *p; // append '=' to obtain '.=' memcpy(opt + len, reg->fields[f].name, flen); @@ -179,7 +180,31 @@ static int __init find_field(const char *cmdline, char *opt, int len, if (memcmp(cmdline, opt, len)) return -1; - return kstrtou64(cmdline + len, 0, v); + p = cmdline + len; + + // skip "0x" if it comes next + if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) + p += 2; + + // check whether the RHS is a single non-whitespace character + if (*p == '\0' || (p[1] && !isspace(p[1]))) + return -1; + + // only accept a single hex character as the value + switch (*p) { + case '0' ... '9': + *v = *p - '0'; + break; + case 'a' ... 'f': + *v = *p - 'a' + 10; + break; + case 'A' ... 'F': + *v = *p - 'A' + 10; + break; + default: + return -1; + } + return 0; } static const void * __init get_filter(const struct ftr_set_desc *reg, int idx)