From patchwork Thu Aug 31 16:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mostafa Saleh X-Patchwork-Id: 13371701 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 A615BC83F01 for ; Thu, 31 Aug 2023 16:23:06 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Gfvfc1yKSINvrw5H2mwZGi8gTO8lOOEM9xQXAfBVQVM=; b=T4m SSLRkI1l1kNQIGXgVuys56Tx08IsGZOPB6IowBnVNg5iowtqw4dYsZy+KOy2QrEqpgv7QiK94OFzR hJfoxxWB+5+2kd8VNosiJ7C0tBaPwArfbdYEMAjE7gTNH8z+NGGnyriN6CbR+4eXedsFg+Dj274KP fig4mAbvRkU2Oq8olN2omfj0jrFHWgUDBgO7TqUb1SbUq9OnXkrYLS1QaIAKQ5LR1+qwZjV+Wv/xx io72UiP9Sm62oEzs+3lWJkP/FDwuur6RHSHCwcWtPQL+MGcjA6IXR7CMRYjMPvOe3xTKZqzz9R75U 80/BPno45w6dAZaTGLaQdkD//X1DGkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbkRK-00FZCd-2G; Thu, 31 Aug 2023 16:22:38 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qbkRI-00FZC2-07 for linux-arm-kernel@lists.infradead.org; Thu, 31 Aug 2023 16:22:37 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-30e3ee8a42eso547005f8f.1 for ; Thu, 31 Aug 2023 09:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693498953; x=1694103753; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5e1f1jwIr39xnfoPu0/5wZ+z+ZWuODpVrtDXgqFCd/Y=; b=mofCC3FPDkgboh2VcetMhrcpLToYj/qGT464Y8f67tkxv65RkE5h8gxpZ9leM3LzWa Wi2yHMNq7/+t7SXF1uhMzb0VFYKDY7ngQkRumuxhrEaKXdyPCYHuUNWsUUL+TeF66HEy roVdifi9FFuu9EVLL/wRTazY6zCb6k3PjxmxwowvT2K2quMumjRcGLJlxwWvkdI2LLtC BUn3FOJd3q51XcC660BiZX2iAGyjfOnhCevgx8akIhoopnQRuqlpXt7dxUpBHvrWBMYU UHkQLaoitt/j0sQyo1kkkXF3c+U1evoOjQxUYmGwm5S//yfXI+Y71sAz6HIUwJYalAxk boIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693498953; x=1694103753; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5e1f1jwIr39xnfoPu0/5wZ+z+ZWuODpVrtDXgqFCd/Y=; b=cWPq66Uq7p3pftXl2pDULQAy44pPpUfgCXBTApVr/R2KhlJNLrUQq5J8KdqEwLIxHz FUnFLunvVUWBR3j2BF0l+U8OsMc/2bHmkgaVe9FpI4eWq2QBVUFVlrXF4dkAnX+Sr8Nb YQvbSiIkx5JjHxHfKlAmy4iIinlhbPv+VZluyVUAlYr/m0bEUSulrcomP+1YwFhWsIll YA73zJ+DFKU+veZqbOPiO964NNVOgE/uUMv8QlYb14CbrCd/4gLxtGq7T3dEYyJmIhmr ikNRI4r3CDQ+fSdxJuneFD3sJXlJg1RyoRocdkcTMYE7jzSp0g+1PU1u9fw8X9YADAE2 hxUQ== X-Gm-Message-State: AOJu0Yw8SU/VORQu/NsYJI1vc4REVuVwVf+lVJcbHroEVL/cZJuqc+tl T5jYzMxrm89HwtAs/0EeyvuOq05ElTed1w== X-Google-Smtp-Source: AGHT+IEQ6/d4vxUA+8GYooqvM7bVUjnFltIXaDlryCLf8phmepAtkTSn+zOcKuwc2JiGI5yx+H5W0tXYse/6Rg== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:adf:e706:0:b0:31c:6629:a583 with SMTP id c6-20020adfe706000000b0031c6629a583mr87287wrm.13.1693498952747; Thu, 31 Aug 2023 09:22:32 -0700 (PDT) Date: Thu, 31 Aug 2023 16:22:27 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230831162227.2307863-1-smostafa@google.com> Subject: [PATCH] Revert "arm64/sysreg: refactor deprecated strncpy" From: Mostafa Saleh To: catalin.marinas@arm.com, will@kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: maz@kernel.org, oliver.upton@linux.dev, kristina.martsenko@arm.com, broonie@kernel.org, quic_pkondeti@quicinc.com, smostafa@google.com, justinstitt@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230831_092236_072405_C8F15E6E X-CRM114-Status: GOOD ( 12.79 ) 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 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 Tested-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;