Skip to contentSkip to conversation

perf auxtrace: Fix potential null pointer dereference

PATCH In review Leo Yan 2 participants 2 messages Apr 20, 2021 perf events

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH 1/1 perf auxtrace: Fix potential null pointer dereference

In the function auxtrace_parse_snapshot_options(), the callback pointer "itr->parse_snapshot_options" can be NULL if it has not been set during the AUX record initialization. This can cause tool crashing if the callback pointer "itr->parse_snapshot_options" is dereferenced without performing NULL check.

Add a NULL check for the pointer "itr->parse_snapshot_options" before invoke the callback.

Fixes d20031bb63dd ("perf tools: Add AUX area tracing Snapshot Mode")
---
 tools/perf/util/auxtrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/auxtrace.c +1 -1
index 953f4afacd3b..320b47f133d3 100644
@@ -638,7 +638,7 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
 		break;
 	}
 
-	if (itr)
+	if (itr && itr->parse_snapshot_options)
 		return itr->parse_snapshot_options(itr, opts, str);
 
 	pr_err("No AUX area tracing to snapshot\n");
Signature · 1 line
2.25.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Leo Yan

In the function auxtrace_parse_snapshot_options(), the callback pointer "itr->parse_snapshot_options" can be NULL if it has not been set during the AUX record initialization. This can cause tool crashing if the callback pointer "itr->parse_snapshot_options" is dereferenced without performing NULL check.

Add a NULL check for the pointer "itr->parse_snapshot_options" before invoke the callback.

Fixes d20031bb63dd ("perf tools: Add AUX area tracing Snapshot Mode")
Quoted 18 lines
---
 tools/perf/util/auxtrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/auxtrace.c +1 -1
index 953f4afacd3b..320b47f133d3 100644
@@ -638,7 +638,7 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
 		break;
 	}
 
-	if (itr)
+	if (itr && itr->parse_snapshot_options)
 		return itr->parse_snapshot_options(itr, opts, str);
 
 	pr_err("No AUX area tracing to snapshot\n");