Skip to content

Commit d0c2d66

Browse files
azeemshaikh38kees
authored andcommitted
ftrace: 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]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dd06e72 commit d0c2d66

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

kernel/trace/ftrace.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5743,15 +5743,15 @@ bool ftrace_filter_param __initdata;
57435743
static int __init set_ftrace_notrace(char *str)
57445744
{
57455745
ftrace_filter_param = true;
5746-
strlcpy(ftrace_notrace_buf, str, FTRACE_FILTER_SIZE);
5746+
strscpy(ftrace_notrace_buf, str, FTRACE_FILTER_SIZE);
57475747
return 1;
57485748
}
57495749
__setup("ftrace_notrace=", set_ftrace_notrace);
57505750

57515751
static int __init set_ftrace_filter(char *str)
57525752
{
57535753
ftrace_filter_param = true;
5754-
strlcpy(ftrace_filter_buf, str, FTRACE_FILTER_SIZE);
5754+
strscpy(ftrace_filter_buf, str, FTRACE_FILTER_SIZE);
57555755
return 1;
57565756
}
57575757
__setup("ftrace_filter=", set_ftrace_filter);
@@ -5763,14 +5763,14 @@ static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);
57635763

57645764
static int __init set_graph_function(char *str)
57655765
{
5766-
strlcpy(ftrace_graph_buf, str, FTRACE_FILTER_SIZE);
5766+
strscpy(ftrace_graph_buf, str, FTRACE_FILTER_SIZE);
57675767
return 1;
57685768
}
57695769
__setup("ftrace_graph_filter=", set_graph_function);
57705770

57715771
static int __init set_graph_notrace_function(char *str)
57725772
{
5773-
strlcpy(ftrace_graph_notrace_buf, str, FTRACE_FILTER_SIZE);
5773+
strscpy(ftrace_graph_notrace_buf, str, FTRACE_FILTER_SIZE);
57745774
return 1;
57755775
}
57765776
__setup("ftrace_graph_notrace=", set_graph_notrace_function);
@@ -6569,8 +6569,8 @@ static int ftrace_get_trampoline_kallsym(unsigned int symnum,
65696569
continue;
65706570
*value = op->trampoline;
65716571
*type = 't';
6572-
strlcpy(name, FTRACE_TRAMPOLINE_SYM, KSYM_NAME_LEN);
6573-
strlcpy(module_name, FTRACE_TRAMPOLINE_MOD, MODULE_NAME_LEN);
6572+
strscpy(name, FTRACE_TRAMPOLINE_SYM, KSYM_NAME_LEN);
6573+
strscpy(module_name, FTRACE_TRAMPOLINE_MOD, MODULE_NAME_LEN);
65746574
*exported = 0;
65756575
return 0;
65766576
}
@@ -6933,7 +6933,7 @@ ftrace_func_address_lookup(struct ftrace_mod_map *mod_map,
69336933
if (off)
69346934
*off = addr - found_func->ip;
69356935
if (sym)
6936-
strlcpy(sym, found_func->name, KSYM_NAME_LEN);
6936+
strscpy(sym, found_func->name, KSYM_NAME_LEN);
69376937

69386938
return found_func->name;
69396939
}
@@ -6987,8 +6987,8 @@ int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
69876987

69886988
*value = mod_func->ip;
69896989
*type = 'T';
6990-
strlcpy(name, mod_func->name, KSYM_NAME_LEN);
6991-
strlcpy(module_name, mod_map->mod->name, MODULE_NAME_LEN);
6990+
strscpy(name, mod_func->name, KSYM_NAME_LEN);
6991+
strscpy(module_name, mod_map->mod->name, MODULE_NAME_LEN);
69926992
*exported = 1;
69936993
preempt_enable();
69946994
return 0;

0 commit comments

Comments
 (0)