Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3484231iog; Mon, 27 Jun 2022 17:40:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vqM02ZszElSENX+S8IZDfvE035eCoTPlU1BeUn2jm0TFEhWhJcqEwGURG8pVI5YGVsUVuF X-Received: by 2002:a63:5a21:0:b0:3fd:41e4:f833 with SMTP id o33-20020a635a21000000b003fd41e4f833mr14873101pgb.409.1656376839940; Mon, 27 Jun 2022 17:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656376839; cv=none; d=google.com; s=arc-20160816; b=zs8aswbh7w5wKUE0D/EDQ9VdRv13YZbY8uwZR4mDxnSVuaNp3MRMAoObiBGady+QSl Mz1w/wKxEFMa4iDXCnLP/i8agrbyxDIxxDGqqf+/mrWw5SjCDIjbCY+2IpEIl5Aqf+ac Z0z1LsqZBWEPnfZRaPvJb+Vsg03I/oiAwrWwjayNg/FOTi1Y5YxImtxmJyl2BWCn1yN/ FTlKOF7tssb62/vVHt69JD8Qu9ZJt/8iW6Q1jfzLhD7JdKY/nml/AcSIdbMyqESWy+9e 2SOyTvWQkhXx9LZf9ddy62cE+offNwDUUQ/pBy0SgDGvIM6jqDDqEUMBVK/jWLCQggI+ NdLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:date:to:cc:from:subject :references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=l7DDFVrPMfmqLvLRnUgQk8NFZdTzFqKsdcE9f6j29xA=; b=e4i9nyp+A1OEJ6uiMILVPTBZIDingYAmi/9U4u7luMJJRJV71S+O8kBjs7qh5V+MWN nET6rAVcBLIdtMIuULx+b0N7NSlCunwt7nXtl+ZlPg0nKD8H8V5aGq5pcBY2dvHPdyg9 bliTpY3Cmlpu/OWJ4d8WpjgFUpmfSZjaw47PGnGbYD0WnQKLvs55t8kKVYASwCulWQXy 1tqxSOreg6d1wj03fGsEfhZ29XJWHKQMDyNSrctn5duDqp7W1UUUr8pNJqiORCcIsNQ8 XZzIkr5ra/FGlA74rkNSzKSpzexRzwkUZbC5LwIcR/udc6kRaqz2zLxjORrL8VDU7NSR vq1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ITNEpab7; 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 j2-20020a056a00174200b0051872773159si19272576pfc.228.2022.06.27.17.40.27; Mon, 27 Jun 2022 17:40:39 -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=ITNEpab7; 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 S242364AbiF0Xwu (ORCPT + 99 others); Mon, 27 Jun 2022 19:52:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242350AbiF0Xwt (ORCPT ); Mon, 27 Jun 2022 19:52:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59378E0B1; Mon, 27 Jun 2022 16:52:49 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id F13F161629; Mon, 27 Jun 2022 23:52:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43895C34115; Mon, 27 Jun 2022 23:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656373968; bh=9o8m950DV1fTZ5y8Xg05BQF6yJMVzXBC+OPeMCZsUGE=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=ITNEpab73iKnpFuZO1fsLuu9Bp4nVLQIXMSgxrBjfMrS9jnspsnARvsN/0PoDyVR0 xy9klbC7mVhKey7HpboQSJpekk8anFbbm392b1XIHuRLPtRTaAPKSYCzl5kyws+OCL 1S7XOLCZEoYPQGVw3TLxqyug+ehZnOARxSXZmyB8pcmHuU1i+sPhBX1g7fi3MhFSyg mQ4MZppTFdi0jllcIlygL9Y7ZlbfJVP0T5TVQ6AG+Qdo2SFryIkaUaZXVasA9GcgMD 2rh6eMrfZiwwaiJ8dYibmYf43ooR1dHH6ISXlMenlW/GEKwnCarGn61wVBmrtN4Cmd KeWgHWPa0o+Yg== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20220627161642.1.Ie7b480cd99e2c13319220cbc108caf2bcd41286b@changeid> References: <20220627161642.1.Ie7b480cd99e2c13319220cbc108caf2bcd41286b@changeid> Subject: Re: [PATCH] soc: qcom: cmd-db: replace strscpy_pad() with strncpy() From: Stephen Boyd Cc: Douglas Anderson , Andy Gross , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org To: Bjorn Andersson , Douglas Anderson Date: Mon, 27 Jun 2022 16:52:46 -0700 User-Agent: alot/0.10 Message-Id: <20220627235248.43895C34115@smtp.kernel.org> X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Quoting Douglas Anderson (2022-06-27 16:17:00) > Commit ac0126a01735 ("soc: qcom: cmd-db: replace strncpy() with > strscpy_pad()") breaks booting on my sc7280-herobrine-herobrine > device. From printouts I see that at bootup the function is called > with an id of "lnbclka2" which is 8 bytes big. >=20 > Previously all 8 bytes of this string were copied to the > destination. Now only 7 bytes will be copied since strscpy_pad() saves > a byte for '\0' termination. >=20 > We don't need the '\0' termination in the destination. Let's go back > to strncpy(). According to the warning: > If a caller is using non-NUL-terminated strings, strncpy() can still > be used, but destinations should be marked with the __nonstring > attribute to avoid future compiler warnings. > ...so we'll do that. >=20 > Fixes: ac0126a01735 ("soc: qcom: cmd-db: replace strncpy() with strscpy_p= ad()") > Signed-off-by: Douglas Anderson > --- >=20 > drivers/soc/qcom/cmd-db.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c > index c5137c25d819..0aafe90277bc 100644 > --- a/drivers/soc/qcom/cmd-db.c > +++ b/drivers/soc/qcom/cmd-db.c > @@ -141,14 +141,14 @@ static int cmd_db_get_header(const char *id, const = struct entry_header **eh, > const struct rsc_hdr *rsc_hdr; > const struct entry_header *ent; > int ret, i, j; > - u8 query[8]; > + u8 query[8] __nonstring; Since you're already here, can you change 8 to be sizeof(ent->id)? That would directly tie the two lengths together so that one can't change and then the carefully crafted strncpy() fails again. > =20 > ret =3D cmd_db_ready(); > if (ret) > return ret; > =20 > /* Pad out query string to same length as in DB */ > - strscpy_pad(query, id, sizeof(query)); > + strncpy(query, id, sizeof(query));