Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ftrace: Do not blindly read the ip address in ftrace_bug()

It was reported that a bug on arm64 caused a bad ip address to be used for
updating into a nop in ftrace_init(), but the error path (rightfully)
returned -EINVAL and not -EFAULT, as the bug caused more than one error to
occur. But because -EINVAL was returned, the ftrace_bug() tried to report
what was at the location of the ip address, and read it directly. This
caused the machine to panic, as the ip was not pointing to a valid memory
address.

Instead, read the ip address with copy_from_kernel_nofault() to safely
access the memory, and if it faults, report that the address faulted,
otherwise report what was in that location.

Link: https://lore.kernel.org/lkml/20210607032329.28671-1-mark-pk.tsai@mediatek.com/

Cc: stable@vger.kernel.org
Fixes: 05736a427f7e1 ("ftrace: warn on failure to disable mcount callers")
Reported-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Tested-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

+7 -1
+7 -1
kernel/trace/ftrace.c
··· 1967 1967 1968 1968 static void print_ip_ins(const char *fmt, const unsigned char *p) 1969 1969 { 1970 + char ins[MCOUNT_INSN_SIZE]; 1970 1971 int i; 1972 + 1973 + if (copy_from_kernel_nofault(ins, p, MCOUNT_INSN_SIZE)) { 1974 + printk(KERN_CONT "%s[FAULT] %px\n", fmt, p); 1975 + return; 1976 + } 1971 1977 1972 1978 printk(KERN_CONT "%s", fmt); 1973 1979 1974 1980 for (i = 0; i < MCOUNT_INSN_SIZE; i++) 1975 - printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]); 1981 + printk(KERN_CONT "%s%02x", i ? ":" : "", ins[i]); 1976 1982 } 1977 1983 1978 1984 enum ftrace_bug_type ftrace_bug_type;