Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp97171lqo; Tue, 7 May 2024 13:22:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVAEOCWsNMK11JXfwahI3GKeOeMiD5LFolOd+5FwcCsVzT61/2hs85ECWZwMuJloL5Ft9l59CvpGu+6KHEUuBmCuraj4djN56k/klwmWA== X-Google-Smtp-Source: AGHT+IEtiuB+d9b3k2qFCaWLMDl71MVAEZeiugwLaHDVHX6D7029wIVLBx+/AGb98Iupy+Vj+AI2 X-Received: by 2002:a17:906:2b1b:b0:a58:a0b8:2a64 with SMTP id a640c23a62f3a-a59fb94b152mr30569366b.5.1715113370389; Tue, 07 May 2024 13:22:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715113370; cv=pass; d=google.com; s=arc-20160816; b=hMeCZY110wdl6bUBdQXKP8l4tkyL4mCYXzP2CkRY/VcseHjL8Tx1GerHAIt20qpBEp jmGI9c+Ep76J4mogEJbbTG5xcOuD2RpNrV5TfyWHFHX2DldkMX2d6gE+WBY2IlEuXnva vZAUGCD2wqv41mm5dZVUZ1M9QlFjsnuZwYhJ9/Cf6IaXhqdCxtR11iAYv9cgI9qVCusJ uSe5imQ/VpTcz/Ew1zBiB6Hq/l9iboCuyEzfSHPIQcjvEAEf/J3vGEjQS29HT1mDfcep EGkeeVqie02PwRpjb2FRzAmmJH5g7KtPYzaljg10OpLei8M3IH3ILysFUxLqeTvg2EWw mXPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=r9tEHPjjE+Lj7RdN/N8TdpYhl3exmKSy+pzBcXk+ua0=; fh=YvR0+rgjGlqqFjlZ5QPM77BW06x/W8UL2iScm9rsdi0=; b=NgKkn9h/QXbymdv3Tt7FYoG0NYcdpAgqE+BvWIJnVQJ7rz86CH3y/Mf0erb+zxAzWJ jXpkqRKsAigxgC2fvmk7aBp5ENOvtxc5ZyFHkUKf/DoO/Yi9bcgTOc/SExoSCpMwZPI7 InnNXhdgFGW1G+z+QMZAUu8AQ8SMpZIl4AIiFklD46ywsg/cHCz8dlIwDt1iv/7REah3 dgQeDwLkUAqo/lnm5EG0JaSgHP9nZIhJn/sSrn6kyEO0BHNP0qlnLIiEFcYD0JjIv6uY QbAa4+Hp5b+ty3Xzx+V8Q4R9l8hj9LmihDinJichYztAQNUtF4PC4XhoYJ5yQy1rNUgJ gmcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VjMZhEwY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172140-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172140-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lz10-20020a170906fb0a00b00a599e63439asi4795967ejb.342.2024.05.07.13.22.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 13:22:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172140-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VjMZhEwY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172140-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172140-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 232911F235CC for ; Tue, 7 May 2024 20:22:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4F02187350; Tue, 7 May 2024 20:22:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VjMZhEwY" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1997D18733D; Tue, 7 May 2024 20:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715113362; cv=none; b=GF7PTM16stezoLeQZ4xVe2L6WJsBLBds+s+DI2Z09Rr6a2boAtw6HcmysoalHPY8ADH5pvGEcLcUHWggTVZlRzWlVEnOzZ/sqMdsBdlrQycPmsDWD1n/5mIQVEpREb0Uvr8KOrvktmKcVM8fjqcq+xpBUNA9uzBOqqKL9CVxvb0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715113362; c=relaxed/simple; bh=1RbsmdPHrG35757L2/jwausSGTj7PtubNPTbxyDYUSk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZTXf/GdMGiNvhSURDVG+G6p5uByVftFikOA7vDr61dWCrGsPZjtcoKE4/IJsumfmM3NpBrp+Zr9+lpzwJSdT+HISdeN9A259GexVkh1OUlq4nOQ+RrP3ZltyOOyRIzYZSqEdXbuKecfFkBMGoDnYD7uqTZ098uokJ5c8Kg1sdOE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VjMZhEwY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11C02C2BBFC; Tue, 7 May 2024 20:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715113361; bh=1RbsmdPHrG35757L2/jwausSGTj7PtubNPTbxyDYUSk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VjMZhEwYsM0dh7cIqoA9Gd6un66CuCELI6ap3ptY9bh2u752STcG5u/BVeiV0uEeG AaVe8mGddngvOJftpk+RYfdWB1Gl8X09GNyV6fwbMaKZZegbmFwWDR6nNZRcUyhVcS wXmwxC0kCWMlXPUEe9vhkqEK15SYrJ9+CS37TyK8Q70OsW8SVeQApGdnMLcqebyjy8 1zuoHPismpwunJt9Ag83f4l7kgJ3FFdzxVz6AcfGjlrbAUYiOWR7ylVzT8c000oXN+ 3zT6HGeUTsY8/04XtdrHKu7HKq145e93OH4mSoC0oFk0y/DNDeLjwSFA3LtSKpURNo tbFR0cinV5OoA== Date: Tue, 7 May 2024 17:22:38 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers 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 Subject: Re: [PATCH v1 1/8] perf ui browser: Don't save pointer to stack memory Message-ID: References: <20240507183545.1236093-1-irogers@google.com> <20240507183545.1236093-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 allocated > > 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() will > 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 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. - Arnaldo > - Arnaldo > > > Fixes: 05e8b0804ec4 ("perf ui browser: Stop using 'self'") > > Signed-off-by: Ian Rogers > > --- > > tools/perf/ui/browser.c | 4 +++- > > tools/perf/ui/browser.h | 2 +- > > 2 files changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c > > index 603d11283cbd..c4cdf2ea69b7 100644 > > --- a/tools/perf/ui/browser.c > > +++ b/tools/perf/ui/browser.c > > @@ -287,7 +287,8 @@ int ui_browser__show(struct ui_browser *browser, const char *title, > > mutex_lock(&ui__lock); > > __ui_browser__show_title(browser, title); > > > > - browser->title = title; > > + free(browser->title); > > + browser->title = strdup(title); > > zfree(&browser->helpline); > > > > va_start(ap, helpline); > > @@ -304,6 +305,7 @@ void ui_browser__hide(struct ui_browser *browser) > > mutex_lock(&ui__lock); > > ui_helpline__pop(); > > zfree(&browser->helpline); > > + zfree(&browser->title); > > mutex_unlock(&ui__lock); > > } > > > > diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h > > index 510ce4554050..6e98d5f8f71c 100644 > > --- a/tools/perf/ui/browser.h > > +++ b/tools/perf/ui/browser.h > > @@ -21,7 +21,7 @@ struct ui_browser { > > u8 extra_title_lines; > > int current_color; > > void *priv; > > - const char *title; > > + char *title; > > char *helpline; > > const char *no_samples_msg; > > void (*refresh_dimensions)(struct ui_browser *browser); > > -- > > 2.45.0.rc1.225.g2a3ae87e7f-goog