All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kallsyms: Fix segfault in prefix_underscores_count().
@ 2009-09-16  5:08 Paul Mundt
  2009-09-16  6:28 ` Li Zefan
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Mundt @ 2009-09-16  5:08 UTC (permalink / raw)
  To: Lai Jiangshan, Sam Ravnborg, Andrew Morton, Ingo Molnar
  Cc: linux-kernel, linux-kbuild

[ I'm not sure who exactly this should go to, so I've attempted to get all of
  the interested parties in the Cc. ]

This is a re-send of a problem that I reported on August 7th, both Sam and Lai
have been unresponsive, so hopefully someone else can take a look at this.

Commit b478b782e110fdb4135caa3062b6d687e989d994 "kallsyms, tracing:
output more proper symbol name" introduces a "bugfix" that introduces
a segfault in kallsyms in my configurations.

The cause is the introduction of prefix_underscores_count() which
attempts to count underscores, even in symbols that do not have them.
As a result, it just uselessly runs past the end of the buffer until it
crashes:

  CC      init/version.o
  LD      init/built-in.o
  LD      .tmp_vmlinux1
  KSYM    .tmp_kallsyms1.S
/bin/sh: line 1: 16934 Done                    sh-linux-gnu-nm -n .tmp_vmlinux1
     16935 Segmentation fault      | scripts/kallsyms > .tmp_kallsyms1.S
make: *** [.tmp_kallsyms1.S] Error 139

This adds a strlen iterator that bails out if nothing is found in the
string, which fixes up the observed segfaults.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>

---

I've uploaded a sample problematic symbol list to:

	http://userweb.kernel.org/~lethal/symbol-list.gz

that one can pipe in to scripts/kallsyms to reproduce the fault, incase someone
wants to make a better fix. I'm at a loss as to why no one else has reported
this yet.

 scripts/kallsyms.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 64343cc..f1d44b2 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -584,9 +538,14 @@ static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
 static int prefix_underscores_count(const char *str)
 {
 	const char *tail = str;
+	size_t len = strlen(str);
+
+	while (*tail != '_') {
+		if (!len--)
+			return 0;
 
-	while (*tail != '_')
 		tail++;
+	}
 
 	return tail - str;
 }

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

* Re: [PATCH] kallsyms: Fix segfault in prefix_underscores_count().
  2009-09-16  5:08 [PATCH] kallsyms: Fix segfault in prefix_underscores_count() Paul Mundt
@ 2009-09-16  6:28 ` Li Zefan
  2009-09-16  6:48   ` Paul Mundt
  0 siblings, 1 reply; 5+ messages in thread
From: Li Zefan @ 2009-09-16  6:28 UTC (permalink / raw)
  To: Paul Mundt
  Cc: Lai Jiangshan, Sam Ravnborg, Andrew Morton, Ingo Molnar,
	linux-kernel, linux-kbuild, Paulo Marques

CC: Paulo Marques <pmarques@grupopie.com> (who reviewed that patch)

Paul Mundt wrote:
> [ I'm not sure who exactly this should go to, so I've attempted to get all of
>   the interested parties in the Cc. ]
> 
> This is a re-send of a problem that I reported on August 7th, both Sam and Lai
> have been unresponsive, so hopefully someone else can take a look at this.
>

Lai is off office and won't be back in 2 weeks, so I'm afraid
he won't be responsive..

> Commit b478b782e110fdb4135caa3062b6d687e989d994 "kallsyms, tracing:
> output more proper symbol name" introduces a "bugfix" that introduces
> a segfault in kallsyms in my configurations.
> 
> The cause is the introduction of prefix_underscores_count() which
> attempts to count underscores, even in symbols that do not have them.
> As a result, it just uselessly runs past the end of the buffer until it
> crashes:
> 

But the fix looks obviously correct, as long as @str is guaranteed
to be NULL-terminated.

...
> @@ -584,9 +538,14 @@ static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
>  static int prefix_underscores_count(const char *str)
>  {
>  	const char *tail = str;
> +	size_t len = strlen(str);
> +
> +	while (*tail != '_') {
> +		if (!len--)
> +			return 0;
>  
> -	while (*tail != '_')
>  		tail++;
> +	}

Can be simplified as:

	while (*tail != '\0' && *tail != '_')
		tail++;

But..as the name "prefix_underscores_count" suggests, shouldn't
it be:
	while (*tail == '_')
		tail++;
??

>  
>  	return tail - str;
>  }

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

* Re: [PATCH] kallsyms: Fix segfault in prefix_underscores_count().
  2009-09-16  6:28 ` Li Zefan
@ 2009-09-16  6:48   ` Paul Mundt
  2009-09-16  7:06     ` Li Zefan
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Mundt @ 2009-09-16  6:48 UTC (permalink / raw)
  To: Li Zefan
  Cc: Lai Jiangshan, Sam Ravnborg, Andrew Morton, Ingo Molnar,
	linux-kernel, linux-kbuild, Paulo Marques

On Wed, Sep 16, 2009 at 02:28:54PM +0800, Li Zefan wrote:
> Paul Mundt wrote:
> > Commit b478b782e110fdb4135caa3062b6d687e989d994 "kallsyms, tracing:
> > output more proper symbol name" introduces a "bugfix" that introduces
> > a segfault in kallsyms in my configurations.
> > 
> > The cause is the introduction of prefix_underscores_count() which
> > attempts to count underscores, even in symbols that do not have them.
> > As a result, it just uselessly runs past the end of the buffer until it
> > crashes:
> > 
> 
> But the fix looks obviously correct, as long as @str is guaranteed
> to be NULL-terminated.
> 
> ...
> > @@ -584,9 +538,14 @@ static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
> >  static int prefix_underscores_count(const char *str)
> >  {
> >  	const char *tail = str;
> > +	size_t len = strlen(str);
> > +
> > +	while (*tail != '_') {
> > +		if (!len--)
> > +			return 0;
> >  
> > -	while (*tail != '_')
> >  		tail++;
> > +	}
> 
> Can be simplified as:
> 
> 	while (*tail != '\0' && *tail != '_')
> 		tail++;
> 
> But..as the name "prefix_underscores_count" suggests, shouldn't
> it be:
> 	while (*tail == '_')
> 		tail++;
> ??
> 
Yes, that was what I did initially as well, but the behaviour is not
exactly the same, and I wanted an explanation from Lai if there were some
other intentions for the code. In any event, simplifying it still manages
to do the right thing, so I'm fine with that.

------------------------
Subject: [PATCH] kallsyms: Fix segfault in prefix_underscores_count().

Commit b478b782e110fdb4135caa3062b6d687e989d994 "kallsyms, tracing:
output more proper symbol name" introduces a "bugfix" that introduces
a segfault in kallsyms in my configurations.

The cause is the introduction of prefix_underscores_count() which
attempts to count underscores, even in symbols that do not have them.
As a result, it just uselessly runs past the end of the buffer until it
crashes:

  CC      init/version.o
  LD      init/built-in.o
  LD      .tmp_vmlinux1
  KSYM    .tmp_kallsyms1.S
/bin/sh: line 1: 16934 Done                    sh-linux-gnu-nm -n .tmp_vmlinux1
     16935 Segmentation fault      | scripts/kallsyms > .tmp_kallsyms1.S
make: *** [.tmp_kallsyms1.S] Error 139

This simplifies the logic and just does a straightforward count.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>

---

 scripts/kallsyms.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 64343cc..86c3896 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -585,7 +585,7 @@ static int prefix_underscores_count(const char *str)
 {
 	const char *tail = str;
 
-	while (*tail != '_')
+	while (*tail == '_')
 		tail++;
 
 	return tail - str;

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

* Re: [PATCH] kallsyms: Fix segfault in prefix_underscores_count().
  2009-09-16  6:48   ` Paul Mundt
@ 2009-09-16  7:06     ` Li Zefan
  0 siblings, 0 replies; 5+ messages in thread
From: Li Zefan @ 2009-09-16  7:06 UTC (permalink / raw)
  To: Paul Mundt, Andrew Morton
  Cc: Lai Jiangshan, Sam Ravnborg, Ingo Molnar, linux-kernel,
	linux-kbuild, Paulo Marques

>> But..as the name "prefix_underscores_count" suggests, shouldn't
>> it be:
>> 	while (*tail == '_')
>> 		tail++;
>> ??
>>
> Yes, that was what I did initially as well, but the behaviour is not
> exactly the same, and I wanted an explanation from Lai if there were some
> other intentions for the code. In any event, simplifying it still manages
> to do the right thing, so I'm fine with that.
> 

I know what happened.

Lai sent this patch:
	http://lkml.org/lkml/2009/3/13/72

And he himself found the bug, and fixed it and resent it:
	http://lkml.org/lkml/2009/3/13/156

But Andrew mistakenly picked up the former one.

> ------------------------
> Subject: [PATCH] kallsyms: Fix segfault in prefix_underscores_count().
> 
> Commit b478b782e110fdb4135caa3062b6d687e989d994 "kallsyms, tracing:
> output more proper symbol name" introduces a "bugfix" that introduces
> a segfault in kallsyms in my configurations.
> 
> The cause is the introduction of prefix_underscores_count() which
> attempts to count underscores, even in symbols that do not have them.
> As a result, it just uselessly runs past the end of the buffer until it
> crashes:
> 
>   CC      init/version.o
>   LD      init/built-in.o
>   LD      .tmp_vmlinux1
>   KSYM    .tmp_kallsyms1.S
> /bin/sh: line 1: 16934 Done                    sh-linux-gnu-nm -n .tmp_vmlinux1
>      16935 Segmentation fault      | scripts/kallsyms > .tmp_kallsyms1.S
> make: *** [.tmp_kallsyms1.S] Error 139
> 
> This simplifies the logic and just does a straightforward count.
> 
> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
> 

Reviewed-by: Li Zefan <lizf@cn.fujitsu.com>

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

* [PATCH] kallsyms: Fix segfault in prefix_underscores_count().
@ 2009-08-07  9:22 Paul Mundt
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Mundt @ 2009-08-07  9:22 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Lai Jiangshan, linux-next

As a good indicator that Impact lines are completely useless, commit 
b478b782e110fdb4135caa3062b6d687e989d994 "kallsyms, tracing: output more
proper symbol name" introduces a "bugfix" that introduced segfaults on
several of my defconfigs:

	http://kisskb.ellerman.id.au/kisskb/buildresult/1017849/
	http://kisskb.ellerman.id.au/kisskb/buildresult/1017351/
	http://kisskb.ellerman.id.au/kisskb/buildresult/1017354/

The cause is the introduction of prefix_underscores_count() which
attempts to count underscores.. even in symbols that do not have them.
As a result, it just uselessly runs past the end of the buffer until it
crashes.

This adds a strlen iterator that bails out if nothing is found in the
string, which fixes up the observed segfaults.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Sam Ravnborg <sam@ravnborg.org>

---

I've uploaded the symbol list to:

	http://userweb.kernel.org/~lethal/symbol-list.gz

that one can pipe in to scripts/kallsyms to reproduce the fault in -next,
incase someone wants to come up with a better fix :-)

 scripts/kallsyms.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 64343cc..f1d44b2 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -584,9 +538,14 @@ static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
 static int prefix_underscores_count(const char *str)
 {
 	const char *tail = str;
+	size_t len = strlen(str);
+
+	while (*tail != '_') {
+		if (!len--)
+			return 0;
 
-	while (*tail != '_')
 		tail++;
+	}
 
 	return tail - str;
 }

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

end of thread, other threads:[~2009-09-16  7:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-16  5:08 [PATCH] kallsyms: Fix segfault in prefix_underscores_count() Paul Mundt
2009-09-16  6:28 ` Li Zefan
2009-09-16  6:48   ` Paul Mundt
2009-09-16  7:06     ` Li Zefan
  -- strict thread matches above, loose matches on Subject: below --
2009-08-07  9:22 Paul Mundt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.