Skip to contentSkip to conversation

kallsyms: Fix segfault in prefix_underscores_count().

PATCH New Paul Mundt 1 participant 1 message Aug 7, 2009 Linux-next tree

lore
Share & tools
lore

Paul Mundt

author
#0 lore raw

PATCH 1/1 kallsyms: Fix segfault in prefix_underscores_count().

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.

Cc Lai Jiangshan <[email protected]>
Cc Sam Ravnborg <[email protected]>

---

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(-)
scripts/kallsyms.c +6 -1
index 64343cc..f1d44b2 100644
@@ -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;
 }