Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp210384lqo; Tue, 7 May 2024 18:18:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVq5zeDgyyAivxphmIfJSkuK+K1Trucnl909sBNEUrE9PldFqlRUBwLJUzvExz+MygB4KGHURjS+amkn+45TuU5aE+gO/3JQfrubCJgaQ== X-Google-Smtp-Source: AGHT+IHZKGTX9hqx19ZbLGx1fd8fGbj83ujDOxy4Q2oFiw2Qpskxbkc+SiV2InbgqQL0r9ooUajH X-Received: by 2002:ad4:4ee1:0:b0:6a0:a169:4592 with SMTP id 6a1803df08f44-6a1514efdb2mr15404356d6.63.1715131096700; Tue, 07 May 2024 18:18:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715131096; cv=pass; d=google.com; s=arc-20160816; b=IsLKspAarZvRr9dLB5aXxYYD4r2vXrhZzWWVDJgXJGp2FT6MrhktouV3AkyHMC6JxG 7X4n4j3lUcQzlicFHY9Y8dBCsvgIDUoYGuOXVzC7nH5uL183qf39HFYlGvNhQIHyB6ZH U4bUS1iHvsCDhgyQ5Zl0TwZ+PZ8tzh0HWAE10+Wd6o65wh1eIIGaV+C6jt3NrX5kx5nj 5TQ5NDGqttQX2mxV7XWg6JNJaUFyu1R2fygVzXGCDwCkSyd0z3La5lmx/KqATnhD3Fz0 cYmJcQM6SdTZVNArua6Y5yT3k0t4hbIoP9Ic3wSTP4KDoFa5fxKRKn1qGw+8WCPhpTj8 Kz7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=E61N4amXuh7VFXvwkeviInZfYjjo6QzIfwyPvrMCCcw=; fh=pSjuwdnPmMhfjpFOD9f7rk9QPGLzf99a4+ruLoEDZYw=; b=Xi22yg8RMNABuoJX0XNHt7KRDVo0fq4Z8emVjtqRPF/WOeadZVPtWfF+ID6ZsK6Lb1 ETCrc43DP5WZfuJL94vt/JeS/sCroqI4Sce9/6FGV35Cit1OME3RiihXMvSijCC5B0CU S23lR9e0iB5/4mZd9RLarXiNnElWi5Jqn9S3rMgRamv923BVozFxZDb4hh9fJnpib43D 1C3r3uk1y/j79uYpvoqdwhruB7/rmwfvJqlDcpNLIcO6pSKhpQ8QezTdKSu2VtQAt8Rz rgnjbjyXU6oKLsGs0H3HhslxjDy8sP9SfHejIqY56FqiICIwHvQ0rND40QaJXnKr0KLi tUXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Bl9o57tS; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-172583-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gu12-20020a056214260c00b006a0b36299b7si9520718qvb.565.2024.05.07.18.18.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172583-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Bl9o57tS; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-172583-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 642E41C216EA for ; Wed, 8 May 2024 01:18:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA6E6B669; Wed, 8 May 2024 01:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Bl9o57tS" Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A4678C1D for ; Wed, 8 May 2024 01:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715131081; cv=none; b=XlUC4dtBg4X7twGNIm2LTHA2xkRoQcDY2rzWXEzVfT6ZOn3Mv3iWZQfNYbUeK98U467iqdfHi2M+OcpKb87wxos+elv5oRBxiLanz4JxIvvnN+rWHdf5OC0ic+T/htGPVb+BRNLgqhkOAOX5RIEcp/atVN8bBFbQ7ZUcXdmmf/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715131081; c=relaxed/simple; bh=lU4K+YQogUbUsnBfG3NNfnWjg0twdDGt5SBtLLxhFNw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=pksPHvVEJEltd6Qd5EuXK9GqRz/TwB45JmetI0zm86y5Wgh3U+gQ3SXPGTUcoJMu9ir1ZrDHzCdtw5IBr41MT0aoM0WT5pmx/FCg3thkn7aEdj8pEO3+1c/t920KkRO3+qYR397heNdJ/iiEZeGJoCIrTrCtRjGAyssAJ/ZCFqs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Bl9o57tS; arc=none smtp.client-ip=209.85.166.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-36c670757aaso29805ab.1 for ; Tue, 07 May 2024 18:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715131079; x=1715735879; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=E61N4amXuh7VFXvwkeviInZfYjjo6QzIfwyPvrMCCcw=; b=Bl9o57tS40e+ehYxJ1unbKKMxFZVxNpbSeS/QNROZfx/8/IhfwDSqFlg68kPSiLa3B hlkolYnSdY/6Ff4d+73vyCtC6qOlcvyt+2lNg+KE15bsqNr76SHLrgtGew+QUKR1GwhR hASPuRnOyKMEFJE3xkw0tWlKU5fWV63fHQnY/9xNOB/Z4ilW1dohHVKcPdisprGMiLnz k7l+AoKvnT0dAch+raPipWbeqrlbRKhF4pRmvllWR+dBWAVSG0JKGbEMOSLZRH0Cf7uK HpF1kPv5+r/Jpj7MSEKwztVZImNXzQBKCk2N8WV1GlqGXEYMxK3xad0g6K6kCb+yyO8S sckQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715131079; x=1715735879; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E61N4amXuh7VFXvwkeviInZfYjjo6QzIfwyPvrMCCcw=; b=LeFtwsm5MV5aUvpgDLhvMtjJX+QJINy5lfdXU8yl53ZMnsrKbHR5wSQhDwKABmUKj2 5H8absaw0hg/JG6kDwwX2gY9fr9lThJHHOg41b5qnCoGy48/RMQyuOao9mDnaHGJIlwu 8f/6iHBwh9mgffKr5tCQkWuFFMgw6UyyPt+Zl0LUeCXvtubJ+hvbMfV8B9n4JcRU4Jdi CPFZPQaPhngzEswLVaXgOqr7JsrbaUooBN6ywLCEbPqA6ABkNHUktQR5MleQRcxHeR8w Od0pmZdeJcMNCe7Y2MiERExBMybR466niqbqBKYrETFdarBOm6osXN4zJBWyB7r3PHXb m1ng== X-Forwarded-Encrypted: i=1; AJvYcCVp95PzeA66bt4uLRipdi5Qg3hmJL93Yv5QeBO+g/31JTyRwugSbZdjYlB5lFX1JO8bwbKdDyt5vdWbhPTvvFtCKGpr+MOT96tGC1Ef X-Gm-Message-State: AOJu0YxEFFUHSSMYCFxsHVD67fsynqq6axindhUF3C+BFcQzckqPF+45 XpG/oQekTtRCkPHxDge9IMEAdOC1Ph5PjkvWXczL+PXbXhDAiHqEFlfhkuLqPvw/doLnlFlKFvj 5srSm3JnGCPt1nVphskRmW6UL+S5YTCdY5vGM X-Received: by 2002:a05:6e02:1ca5:b0:36c:5f5a:b90c with SMTP id e9e14a558f8ab-36cafeb96fdmr757955ab.23.1715131079449; Tue, 07 May 2024 18:17:59 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240507183545.1236093-1-irogers@google.com> <20240507183545.1236093-2-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Tue, 7 May 2024 18:17:47 -0700 Message-ID: Subject: Re: [PATCH v1 1/8] perf ui browser: Don't save pointer to stack memory To: Arnaldo Carvalho de Melo Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , Oliver Upton , James Clark , Tim Chen , Yicong Yang , K Prateek Nayak , Yanteng Si , Sun Haiyong , Kajol Jain , Ravi Bangoria , Li Dong , Paran Lee , Ben Gainey , Andi Kleen , Athira Rajeev , Linux Kernel Mailing List , linux-perf-users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 7, 2024 at 6:07=E2=80=AFPM Arnaldo Carvalho de Melo wrote: > > > > On Tue, May 7, 2024, 9:51 PM Ian Rogers wrote: >> >> On Tue, May 7, 2024 at 2:07=E2=80=AFPM Arnaldo Carvalho de Melo wrote: >> > >> > On Tue, May 07, 2024 at 06:04:43PM -0300, Arnaldo Carvalho de Melo wro= te: >> > > On Tue, May 07, 2024 at 01:48:28PM -0700, Ian Rogers wrote: >> > > > On Tue, May 7, 2024 at 1:22=E2=80=AFPM Arnaldo Carvalho de Melo wrote: >> > > > > >> > > > > On Tue, May 07, 2024 at 05:20:59PM -0300, Arnaldo Carvalho de Me= lo wrote: >> > > > > > On Tue, May 07, 2024 at 11:35:38AM -0700, Ian Rogers wrote: >> > > > > > > ui_browser__show is capturing the input title that is stack = allocated >> > > > > > > memory in hist_browser__run. Avoid a use after return by str= dup-ing >> > > > > > > the string. >> > > > > > >> > > > > > But everything happens in that context, i.e. hist_brower__run(= ) will >> > > > > > call ui_browser__ methods and then exit. >> > > > > > >> > > > > > We end up having browser->title pointing to returned stack mem= ory >> > > > > > (invalid) but there will be no references to it, no? >> > > > > > >> > > > > > If we return to hist_browser__run() we then call ui_browser__s= how >> > > > > > passing a new title, for "live" stack memory, rinse repeat. Or= have you >> > > > > > noticed an actual use-after-"free"? >> > > > > >> > > > > And I'll take the patch, I'm just trying to figure it out if it = fixed a >> > > > > real bug or if it just makes the code more future proof, i.e. to= avoid >> > > > > us adding code that actually uses invalid stack memory. >> > > > >> > > > My command line using tui is: >> > > > $ sudo bash -c 'rm /tmp/asan.log*; export >> > > > ASAN_OPTIONS=3D"log_path=3D/tmp/asan.log"; /tmp/perf/perf mem reco= rd -a >> > > > sleep 1; /tmp/perf/perf mem report' >> > > > I then go to the perf annotate view and quit. This triggers the as= an >> > > > error (from the log file): >> > > > ``` >> > > >> > > Thanks, it is indeed a bug, I'll keep that Fixes tag, people interes= ted >> > > in the full details can hopefully find this message going from the L= ink: >> > > tag. >> > >> > Nah, I added your explanation to the cset log message. >> >> >> Okay, I found I needed this to avoid a segv introduced by this patch: >> ``` >> diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c >> index c4cdf2ea69b7..19503e838738 100644 >> --- a/tools/perf/ui/browser.c >> +++ b/tools/perf/ui/browser.c >> @@ -203,7 +203,7 @@ void ui_browser__refresh_dimensions(struct >> ui_browser *browser) >> void ui_browser__handle_resize(struct ui_browser *browser) >> { >> ui__refresh_dimensions(false); >> - ui_browser__show(browser, browser->title, ui_helpline__current); >> + ui_browser__show(browser, browser->title ?: "", ui_helpline__cur= rent); >> ui_browser__refresh(browser); >> } >> ``` >> I also found a use-after-free issue with patch 5. I'll send a v2. >> >> Please send a fix, it's already in perf-tools-next. > Okay. It looks like you accidentally pushed tmp.perf-tools.next, that is a .next rather than a -next (dot not dash). I'll work from perf-tools-next. Thanks, Ian > Thanks, > > - Arnaldo > >> Thanks, >> Ian >> >> > Thanks, >> > >> > - Arnaldo