Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp96466lqo; Tue, 7 May 2024 13:21:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtvJ77Dipi3UwAKaR3cNc4yfhwhC0D7qyz+PdHNRLUH4cM5FQjr4WowycJwV/vtcr/guXlg8xl4NhGyhCGYZ3Cj8nV34q6YIcps7Ixyg== X-Google-Smtp-Source: AGHT+IEBtPGML0MCp6hhfdWgdfEYYdisbejXRxxzoqbdUeLOkKtUHRWZXMe516n4XKMVLMw6QYGf X-Received: by 2002:a50:8d4c:0:b0:56d:f3a7:60e with SMTP id 4fb4d7f45d1cf-5731d9d0f35mr431034a12.22.1715113267754; Tue, 07 May 2024 13:21:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715113267; cv=pass; d=google.com; s=arc-20160816; b=MC2U/L+mR5VcoilS3Dj01qUpOlnn/dn0YSe6Jz2CSEeSUch37vyJynGAZ1r7Z/+yAn 2P+uX1OPYczMz0vyWFoDPsh67oRLb2MUf5YN9iVrj6J3WGhXUx1jsL4mr9S6cRDiQK4D znicjHfkXFB1yMDhK9eAusAputbZrkpclf0sh4T2/0EHb2ctIFGOQw6pE3NYk1KMHQSD wjcRrYPdvkSy/FeR8J3ws4/G/KpBGCtc6PIpVsQ83Hv8QvXpXrE99KqBJF4kNwXGrb9Y mjy2EAKfvNWj3uC2REKcQ7+1GHI6TY+W/lsxBOmAD27ZKoeK8rxX3tjUHRHtpeWmPZlj Vaiw== 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=GHOVHW0r1NM/hgo3TKnyYATkc/DSteofcLnRF5Y6/3s=; fh=YvR0+rgjGlqqFjlZ5QPM77BW06x/W8UL2iScm9rsdi0=; b=ZqG94JGXaBbnNJkcn/r+Tqnqj49oVyf5ozAdzI/3Ftzw3yKBJs71iGlfzD/KGphOUG mLP1yLxJrcfOl9q+wPTxorWyFk5d/IpjVlo9GWpmGi3gGeWN23LseRic+m7QZwq4BA9A U/ZvfM+yW7uEsmnYvTKa6K6HmHH1c5QJg7vLSRcG505FzlXC4cJswkDa7n3Nee1K6mrG b0lluOX5IgZhbz0Vva6TicdZ3fKXgDE4PRR1uhpapAaGmEm8tZ6lOoSz5ILFwwjgvSO/ iSHIBld07VdLssYQJFT9WeYWeYFBY7dVyqkLvZk2B+Xkxo05ZkjpT8TSPwNN7294i8KR V/jw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XgrRuc0v; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172138-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172138-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 y9-20020a056402440900b00572e75e3893si4176050eda.259.2024.05.07.13.21.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 13:21:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172138-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=XgrRuc0v; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172138-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172138-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 798271F21691 for ; Tue, 7 May 2024 20:21:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94BBA18734F; Tue, 7 May 2024 20:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XgrRuc0v" 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 BC35718733D; Tue, 7 May 2024 20:20:59 +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=1715113259; cv=none; b=DxZ7vnaqAUMU12/jXW8jIOSbYP4DBAevZevLOmG0nhQms+l3lCeV+hiSWIGQ1q1BZVf6xI8ru3g8YJn5HE6xnPV2viAkqSNC9UhXKJ5oI2IosX+d4TbmleexJFUODKH8lgIpZyJWbfUjzc0UticQkboM/3GbhgvNneB7yQMKp5c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715113259; c=relaxed/simple; bh=qgkgWJ6hcc+kLK5jJ2rjoDUnCXJexR2EWKimTvT98Qs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bADa8Tlg8usKCk+Ldn4fo4W7yg0hZ+XjcvckELxtxigP4A8U5bZNoaLOeyg9AMYTCJfEh+p8QndfRBN7x9LzaWRjCk+zJGwkrX5WV1eLCskDKTHvJH5A+ieMxQLltw+PvOLJH180qM7fu85aaN+122tsE6G3Wm/K0VLN5McRy+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XgrRuc0v; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4BD5C2BBFC; Tue, 7 May 2024 20:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715113259; bh=qgkgWJ6hcc+kLK5jJ2rjoDUnCXJexR2EWKimTvT98Qs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XgrRuc0vDNKHe1SLI2TEjr6N1r1ndxQH6wjicKasHQzQT6m3T1CPhuTRVW7dgRddM tMJ5O0A9/HFOSPuCo5nD1OEDitxNen0+WvpjTEHGux/GYjc79Ey61nQWCtzvtVsEXe d4kFgtMLoxbk8PyLoU4Ty/M0zDHHoD+EUSMkX8h+UhSlA5OU/4v269RsvA9wRlaJnP tWYkxoCaBFOCwG7IlnNacHUzKhSFYoFmtFhDfwBU1mn1lC2nukdwUUYWTTF7ycGnX8 QAes6I53KVDdIitBmvqJDsJaa8C70zdWUUYgVJxlce8LHIQSkoPM0+BlzYErzlYpX1 A6kfCCBZUOF2w== Date: Tue, 7 May 2024 17:20:56 -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: <20240507183545.1236093-2-irogers@google.com> 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"? - 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