mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KDB: Fix incorrect treatment of numbers in the CLI
@ 2024-10-19 19:57 Nir Lichtman
  2024-10-19 20:42 ` [PATCH v2] " Nir Lichtman
  0 siblings, 1 reply; 4+ messages in thread
From: Nir Lichtman @ 2024-10-19 19:57 UTC (permalink / raw)
  To: jason.wessel, daniel.thompson, dianders, kgdb-bugreport, linux-kernel

Problem: In many cases, KDB treats invalid commands as numbers and
instead of printing a usage error, goes ahead and just prints the number
in hex

Example: This can be demonstrated when typing for example "aaazzz", this
confuses KDB into thinking this is the hexadecimal 0xAAA

Solution: Before assuming that the input from the user is a number,
check that it contains only characters that represent numbers.
Also, along the way, transition to using kstrtoul instead of
simple_strtoul (better practice as stated in the definition of the
function)

Signed-off-by: Nir Lichtman <nir@lichtman.org>
---
 kernel/debug/kdb/kdb_main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index f5f7d7fb5936..4efdc4d25a59 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -402,18 +402,18 @@ static void kdb_printenv(void)
  */
 int kdbgetularg(const char *arg, unsigned long *value)
 {
-	char *endp;
 	unsigned long val;
 
-	val = simple_strtoul(arg, &endp, 0);
+	if ((strpbrk(arg, hex_asc) == NULL)
+	 && (strpbrk(arg, hex_asc_upper) == NULL))
+		return KDB_BADINT;
 
-	if (endp == arg) {
+	if (kstrtoul(arg, 0, &val) != 0) {
 		/*
 		 * Also try base 16, for us folks too lazy to type the
 		 * leading 0x...
 		 */
-		val = simple_strtoul(arg, &endp, 16);
-		if (endp == arg)
+		if (kstrtoul(arg, 16, &val) != 0)
 			return KDB_BADINT;
 	}
 
-- 
2.39.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] KDB: Fix incorrect treatment of numbers in the CLI
  2024-10-19 19:57 [PATCH] KDB: Fix incorrect treatment of numbers in the CLI Nir Lichtman
@ 2024-10-19 20:42 ` Nir Lichtman
  2024-10-21 17:14   ` Doug Anderson
  0 siblings, 1 reply; 4+ messages in thread
From: Nir Lichtman @ 2024-10-19 20:42 UTC (permalink / raw)
  To: jason.wessel, daniel.thompson, dianders, kgdb-bugreport, linux-kernel

Problem: In many cases, KDB treats invalid commands as numbers and
instead of printing a usage error, goes ahead and just prints the number
in hex

Example: This can be demonstrated when typing for example "aaazzz", this
confuses KDB into thinking this is the hexadecimal 0xAAA

Solution: Transition to using kstrtoul instead of simple_strtoul.
This function is more strict with what it treats as a number
and thus solves the issue.
(also better practice as stated in the definition of simple_strtoul).

v2: Removed redundant if condition I put in v1

Signed-off-by: Nir Lichtman <nir@lichtman.org>
---
 kernel/debug/kdb/kdb_main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index f5f7d7fb5936..4cbd5cd26821 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -402,18 +402,15 @@ static void kdb_printenv(void)
  */
 int kdbgetularg(const char *arg, unsigned long *value)
 {
-	char *endp;
 	unsigned long val;
 
-	val = simple_strtoul(arg, &endp, 0);
 
-	if (endp == arg) {
+	if (kstrtoul(arg, 0, &val) != 0) {
 		/*
 		 * Also try base 16, for us folks too lazy to type the
 		 * leading 0x...
 		 */
-		val = simple_strtoul(arg, &endp, 16);
-		if (endp == arg)
+		if (kstrtoul(arg, 16, &val) != 0)
 			return KDB_BADINT;
 	}
 
-- 
2.39.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] KDB: Fix incorrect treatment of numbers in the CLI
  2024-10-19 20:42 ` [PATCH v2] " Nir Lichtman
@ 2024-10-21 17:14   ` Doug Anderson
  2024-10-21 19:32     ` Nir Lichtman
  0 siblings, 1 reply; 4+ messages in thread
From: Doug Anderson @ 2024-10-21 17:14 UTC (permalink / raw)
  To: Nir Lichtman
  Cc: jason.wessel, daniel.thompson, kgdb-bugreport, linux-kernel,
	Yuran Pereira

Hi,

On Sat, Oct 19, 2024 at 1:42 PM Nir Lichtman <nir@lichtman.org> wrote:
>
> Problem: In many cases, KDB treats invalid commands as numbers and
> instead of printing a usage error, goes ahead and just prints the number
> in hex
>
> Example: This can be demonstrated when typing for example "aaazzz", this
> confuses KDB into thinking this is the hexadecimal 0xAAA
>
> Solution: Transition to using kstrtoul instead of simple_strtoul.
> This function is more strict with what it treats as a number
> and thus solves the issue.
> (also better practice as stated in the definition of simple_strtoul).
>
> v2: Removed redundant if condition I put in v1
>
> Signed-off-by: Nir Lichtman <nir@lichtman.org>
> ---
>  kernel/debug/kdb/kdb_main.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> index f5f7d7fb5936..4cbd5cd26821 100644
> --- a/kernel/debug/kdb/kdb_main.c
> +++ b/kernel/debug/kdb/kdb_main.c
> @@ -402,18 +402,15 @@ static void kdb_printenv(void)
>   */
>  int kdbgetularg(const char *arg, unsigned long *value)
>  {
> -       char *endp;
>         unsigned long val;
>
> -       val = simple_strtoul(arg, &endp, 0);
>
> -       if (endp == arg) {
> +       if (kstrtoul(arg, 0, &val) != 0) {
>                 /*
>                  * Also try base 16, for us folks too lazy to type the
>                  * leading 0x...
>                  */
> -               val = simple_strtoul(arg, &endp, 16);
> -               if (endp == arg)
> +               if (kstrtoul(arg, 16, &val) != 0)

Instead of just fixing the one case, do you want to just take over the
old patch series that tried to do a more complete job:

https://lore.kernel.org/r/GV1PR10MB6563E0F8DB2D335BD9CFE4D3E8B4A@GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM/

I think in general that series looked good but just had a few nits on
it, but the author (Yuran Pereira) never followed up with a v2. You
could take that series, fix the nits, add your signed-off-by, and post
a v2?

-Doug

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] KDB: Fix incorrect treatment of numbers in the CLI
  2024-10-21 17:14   ` Doug Anderson
@ 2024-10-21 19:32     ` Nir Lichtman
  0 siblings, 0 replies; 4+ messages in thread
From: Nir Lichtman @ 2024-10-21 19:32 UTC (permalink / raw)
  To: Doug Anderson
  Cc: jason.wessel, daniel.thompson, kgdb-bugreport, linux-kernel,
	Yuran Pereira

On Mon, Oct 21, 2024 at 10:14:15AM -0700, Doug Anderson wrote:
> Hi,
> 
> On Sat, Oct 19, 2024 at 1:42 PM Nir Lichtman <nir@lichtman.org> wrote:
> >
> > Problem: In many cases, KDB treats invalid commands as numbers and
> > instead of printing a usage error, goes ahead and just prints the number
> > in hex
> >
> > Example: This can be demonstrated when typing for example "aaazzz", this
> > confuses KDB into thinking this is the hexadecimal 0xAAA
> >
> > Solution: Transition to using kstrtoul instead of simple_strtoul.
> > This function is more strict with what it treats as a number
> > and thus solves the issue.
> > (also better practice as stated in the definition of simple_strtoul).
> >
> > v2: Removed redundant if condition I put in v1
> >
> > Signed-off-by: Nir Lichtman <nir@lichtman.org>
> > ---
> >  kernel/debug/kdb/kdb_main.c | 7 ++-----
> >  1 file changed, 2 insertions(+), 5 deletions(-)
> >
> > diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> > index f5f7d7fb5936..4cbd5cd26821 100644
> > --- a/kernel/debug/kdb/kdb_main.c
> > +++ b/kernel/debug/kdb/kdb_main.c
> > @@ -402,18 +402,15 @@ static void kdb_printenv(void)
> >   */
> >  int kdbgetularg(const char *arg, unsigned long *value)
> >  {
> > -       char *endp;
> >         unsigned long val;
> >
> > -       val = simple_strtoul(arg, &endp, 0);
> >
> > -       if (endp == arg) {
> > +       if (kstrtoul(arg, 0, &val) != 0) {
> >                 /*
> >                  * Also try base 16, for us folks too lazy to type the
> >                  * leading 0x...
> >                  */
> > -               val = simple_strtoul(arg, &endp, 16);
> > -               if (endp == arg)
> > +               if (kstrtoul(arg, 16, &val) != 0)
> 
> Instead of just fixing the one case, do you want to just take over the
> old patch series that tried to do a more complete job:
> 
> https://lore.kernel.org/r/GV1PR10MB6563E0F8DB2D335BD9CFE4D3E8B4A@GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM/
> 
> I think in general that series looked good but just had a few nits on
> it, but the author (Yuran Pereira) never followed up with a v2. You
> could take that series, fix the nits, add your signed-off-by, and post
> a v2?
> 
> -Doug

Interesting, will take a look.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-21 19:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-19 19:57 [PATCH] KDB: Fix incorrect treatment of numbers in the CLI Nir Lichtman
2024-10-19 20:42 ` [PATCH v2] " Nir Lichtman
2024-10-21 17:14   ` Doug Anderson
2024-10-21 19:32     ` Nir Lichtman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®