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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPSxiM_hKOdMkpsogs8dhX3S=Fz42noOFM1KFTYmaBBwK6g23w@mail.gmail.com>
Date: Thu, 3 Jul 2025 00:23:44 +0530
From: Usman Akinyemi <usmanakinyemi202@...il.com>
To: peterz@...radead.org, mingo@...hat.com, acme@...nel.org, 
	namhyung@...nel.org
Cc: mark.rutland@....com, alexander.shishkin@...ux.intel.com, jolsa@...nel.org, 
	irogers@...gle.com, adrian.hunter@...el.com, kan.liang@...ux.intel.com, 
	james.clark@...aro.org, linux-perf-users@...r.kernel.org, 
	linux-kernel@...r.kernel.org, skhan@...uxfoundation.org, 
	linux-kernel-mentees@...ts.linux.dev
Subject: Re: [PATCH] perf/x86: Replace strncpy() with memcpy() for vendor string

On Thu, Jun 19, 2025 at 3:28 AM Usman Akinyemi
<usmanakinyemi202@...il.com> wrote:
>
> strncpy() is unsafe for fixed-size binary data as
> it may not NUL-terminate and is deprecated for such
> usage. Since we're copying raw CPUID register values,
> memcpy() is the correct and safe choice.
>
> Signed-off-by: Usman Akinyemi <usmanakinyemi202@...il.com>
> ---
>  tools/perf/arch/x86/util/header.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c
> index 412977f8aa83..43ba55627817 100644
> --- a/tools/perf/arch/x86/util/header.c
> +++ b/tools/perf/arch/x86/util/header.c
> @@ -16,9 +16,9 @@ void get_cpuid_0(char *vendor, unsigned int *lvl)
>         unsigned int b, c, d;
>
>         cpuid(0, 0, lvl, &b, &c, &d);
> -       strncpy(&vendor[0], (char *)(&b), 4);
> -       strncpy(&vendor[4], (char *)(&d), 4);
> -       strncpy(&vendor[8], (char *)(&c), 4);
> +       memcpy(&vendor[0], (char *)(&b), 4);
> +       memcpy(&vendor[4], (char *)(&d), 4);
> +       memcpy(&vendor[8], (char *)(&c), 4);
>         vendor[12] = '\0';
>  }
>
Hello,

I am just bringing attention to this patch.

I have not received any comments about it.

Thank you.
Usman Akinyemi.
> --
> 2.49.0
>

On Thu, Jun 19, 2025 at 3:28 AM Usman Akinyemi
<usmanakinyemi202@...il.com> wrote:
>
> strncpy() is unsafe for fixed-size binary data as
> it may not NUL-terminate and is deprecated for such
> usage. Since we're copying raw CPUID register values,
> memcpy() is the correct and safe choice.
>
> Signed-off-by: Usman Akinyemi <usmanakinyemi202@...il.com>
> ---
>  tools/perf/arch/x86/util/header.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c
> index 412977f8aa83..43ba55627817 100644
> --- a/tools/perf/arch/x86/util/header.c
> +++ b/tools/perf/arch/x86/util/header.c
> @@ -16,9 +16,9 @@ void get_cpuid_0(char *vendor, unsigned int *lvl)
>         unsigned int b, c, d;
>
>         cpuid(0, 0, lvl, &b, &c, &d);
> -       strncpy(&vendor[0], (char *)(&b), 4);
> -       strncpy(&vendor[4], (char *)(&d), 4);
> -       strncpy(&vendor[8], (char *)(&c), 4);
> +       memcpy(&vendor[0], (char *)(&b), 4);
> +       memcpy(&vendor[4], (char *)(&d), 4);
> +       memcpy(&vendor[8], (char *)(&c), 4);
>         vendor[12] = '\0';
>  }
>
> --
> 2.49.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ