From: Petr Pavlu <petr.pavlu@suse.com>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
"Shyam Saini" <shyamsaini@linux.microsoft.com>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Dmitry Antipov" <dmantipov@yandex.ru>,
linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org,
"Daniel Gomez" <da.gomez@kernel.org>
Subject: Re: [PATCH v2] params: Replace deprecated strcpy() with strscpy() and memcpy()
Date: Wed, 13 Aug 2025 16:14:41 +0200 [thread overview]
Message-ID: <f60327bb-6546-4d15-8bd2-a05e85d96b4f@suse.com> (raw)
In-Reply-To: <20250813132200.184064-2-thorsten.blum@linux.dev>
On 8/13/25 3:21 PM, Thorsten Blum wrote:
> strcpy() is deprecated; use strscpy() and memcpy() instead.
>
> In param_set_copystring(), we can safely use memcpy() because we already
> know the length of the source string 'val' and that it is guaranteed to
> be NUL-terminated within the first 'kps->maxlen' bytes.
>
> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Changes in v2:
> - Use memcpy() in param_set_copystring() as suggested by Petr Pavlu
> - Link to v1: https://lore.kernel.org/lkml/20250810214456.2236-1-thorsten.blum@linux.dev/
> ---
> kernel/params.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/params.c b/kernel/params.c
> index b92d64161b75..b96cfd693c99 100644
> --- a/kernel/params.c
> +++ b/kernel/params.c
> @@ -513,13 +513,14 @@ EXPORT_SYMBOL(param_array_ops);
> int param_set_copystring(const char *val, const struct kernel_param *kp)
> {
> const struct kparam_string *kps = kp->str;
> + const size_t len = strnlen(val, kps->maxlen);
>
> - if (strnlen(val, kps->maxlen) == kps->maxlen) {
> + if (len == kps->maxlen) {
> pr_err("%s: string doesn't fit in %u chars.\n",
> kp->name, kps->maxlen-1);
> return -ENOSPC;
> }
> - strcpy(kps->string, val);
> + memcpy(kps->string, val, len + 1);
> return 0;
> }
> EXPORT_SYMBOL(param_set_copystring);
> @@ -841,7 +842,7 @@ static void __init param_sysfs_builtin(void)
> dot = strchr(kp->name, '.');
> if (!dot) {
> /* This happens for core_param() */
> - strcpy(modname, "kernel");
> + strscpy(modname, "kernel");
> name_len = 0;
> } else {
> name_len = dot - kp->name + 1;
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
--
Thanks,
Petr
next prev parent reply other threads:[~2025-08-13 14:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 13:21 Thorsten Blum
2025-08-13 14:14 ` Petr Pavlu [this message]
2025-08-15 19:19 ` Daniel Gomez
2025-08-16 19:51 ` Daniel Gomez
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=f60327bb-6546-4d15-8bd2-a05e85d96b4f@suse.com \
--to=petr.pavlu@suse.com \
--cc=da.gomez@kernel.org \
--cc=dmantipov@yandex.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=mcgrof@kernel.org \
--cc=shyamsaini@linux.microsoft.com \
--cc=thorsten.blum@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®