kprobes/x86: Check for invalid ftrace location in __recover_probed_insn()
PATCH 1/1 kprobes/x86: Check for invalid ftrace location in __recover_probed_insn()
__recover_probed_insn() should always be called from an address where an instructions starts. The check for ftrace_location() might help to discover a potential inconsistency. Something goes terribly wrong when an address inside the ftrace location is checked. Let's BUG() in this case.
--- arch/x86/kernel/kprobes/core.c | 6 ++++++ 1 file changed, 6 insertions(+)
This is follow up for the patch ("[PATCH v2] kprobes/x86: Use 5-byte NOP when the code might be modified by ftrace") based on the Masami's suggestion, see https://lkml.org/lkml/2015/2/3/207
Let me know if I should merge this with the first patch and send v3.
arch/x86/kernel/kprobes/core.c +6 -0
@@ -228,6 +228,12 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr) kp =get_kprobe ((void *)addr); faddr =ftrace_location (addr);/* +* Addresses inside the ftrace location are refused by +* arch_check_ftrace_location(). Something went terribly wrong +* if such an address is checked here. +*/ +BUG_ON (faddr && faddr != addr); +/* * Use the current code if it is not modified by Kprobe * and it cannot be modified by ftrace. */
Signature · 1 line
1.8.5.6
Quoted 4 lines · Petr Mladek
__recover_probed_insn()should always be called from an address where an instructions starts. The check forftrace_location()might help to discover a potential inconsistency. Something goes terribly wrong when an address inside the ftrace location is checked. Let'sBUG()in this case.
Looks good to me :)
Thank you,
Quoted 33 lines
Suggested-by Masami Hiramatsu <[email protected]>Signed-off-by Petr Mladek <[email protected]>--- arch/x86/kernel/kprobes/core.c | 6 ++++++ 1 file changed, 6 insertions(+)This is follow up for the patch ("[PATCH v2] kprobes/x86: Use 5-byte NOP when the code might be modified by ftrace") based on the Masami's suggestion, see https://lkml.org/lkml/2015/2/3/207
Let me know if I should merge this with the first patch and send v3.
arch/x86/kernel/kprobes/core.c +6
-0@@ -228,6 +228,12 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr) kp =get_kprobe ((void *)addr); faddr =ftrace_location (addr);/* +* Addresses inside the ftrace location are refused by +* arch_check_ftrace_location(). Something went terribly wrong +* if such an address is checked here. +*/ +BUG_ON (faddr && faddr != addr); +/* * Use the current code if it is not modified by Kprobe * and it cannot be modified by ftrace. */
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]