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 <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: [email protected] Acked-by: "Masami Hiramatsu (Google)" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent b5e3f86 commit 8a3750e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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)