| 1 |
# kexec_file_load ____________________________________________ |
| 2 |
# The kexec_file_load() system call first appeared in Linux 3.17 |
| 3 |
# SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, |
| 4 |
# unsigned long, cmdline_len, const char __user *, cmdline_ptr, |
| 5 |
# unsigned long, flags) |
| 6 |
|
| 7 |
@define _SYSCALL_KEXEC_FILE_LOAD_NAME |
| 8 |
%( |
| 9 |
name = "kexec_file_load" |
| 10 |
%) |
| 11 |
|
| 12 |
@define _SYSCALL_KEXEC_FILE_LOAD_ARGSTR |
| 13 |
%( |
| 14 |
argstr = sprintf("%d, %d, %u, %s, %s", kernel_fd, initrd_fd, cmdline_len, |
| 15 |
cmdline, flags_str) |
| 16 |
%) |
| 17 |
|
| 18 |
@define _SYSCALL_KEXEC_FILE_LOAD_REGARGS |
| 19 |
%( |
| 20 |
kernel_fd = int_arg(1) |
| 21 |
initrd_fd = int_arg(2) |
| 22 |
cmdline_len = ulong_arg(3) |
| 23 |
cmdline = user_string_quoted(pointer_arg(4)) |
| 24 |
cmdline_unquoted = user_string_nofault(pointer_arg(4)) |
| 25 |
flags = ulong_arg(5) |
| 26 |
flags_str = _kexec_file_load_flags_str(flags) |
| 27 |
%) |
| 28 |
|
| 29 |
@define _SYSCALL_KEXEC_FILE_LOAD_REGARGS_STORE |
| 30 |
%( |
| 31 |
if (@probewrite(kernel_fd)) |
| 32 |
set_int_arg(1, kernel_fd) |
| 33 |
|
| 34 |
if (@probewrite(initrd_fd)) |
| 35 |
set_int_arg(2, initrd_fd) |
| 36 |
|
| 37 |
if (@probewrite(cmdline_len)) |
| 38 |
set_ulong_arg(3, cmdline_len) |
| 39 |
|
| 40 |
if (@probewrite(cmdline_unquoted)) |
| 41 |
set_user_string_arg(pointer_arg(4), cmdline_unquoted) |
| 42 |
|
| 43 |
if (@probewrite(flags)) |
| 44 |
set_ulong_arg(5, flags) |
| 45 |
%) |
| 46 |
|
| 47 |
probe syscall.kexec_file_load = dw_syscall.kexec_file_load !, nd_syscall.kexec_file_load ? {} |
| 48 |
probe syscall.kexec_file_load.return = dw_syscall.kexec_file_load.return !, nd_syscall.kexec_file_load.return ? {} |
| 49 |
|
| 50 |
# dw_kexec_file_load _____________________________________________________ |
| 51 |
|
| 52 |
probe dw_syscall.kexec_file_load = kernel.function("sys_kexec_file_load").call ? |
| 53 |
{ |
| 54 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 55 |
kernel_fd = __int32($kernel_fd) |
| 56 |
initrd_fd = __int32($initrd_fd) |
| 57 |
cmdline_len = @__compat_ulong($cmdline_len) |
| 58 |
cmdline = user_string_quoted($cmdline_ptr) |
| 59 |
flags = @__compat_ulong($flags) |
| 60 |
flags_str = _kexec_file_load_flags_str(flags) |
| 61 |
@_SYSCALL_KEXEC_FILE_LOAD_ARGSTR |
| 62 |
} |
| 63 |
probe dw_syscall.kexec_file_load.return = |
| 64 |
kernel.function("sys_kexec_file_load").return ? |
| 65 |
{ |
| 66 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 67 |
@SYSC_RETVALSTR($return) |
| 68 |
} |
| 69 |
|
| 70 |
# nd_kexec_file_load _____________________________________________________ |
| 71 |
|
| 72 |
probe nd_syscall.kexec_file_load = nd1_syscall.kexec_file_load!, nd2_syscall.kexec_file_load!, tp_syscall.kexec_file_load |
| 73 |
{ } |
| 74 |
|
| 75 |
probe nd1_syscall.kexec_file_load = kprobe.function("sys_kexec_file_load") ? |
| 76 |
{ |
| 77 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 78 |
@_SYSCALL_KEXEC_FILE_LOAD_REGARGS |
| 79 |
@_SYSCALL_KEXEC_FILE_LOAD_ARGSTR |
| 80 |
} |
| 81 |
|
| 82 |
/* kernel 4.17+ */ |
| 83 |
probe nd2_syscall.kexec_file_load = kprobe.function(@arch_syscall_prefix "sys_kexec_file_load") ? |
| 84 |
{ |
| 85 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 86 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 87 |
@_SYSCALL_KEXEC_FILE_LOAD_REGARGS |
| 88 |
@_SYSCALL_KEXEC_FILE_LOAD_ARGSTR |
| 89 |
}, |
| 90 |
{ |
| 91 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_KEXEC_FILE_LOAD_REGARGS_STORE %) |
| 92 |
} |
| 93 |
|
| 94 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 95 |
probe tp_syscall.kexec_file_load = kernel.trace("sys_enter") |
| 96 |
{ |
| 97 |
__set_syscall_pt_regs($regs) |
| 98 |
@__syscall_compat_gate(@const("__NR_kexec_file_load"), @const("__NR_compat_kexec_file_load")) |
| 99 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 100 |
@_SYSCALL_KEXEC_FILE_LOAD_REGARGS |
| 101 |
@_SYSCALL_KEXEC_FILE_LOAD_ARGSTR |
| 102 |
}, |
| 103 |
{ |
| 104 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_KEXEC_FILE_LOAD_REGARGS_STORE %) |
| 105 |
} |
| 106 |
|
| 107 |
probe nd_syscall.kexec_file_load.return = nd1_syscall.kexec_file_load.return!, nd2_syscall.kexec_file_load.return!, tp_syscall.kexec_file_load.return |
| 108 |
{ } |
| 109 |
|
| 110 |
probe nd1_syscall.kexec_file_load.return = |
| 111 |
kprobe.function("sys_kexec_file_load").return ? |
| 112 |
{ |
| 113 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 114 |
@SYSC_RETVALSTR(returnval()) |
| 115 |
} |
| 116 |
|
| 117 |
/* kernel 4.17+ */ |
| 118 |
probe nd2_syscall.kexec_file_load.return = kprobe.function(@arch_syscall_prefix "sys_kexec_file_load").return ? |
| 119 |
{ |
| 120 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 121 |
@SYSC_RETVALSTR(returnval()) |
| 122 |
} |
| 123 |
|
| 124 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 125 |
probe tp_syscall.kexec_file_load.return = kernel.trace("sys_exit") |
| 126 |
{ |
| 127 |
__set_syscall_pt_regs($regs) |
| 128 |
@__syscall_compat_gate(@const("__NR_kexec_file_load"), @const("__NR_compat_kexec_file_load")) |
| 129 |
@_SYSCALL_KEXEC_FILE_LOAD_NAME |
| 130 |
@SYSC_RETVALSTR($ret) |
| 131 |
} |