From: Tom Zanussi <zanussi@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>,
Linux Trace Kernel <linux-trace-kernel@vger.kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Kees Cook <keescook@chromium.org>,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH] tracing: Always use memcpy() in histogram add_to_key()
Date: Tue, 08 Apr 2025 14:32:50 -0500 [thread overview]
Message-ID: <d37227b12b2fa46dfe4d50f11c428040ed79a076.camel@kernel.org> (raw)
In-Reply-To: <20250403210637.1c477d4a@gandalf.local.home>
Hi Steve,
On Thu, 2025-04-03 at 21:06 -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.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.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Looks good, thanks.
Reviewed-by: Tom Zanussi <zanussi@kernel.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
prev parent reply other threads:[~2025-04-08 19:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 1:06 [PATCH] tracing: Always use memcpy() in histogram add_to_key() Steven Rostedt
2025-04-07 1:04 ` Masami Hiramatsu
2025-04-08 19:32 ` Tom Zanussi [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=d37227b12b2fa46dfe4d50f11c428040ed79a076.camel@kernel.org \
--to=zanussi@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox