]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/ftrace: Use get/copy_from_kernel_nofault consistently
authorVasily Gorbik <gor@linux.ibm.com>
Wed, 28 Aug 2024 17:06:58 +0000 (19:06 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Thu, 29 Aug 2024 20:56:34 +0000 (22:56 +0200)
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 <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/kernel/ftrace.c

index 03eadf7d098e350ba8af1fe50fa07df9d0fe5213..5ae1bf6167bfbc8e365b959e5f28aa8eacf150b1 100644 (file)
@@ -76,12 +76,13 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
 {
        static struct ftrace_hotpatch_trampoline *next_vmlinux_trampoline =
                __ftrace_hotpatch_trampolines_start;
-       static const char orig[6] = { 0xc0, 0x04, 0x00, 0x00, 0x00, 0x00 };
+       static const struct ftrace_insn orig = { .opc = 0xc004, .disp = 0 };
        static struct ftrace_hotpatch_trampoline *trampoline;
        struct ftrace_hotpatch_trampoline **next_trampoline;
        struct ftrace_hotpatch_trampoline *trampolines_end;
        struct ftrace_hotpatch_trampoline tmp;
        struct ftrace_insn *insn;
+       struct ftrace_insn old;
        const char *shared;
        s32 disp;
 
@@ -102,8 +103,10 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
                return -ENOMEM;
        trampoline = (*next_trampoline)++;
 
+       if (copy_from_kernel_nofault(&old, (void *)rec->ip, sizeof(old)))
+               return -EFAULT;
        /* Check for the compiler-generated fentry nop (brcl 0, .). */
-       if (WARN_ON_ONCE(memcmp((const void *)rec->ip, &orig, sizeof(orig))))
+       if (WARN_ON_ONCE(memcmp(&orig, &old, sizeof(old))))
                return -EINVAL;
 
        /* Generate the trampoline. */