Skip to content

Commit 5200614

Browse files
author
Vasily Gorbik
committed
s390/ftrace: Use get/copy_from_kernel_nofault consistently
Use get/copy_from_kernel_nofault to access the kernel text consistently. Replace memcmp() in ftrace_init_nop() to ensure that in case of inconsistencies in the 'mcount' table, the kernel reports a failure instead of potentially crashing. Reviewed-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent efd9cd0 commit 5200614

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/s390/kernel/ftrace.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
7676
{
7777
static struct ftrace_hotpatch_trampoline *next_vmlinux_trampoline =
7878
__ftrace_hotpatch_trampolines_start;
79-
static const char orig[6] = { 0xc0, 0x04, 0x00, 0x00, 0x00, 0x00 };
79+
static const struct ftrace_insn orig = { .opc = 0xc004, .disp = 0 };
8080
static struct ftrace_hotpatch_trampoline *trampoline;
8181
struct ftrace_hotpatch_trampoline **next_trampoline;
8282
struct ftrace_hotpatch_trampoline *trampolines_end;
8383
struct ftrace_hotpatch_trampoline tmp;
8484
struct ftrace_insn *insn;
85+
struct ftrace_insn old;
8586
const char *shared;
8687
s32 disp;
8788

@@ -102,8 +103,10 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
102103
return -ENOMEM;
103104
trampoline = (*next_trampoline)++;
104105

106+
if (copy_from_kernel_nofault(&old, (void *)rec->ip, sizeof(old)))
107+
return -EFAULT;
105108
/* Check for the compiler-generated fentry nop (brcl 0, .). */
106-
if (WARN_ON_ONCE(memcmp((const void *)rec->ip, &orig, sizeof(orig))))
109+
if (WARN_ON_ONCE(memcmp(&orig, &old, sizeof(old))))
107110
return -EINVAL;
108111

109112
/* Generate the trampoline. */

0 commit comments

Comments
 (0)