Skip to content

Commit 8ca25e0

Browse files
azeemshaikh38kees
authored andcommitted
NFS: Prefer strscpy over strlcpy calls
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]. Check for strscpy()'s return value of -E2BIG on truncate for safe replacement with strlcpy(). This is part of a tree-wide cleanup to remove the strlcpy() function entirely from the kernel [2]. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP#89 Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230512155749.1356958-1-azeemshaikh38@gmail.com
1 parent 30ad062 commit 8ca25e0

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/nfs/nfsroot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ __setup("nfsroot=", nfs_root_setup);
164164
static int __init root_nfs_copy(char *dest, const char *src,
165165
const size_t destlen)
166166
{
167-
if (strlcpy(dest, src, destlen) > destlen)
167+
if (strscpy(dest, src, destlen) == -E2BIG)
168168
return -1;
169169
return 0;
170170
}

0 commit comments

Comments
 (0)