ftrace: use strscpy to replace strlcpy
PATCH 1/1 ftrace: use strscpy to replace strlcpy
The strlcpy should not be used because it doesn't limit the source length. Preferred is strscpy.
--- kernel/trace/ftrace.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
kernel/trace/ftrace.c +9 -9
@@ -5902,7 +5902,7 @@ bool ftrace_filter_param __initdata;static int __init set_ftrace_notrace (char *str) { ftrace_filter_param = true; -strlcpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_notrace=" , set_ftrace_notrace);
@@ -5910,7 +5910,7 @@ __setup("ftrace_notrace=", set_ftrace_notrace);static int __init set_ftrace_filter (char *str) { ftrace_filter_param = true; -strlcpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_filter=" , set_ftrace_filter);
@@ -5922,14 +5922,14 @@ static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);static int __init set_graph_function (char *str) { -strlcpy (ftrace_graph_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_graph_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_filter=" , set_graph_function);static int __init set_graph_notrace_function (char *str) { -strlcpy (ftrace_graph_notrace_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_graph_notrace_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_notrace=" , set_graph_notrace_function);
@@ -6714,8 +6714,8 @@ static int ftrace_get_trampoline_kallsym(unsigned int symnum,continue ; *value = op->trampoline; *type ='t' ; -strlcpy (name,FTRACE_TRAMPOLINE_SYM ,KSYM_NAME_LEN ); -strlcpy (module_name,FTRACE_TRAMPOLINE_MOD ,MODULE_NAME_LEN ); +strscpy (name,FTRACE_TRAMPOLINE_SYM ,KSYM_NAME_LEN ); +strscpy (module_name,FTRACE_TRAMPOLINE_MOD ,MODULE_NAME_LEN ); *exported =0 ;return 0 ; }
@@ -7046,7 +7046,7 @@ ftrace_func_address_lookup(struct ftrace_mod_map *mod_map,if (off) *off = addr - found_func->ip;if (sym) -strlcpy (sym, found_func->name,KSYM_NAME_LEN ); +strscpy (sym, found_func->name,KSYM_NAME_LEN );return found_func->name; }
@@ -7100,8 +7100,8 @@ int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value, *value = mod_func->ip; *type ='T' ; -strlcpy (name, mod_func->name,KSYM_NAME_LEN ); -strlcpy (module_name, mod_map->mod->name,MODULE_NAME_LEN ); +strscpy (name, mod_func->name,KSYM_NAME_LEN ); +strscpy (module_name, mod_map->mod->name,MODULE_NAME_LEN ); *exported =1 ;preempt_enable ();return 0 ;
Signature · 1 line
2.25.1
Quoted 36 lines · On Fri, 1 Jul 2022 19:09:15 +0800 (GMT+08:00) "XueBing Chen"…
The strlcpy should not be used because it doesn't limit the source length. Preferred is strscpy.
Signed-off-by XueBing Chen <[email protected]>--- kernel/trace/ftrace.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)kernel/trace/ftrace.c +3
-3@@ -5902,7 +5902,7 @@ bool ftrace_filter_param __initdata;static int __init set_ftrace_notrace (char *str) { ftrace_filter_param = true; -strlcpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_notrace=" , set_ftrace_notrace);@@ -5910,7 +5910,7 @@ __setup("ftrace_notrace=", set_ftrace_notrace);static int __init set_ftrace_filter (char *str) { ftrace_filter_param = true; -strlcpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_filter=" , set_ftrace_filter);@@ -5922,14 +5922,14 @@ static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);static int __init set_graph_function (char *str) { -strlcpy (ftrace_graph_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_graph_buf, str,FTRACE_FILTER_SIZE );
kernel/trace/ftrace.c static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer); · line 5934
Quoted 10 lines
kernel/trace/ftrace.c +1
-1return 1 ; }__setup ("ftrace_graph_filter=" , set_graph_function);static int __init set_graph_notrace_function (char *str) { -strlcpy (ftrace_graph_notrace_buf, str,FTRACE_FILTER_SIZE ); +strscpy (ftrace_graph_notrace_buf, str,FTRACE_FILTER_SIZE );return 1 ; }
No need for strscpy() in init functions that simply read the kernel command line.
kernel/trace/ftrace.c static int ftrace_get_trampoline_kallsym(unsigned int symnum, · line 6718
Quoted 9 lines
kernel/trace/ftrace.c +2
-2__setup ("ftrace_graph_notrace=" , set_graph_notrace_function);@@ -6714,8 +6714,8 @@ static int ftrace_get_trampoline_kallsym(unsigned int symnum,continue ; *value = op->trampoline; *type ='t' ; -strlcpy (name,FTRACE_TRAMPOLINE_SYM ,KSYM_NAME_LEN ); -strlcpy (module_name,FTRACE_TRAMPOLINE_MOD ,MODULE_NAME_LEN ); +strscpy (name,FTRACE_TRAMPOLINE_SYM ,KSYM_NAME_LEN ); +strscpy (module_name,FTRACE_TRAMPOLINE_MOD ,MODULE_NAME_LEN );
The source is a macro, no need for strscpy() here.
kernel/trace/ftrace.c ftrace_func_address_lookup(struct ftrace_mod_map *mod_map, · line 7049
Quoted 9 lines
kernel/trace/ftrace.c +1
-1*exported =0 ;return 0 ; }@@ -7046,7 +7046,7 @@ ftrace_func_address_lookup(struct ftrace_mod_map *mod_map,if (off) *off = addr - found_func->ip;if (sym) -strlcpy (sym, found_func->name,KSYM_NAME_LEN ); +strscpy (sym, found_func->name,KSYM_NAME_LEN );
The name can not be bigger than KSYM_NAME_LEN, no need for strscpy() here.
kernel/trace/ftrace.c int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value, · line 7104
Quoted 11 lines
kernel/trace/ftrace.c +2
-2return found_func->name; }@@ -7100,8 +7100,8 @@ int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value, *value = mod_func->ip; *type ='T' ; -strlcpy (name, mod_func->name,KSYM_NAME_LEN ); -strlcpy (module_name, mod_map->mod->name,MODULE_NAME_LEN ); +strscpy (name, mod_func->name,KSYM_NAME_LEN ); +strscpy (module_name, mod_map->mod->name,MODULE_NAME_LEN );
Same for this.
I don't see how converting any of these to strscpy() is helpful.
NAK.
-- Steve
Quoted 3 lines
kernel/trace/ftrace.c +0
-0*exported =1 ;preempt_enable ();return 0 ;