Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing/branch-profiler: Replace deprecated strncpy with strscpy

strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.

Both of these fields want to be NUL-terminated as per their use in
printk:

F_printk("%u:%s:%s (%u)%s",
__entry->line,
__entry->func, __entry->file, __entry->correct,
__entry->constant ? " CONSTANT" : "")

Use strscpy() as it NUL-terminates the destination buffer, so it doesn't
have to be done manually.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/20240826-strncpy-kernel-trace-trace_branch-c-v1-1-b2c14f2e9e84@google.com
Signed-off-by: Justin Stitt <justinstitt@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Justin Stitt and committed by
Steven Rostedt (Google)
2aa746ec e32540b1

+2 -4
+2 -4
kernel/trace/trace_branch.c
··· 74 74 p--; 75 75 p++; 76 76 77 - strncpy(entry->func, f->data.func, TRACE_FUNC_SIZE); 78 - strncpy(entry->file, p, TRACE_FILE_SIZE); 79 - entry->func[TRACE_FUNC_SIZE] = 0; 80 - entry->file[TRACE_FILE_SIZE] = 0; 77 + strscpy(entry->func, f->data.func); 78 + strscpy(entry->file, p); 81 79 entry->constant = f->constant; 82 80 entry->line = f->data.line; 83 81 entry->correct = val == expect;