Linux Trace Kernel
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Justin Stitt <justinstitt@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] tracing: replace multiple deprecated strncpy with memcpy
Date: Mon, 14 Oct 2024 14:31:29 -0700	[thread overview]
Message-ID: <202410141423.2C30F35EE0@keescook> (raw)
In-Reply-To: <20241014-strncpy-kernel-trace-trace_events_filter-c-v2-1-d821e81e371e@google.com>

On Mon, Oct 14, 2024 at 02:13:14PM -0700, Justin Stitt wrote:
> strncpy() is deprecated for use on NUL-terminated destination strings [1] and
> as such we should prefer more robust and less ambiguous string interfaces.
> 
> String copy operations involving manual pointer offset and length
> calculations followed by explicit NUL-byte assignments are best changed
> to either strscpy or memcpy.
> 
> strscpy is not a drop-in replacement as @len would need a one subtracted
> from it to avoid truncating the source string.
> 
> To not sabotage readability of the current code, use memcpy (retaining
> the manual NUL assignment) as this unambiguously describes the desired
> behavior.

We know the destination must have a NUL-terminated string. Is the src
NUL terminated? Looking at parse_pred(), it seems like no? And we can't
use memtostr_pad() here because the source buffer size isn't known at
compile time. Okay then. And there are no NUL bytes in the "str + s"
span, so yeah, it looks like memcpy() is best.

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

  reply	other threads:[~2024-10-14 21:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 21:13 [PATCH v2] tracing: replace multiple deprecated strncpy with memcpy Justin Stitt
2024-10-14 21:31 ` Kees Cook [this message]
2024-10-14 21:54   ` Steven Rostedt

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=202410141423.2C30F35EE0@keescook \
    --to=kees@kernel.org \
    --cc=justinstitt@google.com \
    --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