From: Stephen Boyd <sboyd@kernel.org>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
Douglas Anderson <dianders@chromium.org>
Cc: Douglas Anderson <dianders@chromium.org>,
Andy Gross <agross@kernel.org>,
Konrad Dybcio <konrad.dybcio@somainline.org>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] soc: qcom: cmd-db: replace strscpy_pad() with strncpy()
Date: Mon, 27 Jun 2022 16:52:46 -0700 [thread overview]
Message-ID: <20220627235248.43895C34115@smtp.kernel.org> (raw)
In-Reply-To: <20220627161642.1.Ie7b480cd99e2c13319220cbc108caf2bcd41286b@changeid>
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.
>
> 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.
>
> 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.
>
> Fixes: ac0126a01735 ("soc: qcom: cmd-db: replace strncpy() with strscpy_pad()")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
>
> drivers/soc/qcom/cmd-db.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> 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.
>
> ret = cmd_db_ready();
> if (ret)
> return ret;
>
> /* Pad out query string to same length as in DB */
> - strscpy_pad(query, id, sizeof(query));
> + strncpy(query, id, sizeof(query));
prev parent reply other threads:[~2022-06-27 23:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 23:17 [PATCH] soc: qcom: cmd-db: replace strscpy_pad() with strncpy() Douglas Anderson
2022-06-27 23:49 ` Matthias Kaehlcke
2022-06-27 23:52 ` Stephen Boyd [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220627235248.43895C34115@smtp.kernel.org \
--to=sboyd@kernel.org \
--cc=agross@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=dianders@chromium.org \
--cc=konrad.dybcio@somainline.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.