Skip to contentSkip to conversation

perf probe: Added protection to avoid endless loop

PATCH Applied Jianlin Lv 3 participants 3 messages Feb 3, 2021 perf events

lore
Share & tools
lore

Jianlin Lv

author
#0 lore raw

PATCH v2 1/1 perf probe: Added protection to avoid endless loop

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.

---
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(-)
tools/perf/util/probe-finder.c +6 -2
index 76dd349aa48d..1b118c9c86a6 100644
@@ -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)
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#1 lore raw
Quoted 5 lines · On Wed, 3 Feb 2021 22:57:02 +0800 Jianlin Lv <[email protected]> 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!

Thank you,

Quoted 38 lines

---
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(-)
tools/perf/util/probe-finder.c +6 -2
index 76dd349aa48d..1b118c9c86a6 100644
@@ -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)
Signature · 1 line
2.25.1
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer Applied
#2 lore raw

Em Thu, Feb 04, 2021 at 12:08:14AM +0900, Masami Hiramatsu escreveu:

Quoted 9 lines
Quoted 5 lines · On Wed, 3 Feb 2021 22:57:02 +0800 Jianlin Lv <[email protected]> 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.

Quoted 3 lines

Thanks for the quick update!

Thanks, applied.

- Arnaldo

Quoted 44 lines

Thank you,

Quoted 38 lines

---
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(-)
tools/perf/util/probe-finder.c +6 -2
index 76dd349aa48d..1b118c9c86a6 100644
@@ -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)
Signature · 1 line
2.25.1
Signature · 1 line
Masami Hiramatsu <[email protected]>
Signature · 1 line
- Arnaldo