The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] tracing: Always use memcpy() in histogram add_to_key()
@ 2025-04-04  1:06 Steven Rostedt
  2025-04-07  1:04 ` Masami Hiramatsu
  2025-04-08 19:32 ` Tom Zanussi
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2025-04-04  1:06 UTC (permalink / raw)
  To: LKML, Linux Trace Kernel
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Tom Zanussi, Kees Cook,
	linux-hardening

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>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tracing: Always use memcpy() in histogram add_to_key()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2025-04-07  1:04 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Linux Trace Kernel, Masami Hiramatsu, Mathieu Desnoyers,
	Tom Zanussi, Kees Cook, linux-hardening

On Thu, 3 Apr 2025 21:06:37 -0400
Steven Rostedt <rostedt@goodmis.org> 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.
> 

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you,

> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.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@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tracing: Always use memcpy() in histogram add_to_key()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Zanussi @ 2025-04-08 19:32 UTC (permalink / raw)
  To: Steven Rostedt, LKML, Linux Trace Kernel
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Kees Cook, linux-hardening

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-08 19:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox