Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp1201430rdb; Fri, 1 Sep 2023 16:44:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhA1G47GRl9KOKh9WOehDRHcCwAzz01h2CRVS3jl46jrhyA2Vi1U0Z+wwzgo9i3pRCtXzo X-Received: by 2002:a05:6a20:428c:b0:140:3aa:e2ce with SMTP id o12-20020a056a20428c00b0014003aae2cemr5041445pzj.42.1693611861858; Fri, 01 Sep 2023 16:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693611861; cv=none; d=google.com; s=arc-20160816; b=v0efNR6YwgO1fskkTdPHKsYXJnoq0Gpt8UFFqA3h+5D0z2WNaKtVzrHE2qYR+PTgoH yaRABtQAMA0yl7iLwrEOr8SJIlfDrAuyoTHfivy0L9jFRkeWRLz5xpkIYzvIXntntW0Y r7kklmIsNL6nS9+6sj6JTVoPzMzScC8F1rqZf7niUh1F9VvCExD2Eac/UGqI/siCOUdE TYMWr/0wbspbgdhU2I83bilv1QHDSYhTw4+b70BZA0ltRD69YbAbdtMUBC8oAlXIqMFG f0VKpzyHALuv9BEIcFsKymnEq700gLSwNKgv6y51M5bN3dxRtvQKIw1WSUSsgtiwzaS0 FVnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=ghaqThwuWHkeXM1NXR1XB4OCqTJJfT4DOtzOvDFQEdM=; fh=gwWN+x0qbYVyepxp5y+OqBs74VkP4sdcP8KduUyJHx4=; b=x+IzhXF6paC06NWaWko+XjFczoRCFncl8gjLCGamU9rJqY/tFe5NO6mNaMpsSPDsW/ SREk022C6I7/lHjC2f16CX9K8UkV5OymwhiKjh0Ct2LRnef8ZJi5Qi5u1cVHfQw7/F7x 3XVm5G6Xx8ADjM1YYSGeyy4pOlqoQ5z6zXwFhmshNWNbb20Q8Qpbv9fGA5qG+AiPAVAn QmJlnmDmSBVMEmzIYH9HJ+IY3PGtJBGH/s53Rpg9oZsEChh16OV6xXGqrXYCtMhdd/S0 S5TrBXl2dH9yoNgyXky3oIMckKfbdkpXPuJqouCUqTzwKPUoUY3SYjeP0/+wsp2Jqx+9 1V2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fQdJjKHl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a63d543000000b00569ca182dbfsi3645011pgi.657.2023.09.01.16.44.08; Fri, 01 Sep 2023 16:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fQdJjKHl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349148AbjIALYz (ORCPT + 99 others); Fri, 1 Sep 2023 07:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231963AbjIALYy (ORCPT ); Fri, 1 Sep 2023 07:24:54 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEDD6FC for ; Fri, 1 Sep 2023 04:24:51 -0700 (PDT) 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 07B93CE22C2 for ; 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") Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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.