[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250407100430.5fbc9d1de5eb0c4c552323d9@kernel.org>
Date: Mon, 7 Apr 2025 10:04:30 +0900
From: Masami Hiramatsu (Google) <mhiramat@...nel.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: LKML <linux-kernel@...r.kernel.org>, Linux Trace Kernel
<linux-trace-kernel@...r.kernel.org>, Masami Hiramatsu
<mhiramat@...nel.org>, Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Tom Zanussi <zanussi@...nel.org>, Kees Cook <keescook@...omium.org>,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH] tracing: Always use memcpy() in histogram add_to_key()
On Thu, 3 Apr 2025 21:06:37 -0400
Steven Rostedt <rostedt@...dmis.org> wrote:
> From: Steven Rostedt <rostedt@...dmis.org>
>
> The add_to_key() function tests if the key is a string or some data. If
> it's a string it does some further calculations of the string size (still
> truncating it to the max size it can be), and calls strncpy().
>
> If the key isn't as string it calls memcpy(). The interesting point is
> that both use the exact same parameters:
>
> strncpy(compound_key + key_field->offset, (char *)key, size);
> } else
> memcpy(compound_key + key_field->offset, key, size);
>
> As strncpy() is being used simply as a memcpy() for a string, and since
> strncpy() is deprecated, just call memcpy() for both memory and string
> keys.
>
Looks good to me.
Acked-by: Masami Hiramatsu (Google) <mhiramat@...nel.org>
Thank you,
> Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>
> ---
> kernel/trace/trace_events_hist.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index c1ea6aaac182..4258324219ca 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -5224,10 +5224,8 @@ static inline void add_to_key(char *compound_key, void *key,
> /* ensure NULL-termination */
> if (size > key_field->size - 1)
> size = key_field->size - 1;
> -
> - strncpy(compound_key + key_field->offset, (char *)key, size);
> - } else
> - memcpy(compound_key + key_field->offset, key, size);
> + }
> + memcpy(compound_key + key_field->offset, key, size);
> }
>
> static void
> --
> 2.47.2
>
--
Masami Hiramatsu (Google) <mhiramat@...nel.org>
Powered by blists - more mailing lists