Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp200612lqo; Tue, 7 May 2024 17:51:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYVnQqrIbBrxqDX0mu+pUnPnqPwVkZ7JZ1mD3fymHayNRfgZGMmQfoMFQVowcepuNBcA9tsGpL/HecKJmaAWLirGvxZGO6Jm8YlUmQiA== X-Google-Smtp-Source: AGHT+IEpmcgg4v9maeoOWvB7NxSgIwi5PuaOwpDHKzplRhNQak7vo7S3e7FhCxixCaklbUFAADEd X-Received: by 2002:a37:c404:0:b0:78d:6479:7c39 with SMTP id af79cd13be357-792b27dc1f1mr127033385a.19.1715129490405; Tue, 07 May 2024 17:51:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715129490; cv=pass; d=google.com; s=arc-20160816; b=qyu1Eghry3ZfCdmP1Yqabi6PzkX82OFFXFhwBNBWKI4+MgzgkoaCRShiWpdUuog80H mbQHceuzxo3sqRe0UZzDvtgY7Y6YSSCzEn88shyT16dBOhgD2qDGOKbCEgx4X9AVavgf 8rlbyHUcVu5W/C119/ltx6j7rsp0UAy89NGbi/2Q7YGqsrGHY1Eokwnd5i59mqszGajm JYK7TwM/UagtS+CcBJTFoJ5chT6NPhua9eQLxmQIPbma242bPDEB3rj/YK970ED7NQ/j 73/aYU4Nor2NfJ5FNDT+ydPqFgY1HDK+q2HwrrCYpfSEqnyQRBHSPtVf01u/7wBK74wy 0qdw== 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=9yxY1w9XvCxUPvXqMAMhe9NTxvR+eY9pH/XL6Sd2kTk=; fh=3QpFWx3iQo7xIwFZ6Z36oTJ+yPsbKEGazH9P9NtXuOk=; b=Z1VEig+qkh0zytEMOrYV25WJWUJSok7BkqnCEwlfLnkD7sPRA6aqLMDGKfFnJAp1JG uH48DDXuKtmxLa1q2suuKDMQPadZLw6BStDnwWebUEpcJ/382d8uy3c9t16c54rMFedU +mw2LDEI45jF82WOWfg6cUAxWwIli1Tc8mJ1i+9DLFxtAlUQhjJ7r0oemOkAL8+GtCMu ErBDRyI0zAkizBx18UNa0qIUe0sFgyfGicS4zyWNduUKkyGx2ardOUL2U7vWRCgKVqlr Yd1qDD3XFMwryuWAUYHjkTrnbCqo4r1nMvWE6NYp9jPERCSfkV3/9uYSpnQNr8CvsW4U ETqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ShBxnWHS; 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-172572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172572-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z20-20020a05620a261400b0078d4b620c82si14044118qko.609.2024.05.07.17.51.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 17:51:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ShBxnWHS; 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-172572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172572-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 1AA3D1C236DC for ; Wed, 8 May 2024 00:51:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DA28652; Wed, 8 May 2024 00:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ShBxnWHS" Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 F2FA038F for ; Wed, 8 May 2024 00:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715129484; cv=none; b=ndclf48qDI2n1LqOkH+lIAvC3iknN0kuNQ56XdkB+UMBpDhGgenXxxlPC8axMGC0Nj2LHtehBptFhTM5P6VZ3qsUY331lOa2XnK+oGHnZAP51yfge4SCRzkQe1RRQxi5HJz+AMQ1ctFf0tHPPkwm+LKUbvJ+m4QMFE/BKuiYhdw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715129484; c=relaxed/simple; bh=J9f+ozTQRVvFEaj/RTq9sBDGm3e0WJAgiC7XQw+Bzo4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=h8zvMbcpeDGP0Q0T8VW+iwXEMiAL9jjwoh+RmuWkMboAvuLhFLAPZaCEltvusoovSqDGCtHsPnofm4Jz9iCRQOl2PeOXhdvqoIyspQCQKtQnEv8x4Ike0cN5UR3UVjl35cwvgGpLMeSbBgRxmsGpeDtd08DXKPt7BSDYAC9Fz08= 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=ShBxnWHS; arc=none smtp.client-ip=209.85.160.177 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-qt1-f177.google.com with SMTP id d75a77b69052e-439b1c72676so130131cf.1 for ; Tue, 07 May 2024 17:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715129482; x=1715734282; 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=9yxY1w9XvCxUPvXqMAMhe9NTxvR+eY9pH/XL6Sd2kTk=; b=ShBxnWHSbUv0gI4AcmlLXXju+PAA041ExSciSa8xn9uJ1pMt9EuE8UlQVyX1xU4D5i JA4Y9bDVQKxtFfjtoguyElXBanujAyJ0uVAF6i4bkq+Kutr7dAt958q+Z7zclzNtJIUS bvNGOV9PvGNd4wJAyUcrrsPIYPNeuzbVKiE72RpAeew3n2hDmrbOoQ/ADYsWjU7TyrpL H1q0/lyTTglP+VdSqgzMtlHIh7D/l4TSBXzBhFytCFOZJ1sbnyX7E8AJAoErm/DDrCRc mLf1772L4paGcCaTFsWcMuLG209OtevIBcmyqdFA4Bcr9k618LOfw65Y5HqdMh9d+ALP nz3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715129482; x=1715734282; 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=9yxY1w9XvCxUPvXqMAMhe9NTxvR+eY9pH/XL6Sd2kTk=; b=Q4FFvQVBZVKXbgEXp+LMzJTDta0z21hcdNf8vqFK6pOsbNFxbTESC3uZPxcNYGizc1 PGIykXMCRMrW03ROQSKuc9iN/vIBouveMOkqvhVJCDEVPJYJaCany+PldMhl56o4UNvZ F0wo3egOp6Ue4VH4aybGe5HsWXsLbeWuHzA3wLypwQL9vs/X08s5NioghYmRuRbvDfyt t4eUtyFlZjwNJpejoZ6N507usqgTqkdhP0pbVhIR+M+qJbhULFIdkkuWJBQwdPccSKxi REnL8TJ4+0W9jTbeQvykCIIYxxMpmqfY6nXPlYhLPd7Oz6tnwbXYyLX+ABSEIXPBuTnp brxg== X-Forwarded-Encrypted: i=1; AJvYcCWAt0/rrgFTIJ0sAGfpZfjLNZJOsa1lFX73WUqQsFKUYtlpiADGKMnUFovxtArvURYZD1unS/awe1bZpKB1DthkWTT3hADUxltSpdBc X-Gm-Message-State: AOJu0Yz5ylsrmGMYJ8Hq8MZug52TZTlPKXsOwXs3KYiLuDzHOIJ18J6q yRbHVtPvgVNuBl0B/kSl0sRmjRdsC7aSz+I9d+yQ7vT1iKJaelPqQtt95iaX9xmRI6xc40D82Iu d4Gbr+F5vzsO1bygyrl2awpKKgZCTIqlGj7FX X-Received: by 2002:a05:622a:5490:b0:43b:6b6:8cad with SMTP id d75a77b69052e-43dc2d9577amr1413111cf.10.1715129481777; Tue, 07 May 2024 17:51:21 -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 17:51:10 -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: 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@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 wrote: > > 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 Melo = 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 all= ocated > > > > > > memory in hist_browser__run. Avoid a use after return by strdup= -ing > > > > > > the string. > > > > > > > > > > But everything happens in that context, i.e. hist_brower__run() w= ill > > > > > call ui_browser__ methods and then exit. > > > > > > > > > > We end up having browser->title pointing to returned stack memory > > > > > (invalid) but there will be no references to it, no? > > > > > > > > > > If we return to hist_browser__run() we then call ui_browser__show > > > > > passing a new title, for "live" stack memory, rinse repeat. Or ha= ve you > > > > > noticed an actual use-after-"free"? > > > > > > > > And I'll take the patch, I'm just trying to figure it out if it fix= ed a > > > > real bug or if it just makes the code more future proof, i.e. to av= oid > > > > 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 record = -a > > > sleep 1; /tmp/perf/perf mem report' > > > I then go to the perf annotate view and quit. This triggers the asan > > > error (from the log file): > > > ``` > > > > Thanks, it is indeed a bug, I'll keep that Fixes tag, people interested > > in the full details can hopefully find this message going from the Link= : > > 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__curren= t); ui_browser__refresh(browser); } ``` I also found a use-after-free issue with patch 5. I'll send a v2. Thanks, Ian > Thanks, > > - Arnaldo