kcsan: Fix function matching in report
authorMarco Elver <elver@google.com>
Fri, 10 Apr 2020 16:44:17 +0000 (18:44 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Tue, 14 Apr 2020 00:18:15 +0000 (17:18 -0700)
Pass string length as returned by scnprintf() to strnstr(), since
strnstr() searches exactly len bytes in haystack, even if it contains a
NUL-terminator before haystack+len.

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/kcsan/report.c

index ddc18f1224a4015ded9c9ca85fd34250a8a66da4..cf41d63dd0cdfb1669fe0b630aad4dafb521fa36 100644 (file)
@@ -192,11 +192,11 @@ skip_report(enum kcsan_value_change value_change, unsigned long top_frame)
                 * maintainers.
                 */
                char buf[64];
+               int len = scnprintf(buf, sizeof(buf), "%ps", (void *)top_frame);
 
-               snprintf(buf, sizeof(buf), "%ps", (void *)top_frame);
-               if (!strnstr(buf, "rcu_", sizeof(buf)) &&
-                   !strnstr(buf, "_rcu", sizeof(buf)) &&
-                   !strnstr(buf, "_srcu", sizeof(buf)))
+               if (!strnstr(buf, "rcu_", len) &&
+                   !strnstr(buf, "_rcu", len) &&
+                   !strnstr(buf, "_srcu", len))
                        return true;
        }
 
@@ -262,15 +262,15 @@ static const char *get_thread_desc(int task_id)
 static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries)
 {
        char buf[64];
+       int len;
        int skip = 0;
 
        for (; skip < num_entries; ++skip) {
-               snprintf(buf, sizeof(buf), "%ps", (void *)stack_entries[skip]);
-               if (!strnstr(buf, "csan_", sizeof(buf)) &&
-                   !strnstr(buf, "tsan_", sizeof(buf)) &&
-                   !strnstr(buf, "_once_size", sizeof(buf))) {
+               len = scnprintf(buf, sizeof(buf), "%ps", (void *)stack_entries[skip]);
+               if (!strnstr(buf, "csan_", len) &&
+                   !strnstr(buf, "tsan_", len) &&
+                   !strnstr(buf, "_once_size", len))
                        break;
-               }
        }
        return skip;
 }