Skip to content

Commit ee92fa4

Browse files
Chen Zhongjinrostedt
authored andcommitted
ftrace: Fix invalid address access in lookup_rec() when index is 0
KASAN reported follow problem: BUG: KASAN: use-after-free in lookup_rec Read of size 8 at addr ffff000199270ff0 by task modprobe CPU: 2 Comm: modprobe Call trace: kasan_report __asan_load8 lookup_rec ftrace_location arch_check_ftrace_location check_kprobe_address_safe register_kprobe When checking pg->records[pg->index - 1].ip in lookup_rec(), it can get a pg which is newly added to ftrace_pages_start in ftrace_process_locs(). Before the first pg->index++, index is 0 and accessing pg->records[-1].ip will cause this problem. Don't check the ip when pg->index is 0. Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: [email protected] Fixes: 9644302 ("ftrace: Speed up search by skipping pages by address") Suggested-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Chen Zhongjin <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 9f116f7 commit ee92fa4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/trace/ftrace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
15371537
key.flags = end; /* overload flags, as it is unsigned long */
15381538

15391539
for (pg = ftrace_pages_start; pg; pg = pg->next) {
1540-
if (end < pg->records[0].ip ||
1540+
if (pg->index == 0 ||
1541+
end < pg->records[0].ip ||
15411542
start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE))
15421543
continue;
15431544
rec = bsearch(&key, pg->records, pg->index,

0 commit comments

Comments
 (0)