* [PATCH v4] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf
@ 2025-04-04 18:58 Devaansh Kumar
0 siblings, 0 replies; 4+ messages in thread
From: Devaansh Kumar @ 2025-04-04 18:58 UTC (permalink / raw)
To: rostedt, mhiramat, mathieu.desnoyers
Cc: Devaansh Kumar, linux-trace-kernel, linux-kernel, skhan,
linux-kernel-mentees
strncpy() is deprecated for NUL-terminated destination buffers and must
be replaced by strscpy().
See issue: https://github.com/KSPP/linux/issues/90
Signed-off-by: Devaansh Kumar <devaanshk840@gmail.com>
---
kernel/trace/trace_stack.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index 5a48dba912ea..617e59a234da 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -544,7 +544,7 @@ static __init int enable_stacktrace(char *str)
int len;
if ((len = str_has_prefix(str, "_filter=")))
- strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
+ strscpy(stack_trace_filter_buf, str + len, sizeof(stack_trace_filter_buf));
stack_tracer_enabled = 1;
return 1;
--
2.47.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v4] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf
@ 2025-04-18 22:14 Devaansh Kumar
2025-04-19 2:45 ` Steven Rostedt
0 siblings, 1 reply; 4+ messages in thread
From: Devaansh Kumar @ 2025-04-18 22:14 UTC (permalink / raw)
To: rostedt, mhiramat, mathieu.desnoyers
Cc: Devaansh Kumar, linux-trace-kernel, linux-kernel, skhan,
linux-kernel-mentees
strncpy() is deprecated for NUL-terminated destination buffers and must
be replaced by strscpy().
See issue: https://github.com/KSPP/linux/issues/90
Signed-off-by: Devaansh Kumar <devaanshk840@gmail.com>
---
kernel/trace/trace_stack.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index 14c6f272c4d8..0f2253f3bc8c 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -542,7 +542,7 @@ static __init int enable_stacktrace(char *str)
int len;
if ((len = str_has_prefix(str, "_filter=")))
- strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
+ strscpy(stack_trace_filter_buf, str + len, sizeof(stack_trace_filter_buf));
stack_tracer_enabled = 1;
return 1;
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf
2025-04-18 22:14 Devaansh Kumar
@ 2025-04-19 2:45 ` Steven Rostedt
2025-04-19 9:29 ` Devaansh Kumar
0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2025-04-19 2:45 UTC (permalink / raw)
To: Devaansh Kumar
Cc: mhiramat, mathieu.desnoyers, linux-trace-kernel, linux-kernel,
skhan, linux-kernel-mentees
On Sat, 19 Apr 2025 03:44:41 +0530
Devaansh Kumar <devaanshk840@gmail.com> wrote:
> diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
> index 14c6f272c4d8..0f2253f3bc8c 100644
> --- a/kernel/trace/trace_stack.c
> +++ b/kernel/trace/trace_stack.c
> @@ -542,7 +542,7 @@ static __init int enable_stacktrace(char *str)
> int len;
>
> if ((len = str_has_prefix(str, "_filter=")))
> - strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
> + strscpy(stack_trace_filter_buf, str + len, sizeof(stack_trace_filter_buf));
Is the sizeof() needed?
From include/linux/string.h:
/**
* strscpy - Copy a C-string into a sized buffer
* @dst: Where to copy the string to
* @src: Where to copy the string from
* @...: Size of destination buffer (optional)
*
* Copy the source string @src, or as much of it as fits, into the
* destination @dst buffer. The behavior is undefined if the string
* buffers overlap. The destination @dst buffer is always NUL terminated,
* unless it's zero-sized.
*
* The size argument @... is only required when @dst is not an array, or
* when the copy needs to be smaller than sizeof(@dst).
*
* Preferred to strncpy() since it always returns a valid string, and
* doesn't unnecessarily force the tail of the destination buffer to be
* zero padded. If padding is desired please use strscpy_pad().
*
* Returns the number of characters copied in @dst (not including the
* trailing %NUL) or -E2BIG if @size is 0 or the copy from @src was
* truncated.
*/
#define strscpy(dst, src, ...) \
CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
With stack_trace_filter_buf defined as:
static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
This looks like a text book example of just having that be:
strscpy(stack_trace_filter_buf, str + len);
-- Steve
>
> stack_tracer_enabled = 1;
> return 1;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf
2025-04-19 2:45 ` Steven Rostedt
@ 2025-04-19 9:29 ` Devaansh Kumar
0 siblings, 0 replies; 4+ messages in thread
From: Devaansh Kumar @ 2025-04-19 9:29 UTC (permalink / raw)
To: Steven Rostedt
Cc: mhiramat, mathieu.desnoyers, linux-trace-kernel, linux-kernel,
skhan, linux-kernel-mentees
On Sat, 19 Apr 2025 at 08:15, Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Sat, 19 Apr 2025 03:44:41 +0530
> Devaansh Kumar <devaanshk840@gmail.com> wrote:
>
> > diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
> > index 14c6f272c4d8..0f2253f3bc8c 100644
> > --- a/kernel/trace/trace_stack.c
> > +++ b/kernel/trace/trace_stack.c
> > @@ -542,7 +542,7 @@ static __init int enable_stacktrace(char *str)
> > int len;
> >
> > if ((len = str_has_prefix(str, "_filter=")))
> > - strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
> > + strscpy(stack_trace_filter_buf, str + len, sizeof(stack_trace_filter_buf));
>
> Is the sizeof() needed?
>
> From include/linux/string.h:
>
> /**
> * strscpy - Copy a C-string into a sized buffer
> * @dst: Where to copy the string to
> * @src: Where to copy the string from
> * @...: Size of destination buffer (optional)
> *
> * Copy the source string @src, or as much of it as fits, into the
> * destination @dst buffer. The behavior is undefined if the string
> * buffers overlap. The destination @dst buffer is always NUL terminated,
> * unless it's zero-sized.
> *
> * The size argument @... is only required when @dst is not an array, or
> * when the copy needs to be smaller than sizeof(@dst).
> *
> * Preferred to strncpy() since it always returns a valid string, and
> * doesn't unnecessarily force the tail of the destination buffer to be
> * zero padded. If padding is desired please use strscpy_pad().
> *
> * Returns the number of characters copied in @dst (not including the
> * trailing %NUL) or -E2BIG if @size is 0 or the copy from @src was
> * truncated.
> */
> #define strscpy(dst, src, ...) \
> CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
>
> With stack_trace_filter_buf defined as:
>
> static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
>
> This looks like a text book example of just having that be:
>
> strscpy(stack_trace_filter_buf, str + len);
>
Right I have tested it, just using strscpy(stack_trace_filter_buf, str
+ len) works.
> -- Steve
>
>
> >
> > stack_tracer_enabled = 1;
> > return 1;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-19 9:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-04 18:58 [PATCH v4] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf Devaansh Kumar
-- strict thread matches above, loose matches on Subject: below --
2025-04-18 22:14 Devaansh Kumar
2025-04-19 2:45 ` Steven Rostedt
2025-04-19 9:29 ` Devaansh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox