Re: [for-next][PATCH 03/11] kdb: Replace the use of simple_strto with safer kstrto in kdb_main

Doug Anderson
2024-11-01T14:21:26Z

Hi,

On Fri, Nov 1, 2024 at 3:36 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> From: Yuran Pereira <yuran.pereira@hotmail.com>
>
> The simple_str* family of functions perform no error checking in
> scenarios where the input value overflows the intended output variable.
> This results in these functions successfully returning even when the
> output does not match the input string.
>
> 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_strto* series of functions
> with their safer kstrto* alternatives.
>
> Side effects of this patch:
> - Every string to long or long long conversion using kstrto* is now
> checked for failure.
> - kstrto* errors are handled with appropriate `KDB_BADINT` wherever
> applicable.
> - A good side effect is that we end up saving a few lines of code
> since unlike in simple_strto* functions, kstrto functions do not
> need an additional "end pointer" variable, and the return values
> of the latter can be directly checked in an "if" statement without
> the need to define additional `ret` or `err` variables.
> This, of course, results in cleaner, yet still easy to understand
> code.
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull
>
> Link: https://lore.kernel.org/20241028191916.GA918454@lichtman.org
> Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
> [nir: addressed review comments by fixing styling, invalid conversion and a missing error return]
> Signed-off-by: Nir Lichtman <nir@lichtman.org>
> Reviewed-by: Douglas Anderson <dianders@chromium.org>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> kernel/debug/kdb/kdb_main.c | 69 +++++++++++--------------------------
> 1 file changed, 21 insertions(+), 48 deletions(-)

FWIW, I personally have no objection to this patch and patch #3/3 in
Nir's series (#5/11 in your email thread) going through the ftrace
tree, I'm not actually the maintainer of kdb/kgdb. I'm a reviewer and
I try my best to help, but officially you should probably have Daniel
Thompson's Ack for them. ...or at least make sure he's CCed here
saying that you've picked them up.

I've added him to the conversation here.

-Doug