Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp337767ybm; Wed, 22 May 2019 04:09:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzktrHcfyuqNtI+6sAZWV7A7GShLcETAbtWiuPxNuRSRRl7fTad1BZ7XYDontUCGWcZGEQk X-Received: by 2002:a63:c601:: with SMTP id w1mr1596072pgg.190.1558523392130; Wed, 22 May 2019 04:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558523392; cv=none; d=google.com; s=arc-20160816; b=DoVgKGLSEAq9iMc64hK6wWvTFxzWOq6Y0DJrGoyi0z2YqoSmj7pJOPfCbRktDVWJ/F wXrf3M6pup1GIu4j+ZWipG3mfKKlXRkuGi50bpNthBtMuxC0vnF0GXayPhuOdNl2Lj4y XzP/sm1Q7M/1bdGVqZJVyF46zgpn3ruh4pW1/mS2PBVsXhDJ5/7wHvn2+v7H6P2/N6Sy Y/TTpgW0o5Scv1XVtSlbWnBZ6EDkG4f1r+263cPOMxh3EYslFxZ/2gdEWhQO/fcnYZ6Q 4Cgu7q698fhnrbsQg6F568RCRlVz2Mal/C+QaZFR6gAyycARCyzWeudOLsoHoSoxco5/ wwXQ== 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=pMmkqCL3UPJrqwz90rzNGDcu6Lug81+3J4XTOSHnFoo=; b=zZ3mFmJ0zNE9rH1b2I7itXBDAdRPK3L2WZ9u5qF8hiFK9esJQ1WxECT7zq1/y2CcWg WJ1egUvjThCg5YYdk+qqSjzZMg8EW7KSbU/+vH0m8trEtnMWNmJM0sk7anHSzKkg1KSj ZbMQCaC3z1Viy0OpOoFiE9OXigDI+eSpBgMGUXIqho+ADc34A6qWEarQXY0S2C/RJ2UP whOoedbh+CDpF148jO+HbSjbEWtsnSxtui0h66IH1ptw+E1qR2yKZktq/gurF1JjT6Tv jdUbRlrMBuaF29mHVE7n+Fk9b4A0F9/K1CMGznI7EWAXFKxSvBlVblAuHCBzlJ3v1GEM Hz5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dFfxQx0w; 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 o8si24994935pgc.137.2019.05.22.04.09.35; Wed, 22 May 2019 04:09:52 -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=dFfxQx0w; 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 S1728971AbfEVLI1 (ORCPT + 99 others); Wed, 22 May 2019 07:08:27 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:41322 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727464AbfEVLI1 (ORCPT ); Wed, 22 May 2019 07:08:27 -0400 Received: by mail-qk1-f195.google.com with SMTP id m18so1148661qki.8 for ; Wed, 22 May 2019 04:08:27 -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=pMmkqCL3UPJrqwz90rzNGDcu6Lug81+3J4XTOSHnFoo=; b=dFfxQx0w5CGo2K4bRdhb8YGzJbCf+ECw2Hk4Wy3KSZYqNBOr5W2RNLySFynk5joveK 4kwd1CY7+UukFn/O2e02XsMCaUqaz6Xe1ItyK5G7e6pGonGPVdOkzmXMCJLs6DBu9xdh 26L6t53862Vbe5F/GLgN1GgrGS6YUZL/Ff3A1bMLNEyX0y0Qk9dvbbeYYqt5GjZJzNOi yoIx0BrtkCYyxc2Nyt5YP2cRiVxZARKU75TzcChfgV2edjAXk9r7piV3tlF6XGDscntJ nAzP08z9ZbE3RkWqGtuQe5OE9wUch7VjI4z1k/Pj8JK7gUgA25OfLsduYR+3Sya1yZsq P8Ww== 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=pMmkqCL3UPJrqwz90rzNGDcu6Lug81+3J4XTOSHnFoo=; b=FyyXqUGvuoBRBvRFimm8dYb1PMBV3ojl9wZW28cR4KzYh4ZZqRpoPuRX3p63Vahso5 8IKeWLfRDsXJlauUurRpUfKv4N1b/1Ockf021fndmXlWz8sfDPYNakR7ec7PmgAybNgg GDelLnPiVOK8ZZyQch/hoI9HCTj73ybI307fk0eUMqB6oQ91pVrvEtyxjM0bFxDledRk Rv/lYmUUzBCp8Hi9hsGzaS0Bf3bzTbD4WYUh5DJWrPFxjb7y6fnsA6roRKQDB+6rsxGK EUvQJpqMQyu26RxGo9gBDqH3MwNzqNP/8Al/8TyHqC0FmeO69naB885K3hHU9ajuqnHa R58A== X-Gm-Message-State: APjAAAUkip4ec14W6ytB00YCaiWFwR6/Ym6JsvWHM75RT1Vt2DVigCld NztnfaBu9VmI5BFsmgbQSUEFP39V X-Received: by 2002:a05:620a:1107:: with SMTP id o7mr61050709qkk.184.1558523306657; Wed, 22 May 2019 04:08:26 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.11]) by smtp.gmail.com with ESMTPSA id k127sm10976158qkb.96.2019.05.22.04.08.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 22 May 2019 04:08:25 -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 2B53F404A1; Wed, 22 May 2019 08:08:23 -0300 (-03) Date: Wed, 22 May 2019 08:08:23 -0300 To: Wei Li Cc: Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Jiri Olsa , linux-kernel@vger.kernel.org, xiezhipeng1@huawei.com Subject: Re: [PATCH v2] fix use-after-free in perf_sched__lat Message-ID: <20190522110823.GR8945@kernel.org> References: <20190508143648.8153-1-liwei391@huawei.com> <20190522065555.GA206606@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190522065555.GA206606@google.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, May 22, 2019 at 03:56:10PM +0900, Namhyung Kim escreveu: > On Wed, May 08, 2019 at 10:36:48PM +0800, Wei Li wrote: > > After thread is added to machine->threads[i].dead in > > __machine__remove_thread, the machine->threads[i].dead is freed > > when calling free(session) in perf_session__delete(). So it get a > > Segmentation fault when accessing it in thread__put(). > > > > In this patch, we delay the perf_session__delete until all threads > > have been deleted. > > > > This can be reproduced by following steps: > > ulimit -c unlimited > > export MALLOC_MMAP_THRESHOLD_=0 > > perf sched record sleep 10 > > perf sched latency --sort max > > Segmentation fault (core dumped) > > > > Signed-off-by: Zhipeng Xie > > Signed-off-by: Wei Li > > Acked-by: Namhyung Kim I'll try to analyse this one soon, but my first impression was that we should just grab reference counts when keeping a pointer to those threads instead of keeping _all_ threads alive when supposedly we could trow away unreferenced data structures. But this is just a first impression from just reading the patch description, probably I'm missing something. Thanks for providing instructions on readily triggering the segfault. - Arnaldo