From patchwork Fri Aug 9 10:47:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 170904 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9823629ile; Fri, 9 Aug 2019 03:48:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzU72BYdwle8RIngkn5VwLoFI2/iZDw8uVN23L5S/I+dY0QB2TdFbKyYUvHZLKT0lRbXzvj X-Received: by 2002:a63:2784:: with SMTP id n126mr16405555pgn.92.1565347692613; Fri, 09 Aug 2019 03:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565347692; cv=none; d=google.com; s=arc-20160816; b=NpcfjGJLBM+YJeH5Q/O3o5miRwG1GcU5zF/3oC1TXwD8lsmtS2QrQHqYk0jA0gXvuG +ifdGd6o+9j6b4UvmtQuFY/yVuvCqMVmBJMCQGAiZYf0YAOFYoWYKdSsm/rAqXQo9YCf No0+ou59/XDYR7SnuwmS0iV1bRVVz4kzPBzYfr2UvmRuSaKTvAOcB/kUK2UVfgvnCMHL 1ZmGXmrsr5E28dUugy8XHNIg5yQnStW9hnuqVW/x1usFcJgBWPhVQxoWmsH5zEUfJgKQ ZrypRQWL770DWONAVJRbtxnF4snpmVv2lbvar61ytaCVOQu5zhTXIKlyk/8jvrhQ+rvB iuoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=SWSgHhHu/9BjvEKvg6DvYw5jthq0QCStuXD5Y25D++k=; b=s4OWSL0KKc0fc2xszGHWFMXxB85qf2T0tlcmsxP2uMFPVqpSz35ocY4mdTflS+GzG0 RB2BwZQDq6+9bYXC2rwedeql99jWtynkkUU4KLLHtOCVqJJW5lVABS/sgjRJWKKD1D6/ UHJbQPd4pZs2tKUs0Cur7NJqB4/Nretfx/O5PR4j9oB74F7FEE89ZSpsLf4Q/Efm1KHt 0IWtm6G5lnUNWrBnOy+lD6/XOGQupfPU4PkaFtmcBivevzECWSBCx3JarVUOqdOM6cMg w2a3EL/jpU1zfje2Hkcnx8fuI0iko6UMfOCD8Qvg+umOfrNPMvdr2CNANxwG8u2FBtP4 vICQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=olBzn9Ia; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h17si1376682pjq.16.2019.08.09.03.48.12; Fri, 09 Aug 2019 03:48:12 -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; dkim=pass header.i=@linaro.org header.s=google header.b=olBzn9Ia; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbfHIKsK (ORCPT + 28 others); Fri, 9 Aug 2019 06:48:10 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34501 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbfHIKsK (ORCPT ); Fri, 9 Aug 2019 06:48:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id b13so45855035pfo.1 for ; Fri, 09 Aug 2019 03:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=SWSgHhHu/9BjvEKvg6DvYw5jthq0QCStuXD5Y25D++k=; b=olBzn9Iae3J+Se9iHRoHNcpUalAkm0ZD09Av8Rhf0Un1Erb82ltsMGyfBJNHsDpsio LlbQvDyOt9ixqafHrC8B30eZNQFydT4ALlqO+PDtaXDqR4t+msvvRbMRJA9mlCGEu1hk OWPdIUoClXdonkrlZl0wMf7etys7/V0IUfhh6KzMsReQc8ryg6G4ekAD7BMSlJ7V2qmU erp/KwrNpRh1Rsx4z65y13/nqjod+Jpum23/PTaXvdW+hSPFj9YiD2+AqR4K2BRVzNSd eap5YaVNNKHXwu78ZyVTVLyxgl5j7Dke93bjTNx2H5SEjKGaVOV9aCWV5DhSzXE2AMVB pBMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SWSgHhHu/9BjvEKvg6DvYw5jthq0QCStuXD5Y25D++k=; b=Qlko0yp/TCWsy7phEBUrVqIZKx5vx/9hNywdu1Wuozh1hoOnMo1+Ez7Yb6xmdC31KA SmsDDFVyer4A3dHGQed8OxFVPBfAw+35o90q1wurSx8JHXhjeseezV4GtgEqEKs7L0H5 OtnSUGJ2kaMtENYhzB8cn+xTTL7OtDM+QQXzPkWKw23JMzbMHm9OQz9dM9Wt4PwaM9bf knUfPWsXqHYKrF12PFq7EO66rVbUkakOCddNoSALuhofYSW+lutTG7HQ2GmdQ0pj8i6c GnAzzrgEDDEayoDN2H60IYdgUJtNKOdekSyYV26d5zlCYzS3BoRPUD5/Bd3NsXCsvRH/ nm0Q== X-Gm-Message-State: APjAAAW4+qBLMpVHK5pHw9Z7fHj3+J2k+Ou9RCsjiOHtayozc1cQt/X/ nxgndsi34AAGJUdESCB6bhCdJA== X-Received: by 2002:aa7:82da:: with SMTP id f26mr20912390pfn.82.1565347689544; Fri, 09 Aug 2019 03:48:09 -0700 (PDT) Received: from localhost.localdomain (li456-16.members.linode.com. [50.116.10.16]) by smtp.gmail.com with ESMTPSA id l44sm4651449pje.29.2019.08.09.03.48.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 09 Aug 2019 03:48:08 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Leo Yan Subject: [PATCH] perf trace: Fix segmentation fault when access syscall info Date: Fri, 9 Aug 2019 18:47:52 +0800 Message-Id: <20190809104752.27338-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'perf trace' reports the segmentation fault as below on Arm64: # perf trace -e string -e augmented_raw_syscalls.c LLVM: dumping tools/perf/examples/bpf/augmented_raw_syscalls.o perf: Segmentation fault Obtained 12 stack frames. perf(sighandler_dump_stack+0x47) [0xaaaaac96ac87] linux-vdso.so.1(+0x5b7) [0xffffadbeb5b7] /lib/aarch64-linux-gnu/libc.so.6(strlen+0x10) [0xfffface7d5d0] /lib/aarch64-linux-gnu/libc.so.6(_IO_vfprintf+0x1ac7) [0xfffface49f97] /lib/aarch64-linux-gnu/libc.so.6(__vsnprintf_chk+0xc7) [0xffffacedfbe7] perf(scnprintf+0x97) [0xaaaaac9ca3ff] perf(+0x997bb) [0xaaaaac8e37bb] perf(cmd_trace+0x28e7) [0xaaaaac8ec09f] perf(+0xd4a13) [0xaaaaac91ea13] perf(main+0x62f) [0xaaaaac8a147f] /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe3) [0xfffface22d23] perf(+0x57723) [0xaaaaac8a1723] Segmentation fault This issue is introduced by commit 30a910d7d3e0 ("perf trace: Preallocate the syscall table"), it allocates trace->syscalls.table[] array and the element count is 'trace->sctbl->syscalls.nr_entries'; but on Arm64, the system call number is not continuously used; e.g. the syscall maximum id is 436 but the real entries is only 281. So the table is allocated with 'nr_entries' as the element count, but it accesses the table with the syscall id, which might be out of the bound of the array and cause the segmentation fault. This patch allocates trace->syscalls.table[] with the element count is 'trace->sctbl->syscalls.max_id + 1', this allows any id to access the table without out of the bound. Fixes: 30a910d7d3e0 ("perf trace: Preallocate the syscall table") Signed-off-by: Leo Yan --- tools/perf/builtin-trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 75eb3811e942..d553d06a9aeb 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1492,7 +1492,7 @@ static int trace__read_syscall_info(struct trace *trace, int id) const char *name = syscalltbl__name(trace->sctbl, id); if (trace->syscalls.table == NULL) { - trace->syscalls.table = calloc(trace->sctbl->syscalls.nr_entries, sizeof(*sc)); + trace->syscalls.table = calloc(trace->sctbl->syscalls.max_id + 1, sizeof(*sc)); if (trace->syscalls.table == NULL) return -ENOMEM; }