perf dwarf: Fix potential array out of bounds access

There is a problem in the dwarf-regs.c files for sh, sparc and x86 where
it is possible to make an out-of-bounds array access when searching for
register names.

This patch fixes it by replacing '<=' to '<', so when register (number
== XXX_MAX_REGS), get_arch_regstr() will return NULL.

Signed-off-by: Wang Nan <[email protected]>
Reviewed-by: Matt Fleming <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Acked-by: Masami Hiramatsu <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Zefan Li <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
This commit is contained in:
Wang Nan 2015-09-01 03:29:44 +00:00 • committed by Arnaldo Carvalho de Melo
commit 3b27d13940
3 changed files with 3 additions and 3 deletions

View file

@ -51,5 +51,5 @@ const char *sh_regs_table[SH_MAX_REGS] = {
/* Return architecture dependent register string (for kprobe-tracer) */
const char *get_arch_regstr(unsigned int n)
{
return (n <= SH_MAX_REGS) ? sh_regs_table[n] : NULL;
return (n < SH_MAX_REGS) ? sh_regs_table[n] : NULL;
}

View file

@ -39,5 +39,5 @@ const char *sparc_regs_table[SPARC_MAX_REGS] = {
*/
const char *get_arch_regstr(unsigned int n)
{
return (n <= SPARC_MAX_REGS) ? sparc_regs_table[n] : NULL;
return (n < SPARC_MAX_REGS) ? sparc_regs_table[n] : NULL;
}

View file

@ -71,5 +71,5 @@ const char *x86_64_regs_table[X86_64_MAX_REGS] = {
/* Return architecture dependent register string (for kprobe-tracer) */
const char *get_arch_regstr(unsigned int n)
{
return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
return (n < ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
}