Skip to content

Commit f770ed1

Browse files
melverpaulmckrcu
authored andcommitted
kcsan: Fix function matching in report
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 <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent d071e91 commit f770ed1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

kernel/kcsan/report.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ skip_report(enum kcsan_value_change value_change, unsigned long top_frame)
192192
* maintainers.
193193
*/
194194
char buf[64];
195+
int len = scnprintf(buf, sizeof(buf), "%ps", (void *)top_frame);
195196

196-
snprintf(buf, sizeof(buf), "%ps", (void *)top_frame);
197-
if (!strnstr(buf, "rcu_", sizeof(buf)) &&
198-
!strnstr(buf, "_rcu", sizeof(buf)) &&
199-
!strnstr(buf, "_srcu", sizeof(buf)))
197+
if (!strnstr(buf, "rcu_", len) &&
198+
!strnstr(buf, "_rcu", len) &&
199+
!strnstr(buf, "_srcu", len))
200200
return true;
201201
}
202202

@@ -262,15 +262,15 @@ static const char *get_thread_desc(int task_id)
262262
static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries)
263263
{
264264
char buf[64];
265+
int len;
265266
int skip = 0;
266267

267268
for (; skip < num_entries; ++skip) {
268-
snprintf(buf, sizeof(buf), "%ps", (void *)stack_entries[skip]);
269-
if (!strnstr(buf, "csan_", sizeof(buf)) &&
270-
!strnstr(buf, "tsan_", sizeof(buf)) &&
271-
!strnstr(buf, "_once_size", sizeof(buf))) {
269+
len = scnprintf(buf, sizeof(buf), "%ps", (void *)stack_entries[skip]);
270+
if (!strnstr(buf, "csan_", len) &&
271+
!strnstr(buf, "tsan_", len) &&
272+
!strnstr(buf, "_once_size", len))
272273
break;
273-
}
274274
}
275275
return skip;
276276
}

0 commit comments

Comments
 (0)