[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAD=FV=X0TYPpLow=GGAcNGz5_joKG7-d=-DorDcxh9ppgNdQaA@mail.gmail.com>
Date: Mon, 28 Oct 2024 14:09:44 -0700
From: Doug Anderson <dianders@...omium.org>
To: Nir Lichtman <nir@...htman.org>
Cc: kgdb-bugreport@...ts.sourceforge.net, linux-trace-kernel@...r.kernel.org,
yuran.pereira@...mail.com, jason.wessel@...driver.com,
daniel.thompson@...aro.org, rostedt@...dmis.org, mhiramat@...nel.org,
linux-kernel@...r.kernel.org, linux-kernel-mentees@...ts.linuxfoundation.org
Subject: Re: [PATCH v4 1/3] kdb: Replace the use of simple_strto with safer
kstrto in kdb_main
Hi,
On Mon, Oct 28, 2024 at 12:19 PM Nir Lichtman <nir@...htman.org> wrote:
>
> From: Yuran Pereira <yuran.pereira@...mail.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
>
> Signed-off-by: Yuran Pereira <yuran.pereira@...mail.com>
> [nir: addressed review comments by fixing styling, invalid conversion and a missing error return]
> Signed-off-by: Nir Lichtman <nir@...htman.org>
> ---
> kernel/debug/kdb/kdb_main.c | 69 +++++++++++--------------------------
> 1 file changed, 21 insertions(+), 48 deletions(-)
Reviewed-by: Douglas Anderson <dianders@...omium.org>
Powered by blists - more mailing lists