Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2331623imm; Thu, 7 Jun 2018 08:55:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL211lu+ebKzDZ/J18an4FSQqFBieEqhjwgNAhk4d0A7Op7MKaayP9cLd90eLORjdGITeaT X-Received: by 2002:a62:1411:: with SMTP id 17-v6mr2303838pfu.3.1528386947347; Thu, 07 Jun 2018 08:55:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528386947; cv=none; d=google.com; s=arc-20160816; b=Umi3CCflOMQ8l363vhHyY1Bm3tZjo7x6bzNDdd1zXYKTv6I6dhNpwfmPY2H7+v1VnE 6+5tFMRK0n5clXOPauNYOchL3yybkBRmj1QA/mMOKmTcJm0NvbyWcIDnRAkZS+Wmw2vj Ilu2gvBcE43GtZp7GUYvoYRoYlsY+rlHczCkI0zhszjt5ZKiRq2wrFTgSNeuN6gLomyM B8YKrwdmdg46fb2Y99rgDDSHY4slP9BJDBbjsPzywMqX9C713AlGGQ1kt2QCdmy7KcI0 FAuuG4/oYHCSLCwtQFH1Tllpo9xpnCjvrD5lP9kxIrvg5eS/hNGmPYsDETAYPve2N4kz PLfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=l6gTaf6Re81N6fYFYo72gQpGP2ex2NcclEb6zqKt83o=; b=SKmCuIHFskbecyhM/SGl6OhsDhCM85ya33mDnWwTRQF+nYuFnJbMkLVBhFbSX+joYN hUis4yP5bqbnFbtA7ROYNvwXMZuCWcEltlSD2QDqJwYU6NhsCNU9KzT6JZi39thN5tAn sZLYVaaFux7zcXIcn7Y3DXxOTy6JrtviMhcpj4oM833RVXsx9ws6LdbHx/sxTnfJ0XBW kd3KXqSnDDUzQ2uST0uo0cjMNp4HPcEgo3J/Z+gCxR9riwjKtPid57xJhQIvfGM1wuNw Pl0p/1+VSRn+bUranWZANjOajMhN9B6amYG1Zk+6qoMzvtHhRAExNA5jgvXfAMRhnVju PVxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x61-v6si52973011plb.560.2018.06.07.08.55.32; Thu, 07 Jun 2018 08:55:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934180AbeFGPxk (ORCPT + 99 others); Thu, 7 Jun 2018 11:53:40 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40361 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932649AbeFGOer (ORCPT ); Thu, 7 Jun 2018 10:34:47 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbu-0005Zk-6y; Thu, 07 Jun 2018 15:09:54 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb0-0002m5-5p; Thu, 07 Jun 2018 15:08:58 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Thomas Richter" , "Hendrik Brueckner" , "Arnaldo Carvalho de Melo" , "Ravi Bangoria" , "Heiko Carstens" , "Martin Schwidefsky" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 073/410] perf annotate: Fix objdump comment parsing for Intel mov dissassembly In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Richter commit 35a8a148d8c1ee9e5ae18f9565a880490f816f89 upstream. 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-tmricht@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- 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 @@ -146,6 +146,8 @@ static int comment__symbol(char *raw, ch return 0; *addrp = strtoull(comment, &endptr, 16); + if (endptr == comment) + return 0; name = strchr(endptr, '<'); if (name == NULL) return -1; @@ -251,8 +253,8 @@ static int mov__parse(struct ins_operand while (comment[0] != '\0' && isspace(comment[0])) ++comment; - comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name); - comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); + comment__symbol(ops->source.raw, comment + 1, &ops->source.addr, &ops->source.name); + comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name); return 0; @@ -298,7 +300,7 @@ static int dec__parse(struct ins_operand while (comment[0] != '\0' && isspace(comment[0])) ++comment; - comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); + comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name); return 0; }