Skip to content

Commit 0c10cc2

Browse files
yuranpereiraDaniel Thompson
authored andcommitted
trace: kdb: Replace simple_strtoul with kstrtoul in kdb_ftdump
The function simple_strtoul performs no error checking in scenarios where the input value overflows the intended output variable. This results in this function successfully returning, even when the output does not match the input string (aka the function returns successfully even when the result is wrong). Or as it was mentioned [1], "...simple_strtol(), simple_strtoll(), simple_strtoul(), and simple_strtoull() functions explicitly ignore overflows, which may lead to unexpected results in callers." Hence, the use of those functions is discouraged. This patch replaces all uses of the simple_strtoul with the safer alternatives kstrtoint and kstrtol. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull Signed-off-by: Yuran Pereira <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Acked-by: Steven Rostedt (Google) <[email protected]> [nir: style fixes] Signed-off-by: Nir Lichtman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Thompson <[email protected]>
1 parent 120fb87 commit 0c10cc2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

kernel/trace/trace_kdb.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,19 @@ static int kdb_ftdump(int argc, const char **argv)
9696
{
9797
int skip_entries = 0;
9898
long cpu_file;
99-
char *cp;
99+
int err;
100100
int cnt;
101101
int cpu;
102102

103103
if (argc > 2)
104104
return KDB_ARGCOUNT;
105105

106-
if (argc) {
107-
skip_entries = simple_strtol(argv[1], &cp, 0);
108-
if (*cp)
109-
skip_entries = 0;
110-
}
106+
if (argc && kstrtoint(argv[1], 0, &skip_entries))
107+
return KDB_BADINT;
111108

112109
if (argc == 2) {
113-
cpu_file = simple_strtol(argv[2], &cp, 0);
114-
if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 ||
110+
err = kstrtol(argv[2], 0, &cpu_file);
111+
if (err || cpu_file >= NR_CPUS || cpu_file < 0 ||
115112
!cpu_online(cpu_file))
116113
return KDB_BADINT;
117114
} else {

0 commit comments

Comments
 (0)