mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf iostat: Reject incomplete and out-of-range port strings
@ 2026-11-06  2:20 lirongqing
  2026-11-10  2:52 ` Namhyung Kim
  0 siblings, 1 reply; 2+ messages in thread
From: lirongqing @ 2026-11-06  2:20 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark, Li RongQing,
	Alexander Antonov, linux-perf-users, linux-kernel

From: Li RongQing <lirongqing@baidu.com>

The root port regular expression accepts trailing characters and an
unbounded domain field. A nine-digit domain matches it but makes the
subsequent width-limited sscanf() stop before the bus. The parser still
returns success, allowing the filter to use an uninitialized or stale
bus value. A three-digit bus is silently truncated as well.

Match the complete notation within the documented domain and bus widths.
Check regular expression compilation and propagate conversion failures
instead of treating a warning as successful parsing.

Fixes: f9ed693e8bc0 ("perf stat: Enable iostat mode for x86 platforms")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 tools/perf/arch/x86/util/iostat.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c
index f8b4939..7dc31f5 100644
--- a/tools/perf/arch/x86/util/iostat.c
+++ b/tools/perf/arch/x86/util/iostat.c
@@ -251,9 +251,14 @@ static int iio_root_port_parse_str(u32 *domain, u8 *bus, char *str)
 	 * Valid bus range [0:ff]
 	 * Example: 0000:af, 0:3d, 01:7
 	 */
-	regcomp(&regex, "^([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})", REG_EXTENDED);
+	ret = regcomp(&regex, "^([a-f0-9A-F]{1,4}):([a-f0-9A-F]{1,2})$",
+		      REG_EXTENDED);
+	if (ret)
+		return ret;
 	ret = regexec(&regex, str, 0, NULL, 0);
-	if (ret || sscanf(str, "%08x:%02hhx", domain, bus) != 2)
+	if (!ret && sscanf(str, "%04x:%02hhx", domain, bus) != 2)
+		ret = -EINVAL;
+	if (ret)
 		pr_warning("Unrecognized root port format: %s\n"
 			   "Please use the following format:\n"
 			   "\t [domain]:[bus]\n"
-- 
2.9.4


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

end of thread, other threads:[~2026-11-10  2:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06  2:20 [PATCH] perf iostat: Reject incomplete and out-of-range port strings lirongqing
2026-11-10  2:52 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®