Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp554278imm; Wed, 8 Aug 2018 01:24:54 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwYY2IVg5mU1MqqPs9HBFMLUh+AGrhnQamoRD+wyHFfc7IGXLmojtfBXl2AXg3aMCWxzPT/ X-Received: by 2002:a17:902:5481:: with SMTP id e1-v6mr1640677pli.309.1533716694573; Wed, 08 Aug 2018 01:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533716694; cv=none; d=google.com; s=arc-20160816; b=AcTIPjZl/9a0MujdE8xtRmqKOa1GurbFoZIcKCMhln/z7V813qxlfjgBylguIJgQHQ DFNloMxvEBlfkdZ2FZ2K9WTkSfvD3q9qNHKu0grGijpfcoXsZek9xQekTS4OQ6xeqQvj KJdpQTL3HzH+IKftMUkJhmiucKdN3GMEiWws/4E6rkZgWf5auXINzc4sYu42oWNxs3MT aMLh0yG7/3/NRKvY550Qk/cfVYJFy+OD6I8xpws1grRc/2PdJX34p9txmsaXqg+Wn3+t 9cf+AgK4FcyyZfqpvalZlF101PmwWRe2ifyNbNrKAArgBgrxwiwXFwO974h54kqFCsi+ 51Bg== 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:from:date:arc-authentication-results; bh=XGRIWvh3yGJgTeFcc+dVZhESSC8EQFVf4F/OWQMouXU=; b=spcmc2Gnfj3IQFVsRcrmeLSOpi1yi5Q9pi05Eziz61VHlQzoVVEebt9f676+0OkeOc XSBHoWOFKVLUGbkaIXJOvFCDlwV4Op9FwfGA2S+F1/2ZXZw02W2vIFob8gRxrMzLAYUH bH/leqCH9wJFHJ0lOc9Yfhhd6CrMmoQlVgNojXEJjQLgl4b4wqzU3fk0v5iK5JgfzzHn Q6VQIk1tvpPM0MLC36adQTZI8Q6rbAPvSeBYAYysRobkub7zyvZvfOKpcyHPuq/0bfbZ kx3hXSBFdCQnK54AB0V0YyUnjjGObDR5m7aCUWRA6a7ADKdEllv6Vl3nOCa+fLG2S5m6 DPUg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6-v6si3810406pgr.475.2018.08.08.01.24.39; Wed, 08 Aug 2018 01:24:54 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727106AbeHHKm1 (ORCPT + 99 others); Wed, 8 Aug 2018 06:42:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46918 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726979AbeHHKm1 (ORCPT ); Wed, 8 Aug 2018 06:42:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1978E40216E7; Wed, 8 Aug 2018 08:23:50 +0000 (UTC) Received: from krava (unknown [10.43.17.133]) by smtp.corp.redhat.com (Postfix) with SMTP id 87DBD1C70A; Wed, 8 Aug 2018 08:23:48 +0000 (UTC) Date: Wed, 8 Aug 2018 10:23:47 +0200 From: Jiri Olsa To: Stephane Eranian Cc: LKML , Arnaldo Carvalho de Melo , Peter Zijlstra , mingo@elte.hu Subject: Re: [PATCH] perf ordered_events: fix crash in free_dup_event() Message-ID: <20180808082347.GB20320@krava> References: <1533605015-19514-1-git-send-email-eranian@google.com> <20180807072029.GA7716@krava> <20180807085010.GC7716@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 08 Aug 2018 08:23:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 08 Aug 2018 08:23:50 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jolsa@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 07, 2018 at 12:11:05PM -0700, Stephane Eranian wrote: > Jiri, > On Tue, Aug 7, 2018 at 1:50 AM Jiri Olsa wrote: > > > > On Tue, Aug 07, 2018 at 01:16:22AM -0700, Stephane Eranian wrote: > > > On Tue, Aug 7, 2018 at 12:20 AM Jiri Olsa wrote: > > > > > > > > On Mon, Aug 06, 2018 at 06:23:35PM -0700, Stephane Eranian wrote: > > > > > Depending on memory allocations, it was possible to get a SEGFAULT in > > > > > free_dup_event() because the event pointer was bogus: > > > > > > > > > > perf[1354]: segfault at ffffffff00000006 ip 00000000004b7fc7 > > > > > > > > is there any reproducer? > > > > > > > The cmdline is simple: > > > $ perf record -e cycles:pp -o - -a sleep 1 | perf inject -b -i - >/dev/null > > > I was using v4.13 for my tests and it may be sensitive to compiler. > > > Was using LLVM. > > > > I can't make it fail even when I compile with clang 'make CC=clang' > > > I checked, my actual reproducer is: > $ perf record -o - -e cycles date | perf inject -b -i - >/dev/null > Tue Aug 7 12:03:48 PDT 2018 > [ perf record: Woken up 1 times to write data ] > [ perf record: Captured and wrote 0.000 MB - ] > Segmentation fault (core dumped) > > the crash is in perf inject. > So if I do: > $ perf record -o - -e cycles date >tt > $ gdb perf > (gdb) r inject -b -i - < tt >/dev/null > Program received signal SIGSEGV, Segmentation fault. > free_dup_event (oe=0x26a39a0, event=0xffffffff00000000) at > util/ordered-events.c:85 > 85 in util/ordered-events.c > (gdb) bt > #0 free_dup_event (oe=0x26a39a0, event=0xffffffff00000000) at > util/ordered-events.c:85 > #1 ordered_events__free (oe=0x26a39a0) at util/ordered-events.c:310 > #2 0x00000000004b5a56 in __perf_session__process_pipe_events > (session=) at util/session.c:1753 > #3 perf_session__process_events (session=) at > util/session.c:1932 > #4 0x000000000043a2eb in __cmd_inject (inject=) at > builtin-inject.c:750 > #5 cmd_inject (argc=, argv=) at > builtin-inject.c:924 > #6 0x000000000046b175 in run_builtin (p=0xabc640 , > argc=4, argv=0x7fffffffe560) at perf.c:297 > #7 0x000000000046b062 in handle_internal_command (argc=4, > argv=0x7fffffffe560) at perf.c:349 > #8 0x000000000046a5e8 in run_argv (argcp=, > argv=) at perf.c:393 > #9 main (argc=4, argv=0x7fffffffe560) at perf.c:531 nice > > Again, this is with an older version of perf compiled with LLVM. can you also reproduce it with latest code? > Notice the value of event passed to free_dup_event(): 0xffffffff00000000 > And yes, I checked sizeof(union_perf_event) = 4168 which is the size of > the mmap2_event which is the largest. > > I also checked that you are freeing what you have actually allocated. > No double free. > If I add the padding or modifies the call to memdup() as in the patch, > then the problem > goes away. > > If you don't want to copy 4Kb each time, then you could also make the > event field > by a void *event and case whenever needed. not sure I understand this one.. could you please elaborate? > > I suspect the problem may come from a compiler optimization or assumption which > clashes with what you are optimizing here. I'll go throught the code and try to find somethign.. thanks a lot for the backtrace jirka