From: Steven Rostedt <rostedt@goodmis.org>
To: Devaansh Kumar <devaanshk840@gmail.com>
Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH v4] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf
Date: Fri, 18 Apr 2025 22:45:55 -0400 [thread overview]
Message-ID: <20250418224555.5b8b8232@batman.local.home> (raw)
In-Reply-To: <20250418221443.1067938-1-devaanshk840@gmail.com>
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;
next prev parent reply other threads:[~2025-04-19 2:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 22:14 [PATCH v4] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf Devaansh Kumar
2025-04-19 2:45 ` Steven Rostedt [this message]
2025-04-19 9:29 ` Devaansh Kumar
-- strict thread matches above, loose matches on Subject: below --
2025-04-04 18:58 Devaansh Kumar
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=20250418224555.5b8b8232@batman.local.home \
--to=rostedt@goodmis.org \
--cc=devaanshk840@gmail.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=skhan@linuxfoundation.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