| 1 |
# execve _____________________________________________________ |
| 2 |
# NB: kprocess.exec[_complete] is aliased to syscall.execve[.return] |
| 3 |
%( kernel_v >= "3.7" %? |
| 4 |
# In kernels >= 3.7, sys_execve() has been moved to generic code, so we |
| 5 |
# can use it with confidence. For kernels < 3.7, execve support is in |
| 6 |
# arch-specific tapset code. |
| 7 |
# |
| 8 |
# SYSCALL_DEFINE3(execve, |
| 9 |
# const char __user *, filename, |
| 10 |
# const char __user *const __user *, argv, |
| 11 |
# const char __user *const __user *, envp) |
| 12 |
|
| 13 |
@define _SYSCALL_EXECVE_NAME |
| 14 |
%( |
| 15 |
name = "execve" |
| 16 |
%) |
| 17 |
|
| 18 |
@define _SYSCALL_EXECVE_ARGSTR |
| 19 |
%( |
| 20 |
argstr = sprintf("%s, %s, %s", filename, args, env_str) |
| 21 |
%) |
| 22 |
|
| 23 |
@define _SYSCALL_EXECVE_REGARGS |
| 24 |
%( |
| 25 |
filename = user_string_quoted(pointer_arg(1)) |
| 26 |
args = __get_argv(pointer_arg(2), 0) |
| 27 |
env_str = __get_argv(pointer_arg(3), 0) |
| 28 |
%) |
| 29 |
|
| 30 |
@define _SYSCALL_COMPAT_EXECVE_REGARGS |
| 31 |
%( |
| 32 |
filename = user_string_quoted(pointer_arg(1)) |
| 33 |
args = __get_compat_argv(pointer_arg(2), 0) |
| 34 |
env_str = __get_compat_argv(pointer_arg(3), 0) |
| 35 |
%) |
| 36 |
|
| 37 |
probe syscall.execve = dw_syscall.execve !, nd_syscall.execve {} |
| 38 |
probe syscall.execve.return = dw_syscall.execve.return !, |
| 39 |
nd_syscall.execve.return {} |
| 40 |
|
| 41 |
probe syscall.compat_execve = dw_syscall.compat_execve !, |
| 42 |
nd_syscall.compat_execve ? {} |
| 43 |
probe syscall.compat_execve.return = dw_syscall.compat_execve.return !, |
| 44 |
nd_syscall.compat_execve.return ? {} |
| 45 |
|
| 46 |
# dw_execve _____________________________________________________ |
| 47 |
|
| 48 |
probe dw_syscall.execve = kernel.function("sys_execve").call |
| 49 |
{ |
| 50 |
@_SYSCALL_EXECVE_NAME |
| 51 |
filename = user_string_quoted(@choose_defined($filename, $name)) |
| 52 |
# kernel 3.0 changed the pointer's name to __argv |
| 53 |
__argv = @choose_defined($__argv, $argv) |
| 54 |
args = __get_argv(__argv, 0) |
| 55 |
__envp = @choose_defined($__envp, $envp) |
| 56 |
env_str = __get_argv(__envp, 0) |
| 57 |
@_SYSCALL_EXECVE_ARGSTR |
| 58 |
} |
| 59 |
probe dw_syscall.execve.return = kernel.function("sys_execve").return |
| 60 |
{ |
| 61 |
@_SYSCALL_EXECVE_NAME |
| 62 |
@SYSC_RETVALSTR($return) |
| 63 |
} |
| 64 |
|
| 65 |
# In kernels >= 3.7, compat_sys_execve() has been moved to generic |
| 66 |
# code, so we can use it with confidence. For kernels < 3.7, |
| 67 |
# compat_execve support is in arch-specific tapset code. |
| 68 |
# |
| 69 |
# asmlinkage long compat_sys_execve(const char __user * filename, |
| 70 |
# const compat_uptr_t __user * argv, |
| 71 |
# const compat_uptr_t __user * envp) |
| 72 |
probe dw_syscall.compat_execve = kernel.function("compat_sys_execve").call ? |
| 73 |
{ |
| 74 |
@_SYSCALL_EXECVE_NAME |
| 75 |
filename = user_string_quoted(@__pointer($filename)) |
| 76 |
# kernel 3.0 changed the pointer's name to __argv |
| 77 |
__argv = @__pointer(@choose_defined($__argv, $argv)) |
| 78 |
args = __get_compat_argv(__argv, 0) |
| 79 |
__envp = @__pointer(@choose_defined($__envp, $envp)) |
| 80 |
env_str = __get_compat_argv(__envp, 0) |
| 81 |
@_SYSCALL_EXECVE_ARGSTR |
| 82 |
} |
| 83 |
probe dw_syscall.compat_execve.return = |
| 84 |
kernel.function("compat_sys_execve").return ? |
| 85 |
{ |
| 86 |
@_SYSCALL_EXECVE_NAME |
| 87 |
@SYSC_RETVALSTR($return) |
| 88 |
} |
| 89 |
|
| 90 |
# nd_execve _____________________________________________________ |
| 91 |
|
| 92 |
probe nd_syscall.execve = nd1_syscall.execve!, nd2_syscall.execve!, tp_syscall.execve |
| 93 |
{ } |
| 94 |
|
| 95 |
probe nd1_syscall.execve = kprobe.function("sys_execve") |
| 96 |
{ |
| 97 |
@_SYSCALL_EXECVE_NAME |
| 98 |
asmlinkage() |
| 99 |
@_SYSCALL_EXECVE_REGARGS |
| 100 |
@_SYSCALL_EXECVE_ARGSTR |
| 101 |
} |
| 102 |
|
| 103 |
/* kernel 4.17+ */ |
| 104 |
probe nd2_syscall.execve = kprobe.function(@arch_syscall_prefix "sys_execve") ? |
| 105 |
{ |
| 106 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 107 |
@_SYSCALL_EXECVE_NAME |
| 108 |
@_SYSCALL_EXECVE_REGARGS |
| 109 |
@_SYSCALL_EXECVE_ARGSTR |
| 110 |
} |
| 111 |
|
| 112 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 113 |
probe tp_syscall.execve = kernel.trace("sys_enter") |
| 114 |
{ |
| 115 |
__set_syscall_pt_regs($regs) |
| 116 |
@__syscall_gate(@const("__NR_execve")) |
| 117 |
@_SYSCALL_EXECVE_NAME |
| 118 |
@_SYSCALL_EXECVE_REGARGS |
| 119 |
@_SYSCALL_EXECVE_ARGSTR |
| 120 |
} |
| 121 |
|
| 122 |
probe nd_syscall.execve.return = nd1_syscall.execve.return!, nd2_syscall.execve.return!, tp_syscall.execve.return |
| 123 |
{ } |
| 124 |
|
| 125 |
probe nd1_syscall.execve.return = kprobe.function("sys_execve").return |
| 126 |
{ |
| 127 |
@_SYSCALL_EXECVE_NAME |
| 128 |
@SYSC_RETVALSTR(returnval()) |
| 129 |
} |
| 130 |
|
| 131 |
/* kernel 4.17+ */ |
| 132 |
probe nd2_syscall.execve.return = kprobe.function(@arch_syscall_prefix "sys_execve").return ? |
| 133 |
{ |
| 134 |
@_SYSCALL_EXECVE_NAME |
| 135 |
@SYSC_RETVALSTR(returnval()) |
| 136 |
} |
| 137 |
|
| 138 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 139 |
probe tp_syscall.execve.return = kernel.trace("sys_exit") |
| 140 |
{ |
| 141 |
__set_syscall_pt_regs($regs) |
| 142 |
@__syscall_gate(@const("__NR_execve")) |
| 143 |
@_SYSCALL_EXECVE_NAME |
| 144 |
@SYSC_RETVALSTR($ret) |
| 145 |
} |
| 146 |
|
| 147 |
# In kernels >= 3.7, compat_sys_execve() has been moved to generic |
| 148 |
# code, so we can use it with confidence. For kernels < 3.7, |
| 149 |
# compat_execve support is in arch-specific tapset code. |
| 150 |
# |
| 151 |
# asmlinkage long compat_sys_execve(const char __user * filename, |
| 152 |
# const compat_uptr_t __user * argv, |
| 153 |
# const compat_uptr_t __user * envp) |
| 154 |
|
| 155 |
probe nd_syscall.compat_execve = nd1_syscall.compat_execve!, nd2_syscall.compat_execve!, tp_syscall.compat_execve |
| 156 |
{ } |
| 157 |
|
| 158 |
probe nd1_syscall.compat_execve = kprobe.function("compat_sys_execve").call ? |
| 159 |
{ |
| 160 |
@_SYSCALL_EXECVE_NAME |
| 161 |
asmlinkage() |
| 162 |
@_SYSCALL_COMPAT_EXECVE_REGARGS |
| 163 |
@_SYSCALL_EXECVE_ARGSTR |
| 164 |
} |
| 165 |
|
| 166 |
/* kernel 4.17+ */ |
| 167 |
probe nd2_syscall.compat_execve = kprobe.function(@arch_syscall_prefix "compat_sys_execve") ? |
| 168 |
{ |
| 169 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 170 |
@_SYSCALL_EXECVE_NAME |
| 171 |
@_SYSCALL_COMPAT_EXECVE_REGARGS |
| 172 |
@_SYSCALL_EXECVE_ARGSTR |
| 173 |
} |
| 174 |
|
| 175 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 176 |
probe tp_syscall.compat_execve = kernel.trace("sys_enter") |
| 177 |
{ |
| 178 |
__set_syscall_pt_regs($regs) |
| 179 |
@__compat_syscall_gate(@const("__NR_compat_execve")) |
| 180 |
@_SYSCALL_EXECVE_NAME |
| 181 |
@_SYSCALL_COMPAT_EXECVE_REGARGS |
| 182 |
@_SYSCALL_EXECVE_ARGSTR |
| 183 |
} |
| 184 |
|
| 185 |
probe nd_syscall.compat_execve.return = nd1_syscall.compat_execve.return!, nd2_syscall.compat_execve.return!, tp_syscall.compat_execve.return |
| 186 |
{ } |
| 187 |
|
| 188 |
probe nd1_syscall.compat_execve.return = |
| 189 |
kprobe.function("compat_sys_execve").return ? |
| 190 |
{ |
| 191 |
@_SYSCALL_EXECVE_NAME |
| 192 |
@SYSC_RETVALSTR(returnval()) |
| 193 |
} |
| 194 |
|
| 195 |
/* kernel 4.17+ */ |
| 196 |
probe nd2_syscall.compat_execve.return = kprobe.function(@arch_syscall_prefix "compat_sys_execve").return ? |
| 197 |
{ |
| 198 |
@_SYSCALL_EXECVE_NAME |
| 199 |
@SYSC_RETVALSTR(returnval()) |
| 200 |
} |
| 201 |
|
| 202 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 203 |
probe tp_syscall.compat_execve.return = kernel.trace("sys_exit") |
| 204 |
{ |
| 205 |
__set_syscall_pt_regs($regs) |
| 206 |
@__compat_syscall_gate(@const("__NR_compat_execve")) |
| 207 |
@_SYSCALL_EXECVE_NAME |
| 208 |
@SYSC_RETVALSTR($ret) |
| 209 |
} |
| 210 |
%) |