[PATCH v2 01/11] perf debug: Avoid stack overflow in recursive error message

Ian Rogers posted 11 patches 9 months, 3 weeks ago
[PATCH v2 01/11] perf debug: Avoid stack overflow in recursive error message
Posted by Ian Rogers 9 months, 3 weeks ago
In debug_file, pr_warning_once is called on error. As that function
calls debug_file the function will yield a stack overflow. Switch the
location of the call so the recursion is avoided.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 995f6bb05b5f..f9ef7d045c92 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -46,8 +46,8 @@ int debug_type_profile;
 FILE *debug_file(void)
 {
 	if (!_debug_file) {
-		pr_warning_once("debug_file not set");
 		debug_set_file(stderr);
+		pr_warning_once("debug_file not set");
 	}
 	return _debug_file;
 }
-- 
2.48.1.711.g2feabab25a-goog
Re: [PATCH v2 01/11] perf debug: Avoid stack overflow in recursive error message
Posted by Arnaldo Carvalho de Melo 9 months, 2 weeks ago
On Fri, Feb 28, 2025 at 02:22:58PM -0800, Ian Rogers wrote:
> In debug_file, pr_warning_once is called on error. As that function
> calls debug_file the function will yield a stack overflow. Switch the
> location of the call so the recursion is avoided.
> 
> Reviewed-by: Howard Chu <howardchu95@gmail.com>
> Signed-off-by: Ian Rogers <irogers@google.com>

Good to add this so that stable picks it:

Fixes: ec49230cf6dda704 ("perf debug: Expose debug file")

- Arnaldo

> ---
>  tools/perf/util/debug.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
> index 995f6bb05b5f..f9ef7d045c92 100644
> --- a/tools/perf/util/debug.c
> +++ b/tools/perf/util/debug.c
> @@ -46,8 +46,8 @@ int debug_type_profile;
>  FILE *debug_file(void)
>  {
>  	if (!_debug_file) {
> -		pr_warning_once("debug_file not set");
>  		debug_set_file(stderr);
> +		pr_warning_once("debug_file not set");
>  	}
>  	return _debug_file;
>  }
> -- 
> 2.48.1.711.g2feabab25a-goog
Re: [PATCH v2 01/11] perf debug: Avoid stack overflow in recursive error message
Posted by Arnaldo Carvalho de Melo 9 months, 2 weeks ago
On Mon, Mar 10, 2025 at 05:22:16PM -0300, Arnaldo Carvalho de Melo wrote:
> On Fri, Feb 28, 2025 at 02:22:58PM -0800, Ian Rogers wrote:
> > In debug_file, pr_warning_once is called on error. As that function
> > calls debug_file the function will yield a stack overflow. Switch the
> > location of the call so the recursion is avoided.
> > 
> > Reviewed-by: Howard Chu <howardchu95@gmail.com>
> > Signed-off-by: Ian Rogers <irogers@google.com>
> 
> Good to add this so that stable picks it:
> 
> Fixes: ec49230cf6dda704 ("perf debug: Expose debug file")

Forgot to add:

Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
 
- Arnaldo
> 
> > ---
> >  tools/perf/util/debug.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
> > index 995f6bb05b5f..f9ef7d045c92 100644
> > --- a/tools/perf/util/debug.c
> > +++ b/tools/perf/util/debug.c
> > @@ -46,8 +46,8 @@ int debug_type_profile;
> >  FILE *debug_file(void)
> >  {
> >  	if (!_debug_file) {
> > -		pr_warning_once("debug_file not set");
> >  		debug_set_file(stderr);
> > +		pr_warning_once("debug_file not set");
> >  	}
> >  	return _debug_file;
> >  }
> > -- 
> > 2.48.1.711.g2feabab25a-goog