From patchwork Tue Sep 1 03:29:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 52908 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id B268322EB3 for ; Tue, 1 Sep 2015 03:34:12 +0000 (UTC) Received: by laboe4 with SMTP id oe4sf33185146lab.3 for ; Mon, 31 Aug 2015 20:34:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:content-type:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=OqyxWdnxGdRT3vNKa8kyTjlhAyOqazVnlMZFi0LDzRM=; b=Rvl8UFKBx01vLLfAlmQzemrtzc9LxC3U45x48c9k7IznCqUNIoCmCzja6eLpw9tS4z /7CXKaTJ37VvBZZbC1rkQjNCBkWHz6IPkjWWpx7rk5v8Mn2Ye13J/+MLHfN6iNCeiBOq fOcS59WkDjrReAF28EsRAgJiBSMzYhkvfDiWZvUwc9gcKdMBEWMpv69Qx4y1Jy8dpNfd 2/utO/rBwDs8CNsO0oGnGKyr0bdAHnizrtyhVZ1cfoHonzwygn0We/wkJhYbtFE+KvJF AfdAsfIGa/b35ty362wt1hlcYx0zaA0veWQt+ovxLJ6Rx/hMSYDXztWSMV8ooIGw3jMs 3lLw== X-Gm-Message-State: ALoCoQn0bv/mdfVN+DwKOPCU2xQixnN90F9FEmVjnaz0uOOaB/IvF9clONlQGbEoVc36hfR60nB4 X-Received: by 10.152.21.233 with SMTP id y9mr2353646lae.5.1441078450724; Mon, 31 Aug 2015 20:34:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.73 with SMTP id 9ls463127lak.17.gmail; Mon, 31 Aug 2015 20:34:10 -0700 (PDT) X-Received: by 10.152.44.232 with SMTP id h8mr11751345lam.104.1441078450560; Mon, 31 Aug 2015 20:34:10 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id w5si4987112lal.38.2015.08.31.20.34.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Aug 2015 20:34:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by labnh1 with SMTP id nh1so58872291lab.3 for ; Mon, 31 Aug 2015 20:34:10 -0700 (PDT) X-Received: by 10.152.22.133 with SMTP id d5mr11701313laf.112.1441078450401; Mon, 31 Aug 2015 20:34:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.164.42 with SMTP id yn10csp241329lbb; Mon, 31 Aug 2015 20:34:09 -0700 (PDT) X-Received: by 10.68.164.97 with SMTP id yp1mr43064187pbb.133.1441078449218; Mon, 31 Aug 2015 20:34:09 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id py4si15748121pac.15.2015.08.31.20.34.07; Mon, 31 Aug 2015 20:34:09 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755225AbbIADdo (ORCPT + 28 others); Mon, 31 Aug 2015 23:33:44 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:27828 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755195AbbIADdm (ORCPT ); Mon, 31 Aug 2015 23:33:42 -0400 Received: from 172.24.1.49 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.49]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CRO12643; Tue, 01 Sep 2015 11:30:06 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Tue, 1 Sep 2015 11:29:54 +0800 From: Wang Nan To: CC: , , , Wang Nan , "Arnaldo Carvalho de Melo" , Masami Hiramatsu , "David S. Miller" , Matt Fleming , Jiri Olsa Subject: [PATCH] perf tools: Fix potential array out of bounce accessing Date: Tue, 1 Sep 2015 03:29:44 +0000 Message-ID: <1441078184-105038-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , There is a problem in dwarf-regs.c of sh, sparc and x86 that it is possible to make an out-of-bound array accessing when searching register names. This patch fixes it by replacing '<=' to '<', so when register (number == XXX_MAX_REGS), get_arch_regstr() returns NULL. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Masami Hiramatsu Cc: David S. Miller Cc: Matt Fleming Cc: Jiri Olsa Reviewed-by: Matt Fleming Acked-by: Jiri Olsa Acked-by: Masami Hiramatsu --- tools/perf/arch/sh/util/dwarf-regs.c | 2 +- tools/perf/arch/sparc/util/dwarf-regs.c | 2 +- tools/perf/arch/x86/util/dwarf-regs.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/arch/sh/util/dwarf-regs.c b/tools/perf/arch/sh/util/dwarf-regs.c index 0d0897f..f8dfa89 100644 --- a/tools/perf/arch/sh/util/dwarf-regs.c +++ b/tools/perf/arch/sh/util/dwarf-regs.c @@ -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; } diff --git a/tools/perf/arch/sparc/util/dwarf-regs.c b/tools/perf/arch/sparc/util/dwarf-regs.c index 92eda41..b704fdb 100644 --- a/tools/perf/arch/sparc/util/dwarf-regs.c +++ b/tools/perf/arch/sparc/util/dwarf-regs.c @@ -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; } diff --git a/tools/perf/arch/x86/util/dwarf-regs.c b/tools/perf/arch/x86/util/dwarf-regs.c index be22dd4..a08de0a 100644 --- a/tools/perf/arch/x86/util/dwarf-regs.c +++ b/tools/perf/arch/x86/util/dwarf-regs.c @@ -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; }