linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] perf probe: Added protection to avoid endless loop
@ 2021-02-03 14:57 Jianlin Lv
  2021-02-03 15:08 ` Masami Hiramatsu
  0 siblings, 1 reply; 3+ messages in thread
From: Jianlin Lv @ 2021-02-03 14:57 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, mhiramat, srikar, adrian.hunter
  Cc: Jianlin.Lv, linux-kernel

if dwarf_offdie() return NULL, the continue statement forces the next
iteration of the loop without update variable off. It will cause an
endless loop in the process of traversing the compilation unit.
So added exception protection for loop CUs.

Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
---
v2: removed the statement that updates variable in the function argument.
---
 tools/perf/util/probe-finder.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 76dd349aa48d..1b118c9c86a6 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -1187,8 +1187,10 @@ static int debuginfo__find_probe_location(struct debuginfo *dbg,
 	while (!dwarf_nextcu(dbg->dbg, off, &noff, &cuhl, NULL, NULL, NULL)) {
 		/* Get the DIE(Debugging Information Entry) of this CU */
 		diep = dwarf_offdie(dbg->dbg, off + cuhl, &pf->cu_die);
-		if (!diep)
+		if (!diep) {
+			off = noff;
 			continue;
+		}
 
 		/* Check if target file is included. */
 		if (pp->file)
@@ -1949,8 +1951,10 @@ int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr)
 
 		/* Get the DIE(Debugging Information Entry) of this CU */
 		diep = dwarf_offdie(dbg->dbg, off + cuhl, &lf.cu_die);
-		if (!diep)
+		if (!diep) {
+			off = noff;
 			continue;
+		}
 
 		/* Check if target file is included. */
 		if (lr->file)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf probe: Added protection to avoid endless loop
  2021-02-03 14:57 [PATCH v2] perf probe: Added protection to avoid endless loop Jianlin Lv
@ 2021-02-03 15:08 ` Masami Hiramatsu
  2021-02-03 16:22   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Masami Hiramatsu @ 2021-02-03 15:08 UTC (permalink / raw)
  To: Jianlin Lv
  Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, srikar, adrian.hunter, linux-kernel

On Wed,  3 Feb 2021 22:57:02 +0800
Jianlin Lv <Jianlin.Lv@arm.com> wrote:

> if dwarf_offdie() return NULL, the continue statement forces the next
> iteration of the loop without update variable off. It will cause an
> endless loop in the process of traversing the compilation unit.
> So added exception protection for loop CUs.
> 

Thanks for the quick update!

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thank you,

> Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
> ---
> v2: removed the statement that updates variable in the function argument.
> ---
>  tools/perf/util/probe-finder.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 76dd349aa48d..1b118c9c86a6 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -1187,8 +1187,10 @@ static int debuginfo__find_probe_location(struct debuginfo *dbg,
>  	while (!dwarf_nextcu(dbg->dbg, off, &noff, &cuhl, NULL, NULL, NULL)) {
>  		/* Get the DIE(Debugging Information Entry) of this CU */
>  		diep = dwarf_offdie(dbg->dbg, off + cuhl, &pf->cu_die);
> -		if (!diep)
> +		if (!diep) {
> +			off = noff;
>  			continue;
> +		}
>  
>  		/* Check if target file is included. */
>  		if (pp->file)
> @@ -1949,8 +1951,10 @@ int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr)
>  
>  		/* Get the DIE(Debugging Information Entry) of this CU */
>  		diep = dwarf_offdie(dbg->dbg, off + cuhl, &lf.cu_die);
> -		if (!diep)
> +		if (!diep) {
> +			off = noff;
>  			continue;
> +		}
>  
>  		/* Check if target file is included. */
>  		if (lr->file)
> -- 
> 2.25.1
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf probe: Added protection to avoid endless loop
  2021-02-03 15:08 ` Masami Hiramatsu
@ 2021-02-03 16:22   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-02-03 16:22 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Jianlin Lv, peterz, mingo, mark.rutland, alexander.shishkin,
	jolsa, namhyung, srikar, adrian.hunter, linux-kernel

Em Thu, Feb 04, 2021 at 12:08:14AM +0900, Masami Hiramatsu escreveu:
> On Wed,  3 Feb 2021 22:57:02 +0800
> Jianlin Lv <Jianlin.Lv@arm.com> wrote:
> 
> > if dwarf_offdie() return NULL, the continue statement forces the next
> > iteration of the loop without update variable off. It will cause an
> > endless loop in the process of traversing the compilation unit.
> > So added exception protection for loop CUs.
> > 
> 
> Thanks for the quick update!
> 
> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks, applied.

- Arnaldo

 
> Thank you,
> 
> > Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
> > ---
> > v2: removed the statement that updates variable in the function argument.
> > ---
> >  tools/perf/util/probe-finder.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> > index 76dd349aa48d..1b118c9c86a6 100644
> > --- a/tools/perf/util/probe-finder.c
> > +++ b/tools/perf/util/probe-finder.c
> > @@ -1187,8 +1187,10 @@ static int debuginfo__find_probe_location(struct debuginfo *dbg,
> >  	while (!dwarf_nextcu(dbg->dbg, off, &noff, &cuhl, NULL, NULL, NULL)) {
> >  		/* Get the DIE(Debugging Information Entry) of this CU */
> >  		diep = dwarf_offdie(dbg->dbg, off + cuhl, &pf->cu_die);
> > -		if (!diep)
> > +		if (!diep) {
> > +			off = noff;
> >  			continue;
> > +		}
> >  
> >  		/* Check if target file is included. */
> >  		if (pp->file)
> > @@ -1949,8 +1951,10 @@ int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr)
> >  
> >  		/* Get the DIE(Debugging Information Entry) of this CU */
> >  		diep = dwarf_offdie(dbg->dbg, off + cuhl, &lf.cu_die);
> > -		if (!diep)
> > +		if (!diep) {
> > +			off = noff;
> >  			continue;
> > +		}
> >  
> >  		/* Check if target file is included. */
> >  		if (lr->file)
> > -- 
> > 2.25.1
> > 
> 
> 
> -- 
> Masami Hiramatsu <mhiramat@kernel.org>

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-03 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 14:57 [PATCH v2] perf probe: Added protection to avoid endless loop Jianlin Lv
2021-02-03 15:08 ` Masami Hiramatsu
2021-02-03 16:22   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).