Skip to content

Commit 8a3750e

Browse files
committed
tracing/uprobe: Replace strlcpy() with strscpy()
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated[1]. Additionally, it returns the size of the source string, not the resulting size of the destination string. In an effort to remove strlcpy() completely[2], replace strlcpy() here with strscpy(). The negative return value is already handled by this code so no new handling is needed here. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [1] Link: KSPP#89 [2] Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: linux-trace-kernel@vger.kernel.org Acked-by: "Masami Hiramatsu (Google)" <mhiramat@kernel.org> Link: https://lore.kernel.org/r/20231130205607.work.463-kees@kernel.org Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent b5e3f86 commit 8a3750e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

kernel/trace/trace_uprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fetch_store_string(unsigned long addr, void *dest, void *base)
151151
return -ENOMEM;
152152

153153
if (addr == FETCH_TOKEN_COMM)
154-
ret = strlcpy(dst, current->comm, maxlen);
154+
ret = strscpy(dst, current->comm, maxlen);
155155
else
156156
ret = strncpy_from_user(dst, src, maxlen);
157157
if (ret >= 0) {

0 commit comments

Comments
 (0)