Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp314231ybl; Fri, 9 Aug 2019 06:28:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLBO2uq1Pc1zOtKi8+S4lOx2/z6d2njNuALkY7lvkb/tb7aLavSgPZKTMvXuZm6G42HP99 X-Received: by 2002:aa7:81d9:: with SMTP id c25mr21774459pfn.255.1565357281976; Fri, 09 Aug 2019 06:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565357281; cv=none; d=google.com; s=arc-20160816; b=TCXWV2aDbH6GtlgdXBux6DpP48k9a09ZTEm6XNrFfgCIDC9I88FHsxbiJLgJaM2+WL 8opl9mBBpviHiR8pW43+rs/Ir65kBFBoBXxKcKqNYkvGWeuxsat+0tuy2NWcEbcR3uoD j2seEuK7o75F7I8vZA+g8KF7d4Vz6M3TIvBzS+cI2G/RVuvFpkP0yS4t8AyzjxtEoZ5W UVa0gvwjnk3qDj03Bz/ecyGSHcwyyTM7JnDEtOPH1Vij9NDD3TU7v2di2sVwvHXcpuzQ 2lCSyXRechtYv7OuaS4ZoSpFyKTpZtF1zkcoPTxGK7tY0Hl/476dxb3GTYIQlzGjHqpo +zKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=2ZrY/b4WntgdLGp44kkX12ktRp+3EYn+/QxZioshkhU=; b=aD0tA3VKwZoDUGvmIEaPZUdHZgAMqYy9Z+VmmRKLbLfL2Jes9prMC6QMSnXVnY3eVD F3/ErOiKqDcxFnc1MdRNMWnfnBV9GHur6S+104rnaLXPX9WZS1Ag+mSbd0b7SbvVCjSn hi2IDQlFBIpDyvXwFRQUInneKTNZ+gAxsKKC7Fzma3XwRh5utTm6jhUStrsoTEN01UVK EqPmtugk20d0OLdlHSzctFATL0SMLwp2Ek/RKTcNE34PzPU3NHMPst1JuZUq+LF1phje B+JdWh/FellCmqFcA7/HBfRHlB+AjDuwph8N+Q8Sr2Njmpvrdv3mpoS/tUVgNntI7JoA vGDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Cf5fmB7m; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b35si51285444plb.249.2019.08.09.06.27.46; Fri, 09 Aug 2019 06:28:01 -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=@gmail.com header.s=20161025 header.b=Cf5fmB7m; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407077AbfHINZb (ORCPT + 99 others); Fri, 9 Aug 2019 09:25:31 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:40408 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406273AbfHINZa (ORCPT ); Fri, 9 Aug 2019 09:25:30 -0400 Received: by mail-qk1-f193.google.com with SMTP id s145so71595691qke.7; Fri, 09 Aug 2019 06:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=2ZrY/b4WntgdLGp44kkX12ktRp+3EYn+/QxZioshkhU=; b=Cf5fmB7mzINWWtrGpKp//JYl/uShFrRYFRezo/n+I+yOCKP6rkv6U92vt0YdSYbgSo 0BhJVMNKmLB+Gs4wXSgvOj+yXSLtGc1lg5dzWXvSCXyOzMpG3CDDUkrieA0maDrwwWY5 fWvyhyNA88Ohw/5spZ+0mSk51Mlnn/vXYgsedRAN219VgyMt0gcD1xKOAYd3rQWcP8N9 1+6tStmEY6eLumRqFIcvMMPSXVpywmgg5emaN9h/TqI+sCJu+MLhkeP0lUy1LMd/44pt 0EArm9PRrnH6wdGOlUrqqg09ViTBXGWEIt/pwRfVbtrGWCkDorcBu6qePEDjmcXb/E0r Betg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=2ZrY/b4WntgdLGp44kkX12ktRp+3EYn+/QxZioshkhU=; b=SQOfEPs5p0680gDlJzvZyRsTs2yLZliarEY4D2dCk1EnDMU6JUX3smVwbFN6l9cTby DCVkeYWnZlZv8hgetM+b3tJzgQN+f5Pg+JxNz4et55mdkJDcVpZAVLc7x64MXzNRiQr4 cYOwgpQExKK/vwU53Nblj2P3izetXqN15ycrQw/cWG6PqJBbltuOCzrUh2ndDA7Pkeab o6aa/OBe7FFer5+83KogClgRcBFkkMn33KzOYe4yXV5RbqQ0vrMqfgyNxl3OthORGUP7 dxrjQzj5ugo8kg8PgD+ohm0lLpQJTnzfThP6pi+7UJBTr2++qtmdIMJzG46mdBD2yKTq ZV6A== X-Gm-Message-State: APjAAAU3NdAOrH4OMwaSxBS/NR5hHOznR2jIwMRbxLNZbzkzEq7Q0SnA FWcAR/JeEVV+aXia5ObVKGM= X-Received: by 2002:a37:c87:: with SMTP id 129mr16707779qkm.240.1565357129652; Fri, 09 Aug 2019 06:25:29 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.50]) by smtp.gmail.com with ESMTPSA id z18sm39964608qki.110.2019.08.09.06.25.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 09 Aug 2019 06:25:29 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 8885440340; Fri, 9 Aug 2019 10:25:22 -0300 (-03) Date: Fri, 9 Aug 2019 10:25:22 -0300 To: Leo Yan Cc: 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 Subject: Re: [PATCH] perf trace: Fix segmentation fault when access syscall info Message-ID: <20190809132522.GB20899@kernel.org> References: <20190809104752.27338-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190809104752.27338-1-leo.yan@linaro.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Aug 09, 2019 at 06:47:52PM +0800, Leo Yan escreveu: > '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. Thanks a lot! My bad, that is why we have that max_id there, I forgot about it and since I tested so far only on x86_64... applied to perf/core, since it is only on: [acme@quaco perf]$ git tag --contains 30a910d7d3e0 perf-core-for-mingo-5.4-20190729 [acme@quaco perf]$ - Arnaldo > 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(-) > > 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; > } > -- > 2.17.1 -- - Arnaldo