]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tracing/filters: Fix false positive match in regex_match_full()
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 29 Jul 2026 00:28:07 +0000 (09:28 +0900)
committerSteven Rostedt <rostedt@goodmis.org>
Wed, 29 Jul 2026 18:32:11 +0000 (14:32 -0400)
regex_match_full() calls strncmp(str, r->pattern, len) where len is the
target field buffer size. When len is smaller than r->len (the filter
pattern length), strncmp() checks only len bytes of r->pattern against
str. If those len bytes match, strncmp() returns 0, resulting in a
false-positive match where a shorter string in a fixed-size field
matches a longer filter pattern.

For example, a 4-byte static string field containing "abcd" matched the
filter pattern "abcdefgh" because strncmp("abcd", "abcdefgh", 4)
returned 0. In this case, @len does NOT include '\0' because it is
fixed-size array.

Fix this by returning 0 (no match) early when len < r->len.

Fixes: 1889d20922d1 ("tracing/filters: Provide basic regex support")
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/178528488779.124250.5571741156199253769.stgit@devnote2
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace_events_filter.c

index 6385cd662d8d16658c965fe3ddda25da8c842394..2b46ca5360458b98b34b1fd141ca46656b68ca08 100644 (file)
@@ -1027,6 +1027,9 @@ static int regex_match_full(char *str, struct regex *r, int len)
        if (!len)
                return strcmp(str, r->pattern) == 0;
 
+       if (len < r->len)
+               return 0;
+
        return strncmp(str, r->pattern, len) == 0;
 }