• Jessica Yu's avatar
    kprobes: Propagate error from arm_kprobe_ftrace() · 12310e34
    Jessica Yu authored
    Improve error handling when arming ftrace-based kprobes. Specifically, if
    we fail to arm a ftrace-based kprobe, register_kprobe()/enable_kprobe()
    should report an error instead of success. Previously, this has lead to
    confusing situations where register_kprobe() would return 0 indicating
    success, but the kprobe would not be functional if ftrace registration
    during the kprobe arming process had failed. We should therefore take any
    errors returned by ftrace into account and propagate this error so that we
    do not register/enable kprobes that cannot be armed. This can happen if,
    for example, register_ftrace_function() finds an IPMODIFY conflict (since
    kprobe_ftrace_ops has this flag set) and returns an error. Such a conflict
    is possible since livepatches also set the IPMODIFY flag for their ftrace_ops.
    
    arm_all_kprobes() keeps its current behavior and attempts to arm all
    kprobes. It returns the last encountered error and gives a warning if
    not all probes could be armed.
    
    This patch is based on Petr Mladek's original patchset (patches 2 and 3)
    back in 2015, which improved kprobes error handling, found here:
    
       https://lkml.org/lkml/2015/2/26/452
    
    However, further work on this had been paused since then and the patches
    were not upstreamed.
    Based-on-patches-by: default avatarPetr Mladek <pmladek@suse.com>
    Signed-off-by: default avatarJessica Yu <jeyu@kernel.org>
    Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
    Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
    Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
    Cc: David S . Miller <davem@davemloft.net>
    Cc: Jiri Kosina <jikos@kernel.org>
    Cc: Joe Lawrence <joe.lawrence@redhat.com>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Miroslav Benes <mbenes@suse.cz>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: live-patching@vger.kernel.org
    Link: http://lkml.kernel.org/r/20180109235124.30886-2-jeyu@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    12310e34
kprobes.c 63.8 KB