From mboxrd@z Thu Jan 1 00:00:00 1970 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 DC0DFCA0FE1 for ; Fri, 1 Sep 2023 11:25:31 +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: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y+YnVmn83MunldvxYvXX4UmpxboFDsHSzM1193nDgvU=; b=DsHwtifVygSrt4 dYuYOhOtrzMBfDY7uHkzeVTAJxGsjsp69XADZNO1a0vGpL/d3YDRf0WRa3QY6Ltv8jP93eDUMt64V rkXeaH7AsoqxabDKyMyUpVJDKKxZcBSnm/pIbbNysADveRw0NovPUqq1+6YbNhZ/4F2MKmacPfhts tUkCalRlvNZWBnonFuF/x5r18fDNEESn0ylco8LtjxeWJ2oln9DSKOdW220f8yIwWnpe4Fl5hWBQI wikKmWloMyIg7VgUCk2Un/sH0kauzT3bin2TVyvscycJEjjoTxhXR2EQpdZ/XsKJA2dBY8JOOPTMt +wk9dNKpC9MfPTkocyRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qc2Gn-00HF8v-1k; Fri, 01 Sep 2023 11:24:57 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qc2Gk-00HF7v-0t for linux-arm-kernel@lists.infradead.org; Fri, 01 Sep 2023 11:24:55 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 032C1CE224C; Fri, 1 Sep 2023 11:24:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40438C433C8; Fri, 1 Sep 2023 11:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693567488; bh=ISlbIFDzUSUgg9q15hbTTknP8Yy5t0vmuvU3sSDJ3z4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fQdJjKHl0OU1E81MEcl1CatFCNww7Ku8s37FGuhALWAOJVAycEzyRmDWnZKo+nBCA IlScbaGvU7SgexkowRFnBizO62vVfjtqMlQaUCZeRvaZbcb6MUWrRGsum6lSC9Jx3A Seq87tiv0NVnMLWb2t+5MQcoXeq6GabXJeNyolcsg2tD9exQk3ugk9g41iHh9kvvGm 84U0kL7kQFkGkbr0tiLVR7ADbD9BUI7Vv8kASlyPGdbIAuNDEfL7ro0UM3rikvG96J 97GaIDK6vDsNCgXeoaYVnDUhg19OgxPWTvm41chErXJXIleGad6DQRHPgZv44NFmBk TWjq9zxUgAPuA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qc2Gb-009vXb-FT; Fri, 01 Sep 2023 12:24:45 +0100 Date: Fri, 01 Sep 2023 12:24:45 +0100 Message-ID: <86v8cudtky.wl-maz@kernel.org> From: Marc Zyngier To: Mostafa Saleh Cc: catalin.marinas@arm.com, will@kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, kristina.martsenko@arm.com, broonie@kernel.org, quic_pkondeti@quicinc.com, justinstitt@google.com Subject: Re: [PATCH] Revert "arm64/sysreg: refactor deprecated strncpy" In-Reply-To: <20230831162227.2307863-1-smostafa@google.com> References: <20230831162227.2307863-1-smostafa@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: smostafa@google.com, catalin.marinas@arm.com, will@kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, kristina.martsenko@arm.com, broonie@kernel.org, quic_pkondeti@quicinc.com, justinstitt@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230901_042454_684678_061F4A7B X-CRM114-Status: GOOD ( 25.24 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Mostafa, On Thu, 31 Aug 2023 17:22:27 +0100, Mostafa Saleh wrote: > > This reverts commit d232606773a0b09ec7f1ffc25f63abe801d011fd. > > Using strscpy is not correct in this context and the commit > assumption is not right "strncpy is deprecated for use on > NUL-terminated destination strings". > > strncpy is used here to copy parts of the string(cmdline) separated > by spaces into the buffer and not a NULL terminated string. > > This breaks the arm options "kvm-arm.mode=protected, arm64.nobti ..." > > Signed-off-by: Mostafa Saleh > --- > arch/arm64/kernel/idreg-override.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c > index aee12c75b738..2fe2491b692c 100644 > --- a/arch/arm64/kernel/idreg-override.c > +++ b/arch/arm64/kernel/idreg-override.c > @@ -262,9 +262,9 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) > if (!len) > return; > > - len = strscpy(buf, cmdline, ARRAY_SIZE(buf)); > - if (len == -E2BIG) > - len = ARRAY_SIZE(buf) - 1; > + len = min(len, ARRAY_SIZE(buf) - 1); > + strncpy(buf, cmdline, len); > + buf[len] = 0; > > if (strcmp(buf, "--") == 0) > return; Instead of completely reverting the patch, maybe something like the hack below (completely untested), so that we can still get rid of another instance of strncpy(), and yet bring back some sanity in the logic? Thanks, M. diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index aee12c75b738..be5c778a3f14 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -262,9 +262,8 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) if (!len) return; - len = strscpy(buf, cmdline, ARRAY_SIZE(buf)); - if (len == -E2BIG) - len = ARRAY_SIZE(buf) - 1; + len = min(len, ARRAY_SIZE(buf) - 1); + strscpy(buf, cmdline, len); if (strcmp(buf, "--") == 0) return; -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel