Skip to content

Commit 3345793

Browse files
azeemshaikh38kees
authored andcommitted
kallsyms: Replace all non-returning 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]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). No return values were used, so direct replacement is safe. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP#89 Signed-off-by: Azeem Shaikh <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8704109 commit 3345793

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

kernel/kallsyms.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ static int get_ksymbol_bpf(struct kallsym_iter *iter)
716716
{
717717
int ret;
718718

719-
strlcpy(iter->module_name, "bpf", MODULE_NAME_LEN);
719+
strscpy(iter->module_name, "bpf", MODULE_NAME_LEN);
720720
iter->exported = 0;
721721
ret = bpf_get_kallsym(iter->pos - iter->pos_ftrace_mod_end,
722722
&iter->value, &iter->type,
@@ -736,7 +736,7 @@ static int get_ksymbol_bpf(struct kallsym_iter *iter)
736736
*/
737737
static int get_ksymbol_kprobe(struct kallsym_iter *iter)
738738
{
739-
strlcpy(iter->module_name, "__builtin__kprobes", MODULE_NAME_LEN);
739+
strscpy(iter->module_name, "__builtin__kprobes", MODULE_NAME_LEN);
740740
iter->exported = 0;
741741
return kprobe_get_kallsym(iter->pos - iter->pos_bpf_end,
742742
&iter->value, &iter->type,

kernel/params.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ static void __init param_sysfs_builtin(void)
847847
name_len = 0;
848848
} else {
849849
name_len = dot - kp->name + 1;
850-
strlcpy(modname, kp->name, name_len);
850+
strscpy(modname, kp->name, name_len);
851851
}
852852
kernel_add_sysfs_param(modname, kp, name_len);
853853
}

0 commit comments

Comments
 (0)