scripts/kallsyms: fix memory corruption caused by write over-run
PATCH 1/1 scripts/kallsyms: fix memory corruption caused by write over-run
scripts/kallsyms crashes because memcpy() writes one more byte than allocated.
---
scripts/kallsyms.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/kallsyms.c +2 -2
@@ -210,7 +210,7 @@ static struct sym_entry *read_symbol(FILE *in) len =strlen (name) +1 ; - sym =malloc (sizeof (*sym) + len); + sym =malloc (sizeof (*sym) + len +1 );if (!sym) {fprintf (stderr,"kallsyms failure: " "unable to allocate required amount of memory\n" );
@@ -219,7 +219,7 @@ static struct sym_entry *read_symbol(FILE *in) sym->addr = addr; sym->len = len; sym->sym[0 ] = type; -memcpy (sym_name (sym), name, len); +strcpy (sym_name (sym), name); sym->percpu_absolute =0 ;return sym;
Signature · 1 line
2.17.1
Quoted 7 lines · Masahiro Yamada
scripts/kallsymscrashes becausememcpy()writes one more byte than allocated.Fixes 8d60526999aa ("scripts/kallsyms: change table to store (strcut sym_entry *)")Reported-by youling257 <[email protected]>Reported-by Pavel Machek <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>
Thanks!
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Looks like len is already +1, maybe it shouldn't be?
scripts/kallsyms.c static struct sym_entry *read_symbol(FILE *in) · line 213
Quoted 4 lines
len = strlen(name) + 1;scripts/kallsyms.c +1
-1- sym =malloc (sizeof (*sym) + len); + sym =malloc (sizeof (*sym) + len +1 );
Maybe strlcpy or if len wasn't incremented?
Quoted 4 lines
scripts/kallsyms.c +1
-1-memcpy (sym_name (sym), name, len); +strcpy (sym_name (sym), name);
Hi.
Quoted 2 lines · Justin Capella
Looks like len is already +1, maybe it shouldn't be?
This increment is for storing one more character, 'type'.
sym->sym[0] = type;
Quoted 4 lines
scripts/kallsyms.c static struct sym_entry *read_symbol(FILE *in) · line 213
Quoted 4 lines
len = strlen(name) + 1;scripts/kallsyms.c +1
-1- sym =malloc (sizeof (*sym) + len); + sym =malloc (sizeof (*sym) + len +1 );
This increment is for the '\0' termination.
So, malloc() needs to allocate:sizeof(*sym) + strlen(name) + 2.
Quoted 8 lines
Maybe strlcpy or if len wasn't incremented?
Quoted 4 lines
scripts/kallsyms.c +1
-1-memcpy (sym_name (sym), name, len); +strcpy (sym_name (sym), name);
Signature · 2 lines
Best Regards Masahiro Yamada
Masahiro Yamada
AppliedQuoted 9 lines · Masahiro Yamada
scripts/kallsymscrashes becausememcpy()writes one more byte than allocated.Fixes 8d60526999aa ("scripts/kallsyms: change table to store (strcut sym_entry *)")Reported-by youling257 <[email protected]>Reported-by Pavel Machek <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>---
Applied.
I will send a pull request shortly
because many people are tripping over this bug.
Quoted 28 lines
scripts/kallsyms.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)scripts/kallsyms.c +2
-3@@ -210,7 +210,7 @@ static struct sym_entry *read_symbol(FILE *in) len =strlen (name) +1 ; - sym =malloc (sizeof (*sym) + len); + sym =malloc (sizeof (*sym) + len +1 );if (!sym) {fprintf (stderr,"kallsyms failure: " "unable to allocate required amount of memory\n" );@@ -219,7 +219,7 @@ static struct sym_entry *read_symbol(FILE *in) sym->addr = addr; sym->len = len; sym->sym[0 ] = type; -memcpy (sym_name (sym), name, len); +strcpy (sym_name (sym), name); sym->percpu_absolute =0 ;return sym; --2.17.1
Signature · 2 lines
Best Regards Masahiro Yamada