[PATCH 4.14 073/109] perf annotate: Fix objdump comment parsing for Intel mov dissassembly

2018-03-16 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Thomas Richter 


[ Upstream commit 35a8a148d8c1ee9e5ae18f9565a880490f816f89 ]

The command 'perf annotate' parses the output of objdump and also
investigates the comments produced by objdump. For example the
output of objdump produces (on x86):

23eee:  4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 

and the function mov__parse() is called to investigate the complete
line. Mov__parse() breaks this line into several parts and finally
calls function comment__symbol() to parse the data after the comment
character '#'. Comment__symbol() expects a hexadecimal address followed
by a symbol in '<' and '>' brackets.

However the 2nd parameter given to function comment__symbol()
always points to the comment character '#'. The address parsing
always returns 0 because the character '#' is not a digit and
strtoull() fails without being noticed.

Fix this by advancing the second parameter to function comment__symbol()
by one byte before invocation and add an error check after strtoull()
has been called.

Signed-off-by: Thomas Richter 
Reviewed-by: Hendrik Brueckner 
Acked-by: Ravi Bangoria 
Cc: Heiko Carstens 
Cc: Martin Schwidefsky 
Fixes: 6de783b6f50f ("perf annotate: Resolve symbols using objdump comment")
Link: http://lkml.kernel.org/r/20171128075632.72182-1-tmri...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/perf/util/annotate.c |8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -323,6 +323,8 @@ static int comment__symbol(char *raw, ch
return 0;
 
*addrp = strtoull(comment, , 16);
+   if (endptr == comment)
+   return 0;
name = strchr(endptr, '<');
if (name == NULL)
return -1;
@@ -436,8 +438,8 @@ static int mov__parse(struct arch *arch,
return 0;
 
comment = ltrim(comment);
-   comment__symbol(ops->source.raw, comment, >source.addr, 
>source.name);
-   comment__symbol(ops->target.raw, comment, >target.addr, 
>target.name);
+   comment__symbol(ops->source.raw, comment + 1, >source.addr, 
>source.name);
+   comment__symbol(ops->target.raw, comment + 1, >target.addr, 
>target.name);
 
return 0;
 
@@ -481,7 +483,7 @@ static int dec__parse(struct arch *arch
return 0;
 
comment = ltrim(comment);
-   comment__symbol(ops->target.raw, comment, >target.addr, 
>target.name);
+   comment__symbol(ops->target.raw, comment + 1, >target.addr, 
>target.name);
 
return 0;
 }




[PATCH 4.14 073/109] perf annotate: Fix objdump comment parsing for Intel mov dissassembly

2018-03-16 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Thomas Richter 


[ Upstream commit 35a8a148d8c1ee9e5ae18f9565a880490f816f89 ]

The command 'perf annotate' parses the output of objdump and also
investigates the comments produced by objdump. For example the
output of objdump produces (on x86):

23eee:  4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 

and the function mov__parse() is called to investigate the complete
line. Mov__parse() breaks this line into several parts and finally
calls function comment__symbol() to parse the data after the comment
character '#'. Comment__symbol() expects a hexadecimal address followed
by a symbol in '<' and '>' brackets.

However the 2nd parameter given to function comment__symbol()
always points to the comment character '#'. The address parsing
always returns 0 because the character '#' is not a digit and
strtoull() fails without being noticed.

Fix this by advancing the second parameter to function comment__symbol()
by one byte before invocation and add an error check after strtoull()
has been called.

Signed-off-by: Thomas Richter 
Reviewed-by: Hendrik Brueckner 
Acked-by: Ravi Bangoria 
Cc: Heiko Carstens 
Cc: Martin Schwidefsky 
Fixes: 6de783b6f50f ("perf annotate: Resolve symbols using objdump comment")
Link: http://lkml.kernel.org/r/20171128075632.72182-1-tmri...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/perf/util/annotate.c |8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -323,6 +323,8 @@ static int comment__symbol(char *raw, ch
return 0;
 
*addrp = strtoull(comment, , 16);
+   if (endptr == comment)
+   return 0;
name = strchr(endptr, '<');
if (name == NULL)
return -1;
@@ -436,8 +438,8 @@ static int mov__parse(struct arch *arch,
return 0;
 
comment = ltrim(comment);
-   comment__symbol(ops->source.raw, comment, >source.addr, 
>source.name);
-   comment__symbol(ops->target.raw, comment, >target.addr, 
>target.name);
+   comment__symbol(ops->source.raw, comment + 1, >source.addr, 
>source.name);
+   comment__symbol(ops->target.raw, comment + 1, >target.addr, 
>target.name);
 
return 0;
 
@@ -481,7 +483,7 @@ static int dec__parse(struct arch *arch
return 0;
 
comment = ltrim(comment);
-   comment__symbol(ops->target.raw, comment, >target.addr, 
>target.name);
+   comment__symbol(ops->target.raw, comment + 1, >target.addr, 
>target.name);
 
return 0;
 }