Re: [PATCH v3 01/16] tracing/filters: Fix regex_match_end() for zero-length strings

From
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date
2026-10-28 01:10:29
Reply to
sashiko-bot@kernel.org, 2026-10-28
On Wed, 28 Oct 2026 00:59:33 +0000, sashiko-bot@kernel.org [off-list ref] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] tracing/filters: redundant check in regex_match_end() makes patch a no-op
--

commit 8e400c22f46c7fff9d91b8c8e837ab24dfa0f5cd
Author: Masami Hiramatsu (Google) [off-list ref]

tracing/filters: Fix regex_match_end() for zero-length strings

This commit adds an early return in regex_match_end() when len <= r->len to
avoid underflowing len - 1 and accessing the input string when len is 0 or
smaller than the pattern.
quoted
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 5e74d2dae40a3..59a0d3ba72740 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1075,8 +1075,12 @@ static int regex_match_middle(char *str, struct regex *r, int len)
 
 static int regex_match_end(char *str, struct regex *r, int len)
 {
-	int strlen = len - 1;
+	int strlen;
 
+	if (len <= r->len)
+		return 0;
+
+	strlen = len - 1;
 	if (strlen >= r->len &&
 	    memcmp(str + strlen - r->len, r->pattern, r->len) == 0)
 		return 1;
[Severity: Medium]
Does this change have any functional effect in regex_match_end() in
kernel/trace/trace_events_filter.c?
Oops, right. Please drop this patch. This is my fault (I suggested).
quoted
+	if (len <= r->len)
and
quoted
 	if (strlen >= r->len &&
are the same...

Thanks!

-- 
Masami Hiramatsu (Google) [off-list ref]
Thread (30 messages) 30 messages, 3 authors, last reply 14d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help