lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQ+2icTvHkt7ci285azpci42-8rZ0Air7KtSAmP+bF7m_Q@mail.gmail.com>
Date: Sun, 1 Feb 2026 11:26:07 -0800
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Thorsten Blum <thorsten.blum@...ux.dev>
Cc: Martin KaFai Lau <martin.lau@...ux.dev>, Alexei Starovoitov <ast@...nel.org>, 
	Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>, 
	Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>, 
	Yonghong Song <yonghong.song@...ux.dev>, John Fastabend <john.fastabend@...il.com>, 
	KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, 
	Jiri Olsa <jolsa@...nel.org>, bpf <bpf@...r.kernel.org>, 
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH bpf-next] bpf: Replace snprintf("%s", ...) with strscpy()

On Sun, Feb 1, 2026 at 10:06 AM Thorsten Blum <thorsten.blum@...ux.dev> wrote:
>
> Replace snprintf("%s", ...) with the faster and more direct strscpy().
>
> Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
> ---
>  kernel/bpf/btf.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 8959f3bc1e92..72fa0cb1a71b 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -25,6 +25,7 @@
>  #include <linux/perf_event.h>
>  #include <linux/bsearch.h>
>  #include <linux/kobject.h>
> +#include <linux/string.h>
>  #include <linux/sysfs.h>
>  #include <linux/overflow.h>
>
> @@ -1210,8 +1211,7 @@ static const char *btf_show_name(struct btf_show *show)
>
>         /* Even if we don't want type name info, we want parentheses etc */
>         if (show->flags & BTF_SHOW_NONAME)
> -               snprintf(show->state.name, sizeof(show->state.name), "%s",
> -                        parens);
> +               strscpy(show->state.name, parens);
>         else
>                 snprintf(show->state.name, sizeof(show->state.name),
>                          "%s%s%s(%s%s%s%s%s%s)%s",

I prefer to keep snprintf here for symmetry with the above.

> @@ -6324,7 +6324,7 @@ static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name
>         btf->data_size = data_size;
>         btf->kernel_btf = true;
>         btf->named_start_id = 0;
> -       snprintf(btf->name, sizeof(btf->name), "%s", name);
> +       strscpy(btf->name, name);
>
>         err = btf_parse_hdr(env);
>         if (err)
> @@ -6443,7 +6443,7 @@ static struct btf *btf_parse_module(const char *module_name, const void *data,
>         btf->start_str_off = base_btf->hdr.str_len;
>         btf->kernel_btf = true;
>         btf->named_start_id = 0;
> -       snprintf(btf->name, sizeof(btf->name), "%s", module_name);
> +       strscpy(btf->name, module_name);

These two are fine.

pw-bot: cr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ