^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/error-injection.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) void override_function_with_return(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 'regs' represents the state on entry of a predefined function in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * the kernel/module and which is captured on a kprobe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * When kprobe returns back from exception it will override the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * of probed function and directly return to the predefined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * function's caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) instruction_pointer_set(regs, procedure_link_pointer(regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) NOKPROBE_SYMBOL(override_function_with_return);