| 1 |
# execveat ______________________________________________ |
| 2 |
# SYSCALL_DEFINE5(execveat, |
| 3 |
# int, fd, const char __user *, filename, |
| 4 |
# const char __user *const __user *, argv, |
| 5 |
# const char __user *const __user *, envp, |
| 6 |
# int, flags) |
| 7 |
# |
| 8 |
|
| 9 |
@define _SYSCALL_EXECVEAT_NAME |
| 10 |
%( |
| 11 |
name = "execveat" |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_EXECVEAT_ARGSTR |
| 15 |
%( |
| 16 |
argstr = sprintf("%s, %s, %s, %s, %s", dirfd_str, filename, args, |
| 17 |
env_str, flags_str) |
| 18 |
%) |
| 19 |
|
| 20 |
@define _SYSCALL_EXECVEAT_REGARGS |
| 21 |
%( |
| 22 |
dirfd = int_arg(1) |
| 23 |
dirfd_str = _dfd_str(dirfd) |
| 24 |
%(systemtap_v <= "2.8" %? |
| 25 |
# All other "at" syscalls (faccessat, fchmodat, fchownat, |
| 26 |
# etc.) name their file descriptor argument 'dirfd', so let's |
| 27 |
# do the same. |
| 28 |
fd = dirfd |
| 29 |
fd_str = dirfd_str |
| 30 |
%) |
| 31 |
filename = user_string_quoted(pointer_arg(2)) |
| 32 |
args = __get_argv(pointer_arg(3), 0) |
| 33 |
env_str = __get_argv(pointer_arg(4), 0) |
| 34 |
flags = int_arg(5) |
| 35 |
flags_str = _at_flag_str(flags) |
| 36 |
%) |
| 37 |
|
| 38 |
@define _SYSCALL_COMPAT_EXECVEAT_REGARGS |
| 39 |
%( |
| 40 |
dirfd = int_arg(1) |
| 41 |
dirfd_str = _dfd_str(dirfd) |
| 42 |
%(systemtap_v <= "2.8" %? |
| 43 |
# All other "at" syscalls (faccessat, fchmodat, fchownat, |
| 44 |
# etc.) name their file descriptor argument 'dirfd', so let's |
| 45 |
# do the same. |
| 46 |
fd = dirfd |
| 47 |
fd_str = dirfd_str |
| 48 |
%) |
| 49 |
filename = user_string_quoted(pointer_arg(2)) |
| 50 |
args = __get_compat_argv(pointer_arg(3), 0) |
| 51 |
env_str = __get_compat_argv(pointer_arg(4), 0) |
| 52 |
flags = int_arg(5) |
| 53 |
flags_str = _at_flag_str(flags) |
| 54 |
%) |
| 55 |
|
| 56 |
probe syscall.execveat = dw_syscall.execveat !, nd_syscall.execveat ? {} |
| 57 |
probe syscall.execveat.return = dw_syscall.execveat.return !, |
| 58 |
nd_syscall.execveat.return ? {} |
| 59 |
|
| 60 |
probe syscall.compat_execveat = dw_syscall.compat_execveat !, |
| 61 |
nd_syscall.compat_execveat ? {} |
| 62 |
probe syscall.compat_execveat.return = dw_syscall.compat_execveat.return !, |
| 63 |
nd_syscall.compat_execveat.return ? {} |
| 64 |
|
| 65 |
# dw_execveat _____________________________________________________ |
| 66 |
|
| 67 |
probe dw_syscall.execveat = kernel.function("sys_execveat").call ? |
| 68 |
{ |
| 69 |
@_SYSCALL_EXECVEAT_NAME |
| 70 |
dirfd = __int32($fd) |
| 71 |
dirfd_str = _dfd_str(__int32($fd)) |
| 72 |
%(systemtap_v <= "2.8" %? |
| 73 |
# All other "at" syscalls (faccessat, fchmodat, fchownat, |
| 74 |
# etc.) name their file descriptor argument 'dirfd', so let's |
| 75 |
# do the same. |
| 76 |
fd = dirfd |
| 77 |
fd_str = dirfd_str |
| 78 |
%) |
| 79 |
filename = user_string_quoted(@__pointer($filename)) |
| 80 |
flags = __int32($flags) |
| 81 |
flags_str = _at_flag_str(__int32($flags)) |
| 82 |
__argv = @choose_defined($__argv, $argv) |
| 83 |
args = __get_argv(__argv, 0) |
| 84 |
__envp = @choose_defined($__envp, $envp) |
| 85 |
env_str = __get_argv(__envp, 0) |
| 86 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 87 |
} |
| 88 |
probe dw_syscall.execveat.return = kernel.function("sys_execveat").return ? |
| 89 |
{ |
| 90 |
@_SYSCALL_EXECVEAT_NAME |
| 91 |
@SYSC_RETVALSTR($return) |
| 92 |
} |
| 93 |
|
| 94 |
probe dw_syscall.compat_execveat = kernel.function("compat_sys_execveat").call ? |
| 95 |
{ |
| 96 |
@_SYSCALL_EXECVEAT_NAME |
| 97 |
dirfd = __int32($fd) |
| 98 |
dirfd_str = _dfd_str(__int32($fd)) |
| 99 |
%(systemtap_v <= "2.8" %? |
| 100 |
# All other "at" syscalls (faccessat, fchmodat, fchownat, |
| 101 |
# etc.) name their file descriptor argument 'dirfd', so let's |
| 102 |
# do the same. |
| 103 |
fd = dirfd |
| 104 |
fd_str = dirfd_str |
| 105 |
%) |
| 106 |
filename = user_string_quoted(@__pointer($filename)) |
| 107 |
flags = __int32($flags) |
| 108 |
flags_str = _at_flag_str(__int32($flags)) |
| 109 |
__argv = @__pointer(@choose_defined($__argv, $argv)) |
| 110 |
args = __get_compat_argv(__argv, 0) |
| 111 |
__envp = @__pointer(@choose_defined($__envp, $envp)) |
| 112 |
env_str = __get_compat_argv(__envp, 0) |
| 113 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 114 |
} |
| 115 |
probe dw_syscall.compat_execveat.return = |
| 116 |
kernel.function("compat_sys_execveat").return ? |
| 117 |
{ |
| 118 |
@_SYSCALL_EXECVEAT_NAME |
| 119 |
@SYSC_RETVALSTR($return) |
| 120 |
} |
| 121 |
|
| 122 |
# nd_execveat _____________________________________________________ |
| 123 |
|
| 124 |
probe nd_syscall.execveat = nd1_syscall.execveat!, nd2_syscall.execveat!, tp_syscall.execveat |
| 125 |
{ } |
| 126 |
|
| 127 |
probe nd1_syscall.execveat = kprobe.function("sys_execveat").call ? |
| 128 |
{ |
| 129 |
asmlinkage() |
| 130 |
@_SYSCALL_EXECVEAT_NAME |
| 131 |
@_SYSCALL_EXECVEAT_REGARGS |
| 132 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 133 |
} |
| 134 |
|
| 135 |
/* kernel 4.17+ */ |
| 136 |
probe nd2_syscall.execveat = kprobe.function(@arch_syscall_prefix "sys_execveat") ? |
| 137 |
{ |
| 138 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 139 |
@_SYSCALL_EXECVEAT_NAME |
| 140 |
@_SYSCALL_EXECVEAT_REGARGS |
| 141 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 142 |
} |
| 143 |
|
| 144 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 145 |
probe tp_syscall.execveat = kernel.trace("sys_enter") |
| 146 |
{ |
| 147 |
__set_syscall_pt_regs($regs) |
| 148 |
@__syscall_gate(@const("__NR_execveat")) |
| 149 |
@_SYSCALL_EXECVEAT_NAME |
| 150 |
@_SYSCALL_EXECVEAT_REGARGS |
| 151 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 152 |
} |
| 153 |
|
| 154 |
probe nd_syscall.execveat.return = nd1_syscall.execveat.return!, nd2_syscall.execveat.return!, tp_syscall.execveat.return |
| 155 |
{ } |
| 156 |
|
| 157 |
probe nd1_syscall.execveat.return = kprobe.function("sys_execveat").return ? |
| 158 |
{ |
| 159 |
@_SYSCALL_EXECVEAT_NAME |
| 160 |
@SYSC_RETVALSTR(returnval()) |
| 161 |
} |
| 162 |
|
| 163 |
/* kernel 4.17+ */ |
| 164 |
probe nd2_syscall.execveat.return = kprobe.function(@arch_syscall_prefix "sys_execveat").return ? |
| 165 |
{ |
| 166 |
@_SYSCALL_EXECVEAT_NAME |
| 167 |
@SYSC_RETVALSTR(returnval()) |
| 168 |
} |
| 169 |
|
| 170 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 171 |
probe tp_syscall.execveat.return = kernel.trace("sys_exit") |
| 172 |
{ |
| 173 |
__set_syscall_pt_regs($regs) |
| 174 |
@__syscall_gate(@const("__NR_execveat")) |
| 175 |
@_SYSCALL_EXECVEAT_NAME |
| 176 |
@SYSC_RETVALSTR($ret) |
| 177 |
} |
| 178 |
|
| 179 |
probe nd_syscall.compat_execveat = nd1_syscall.compat_execveat!, nd2_syscall.compat_execveat!, tp_syscall.compat_execveat |
| 180 |
{ } |
| 181 |
|
| 182 |
probe nd1_syscall.compat_execveat = kprobe.function("compat_sys_execveat").call ? |
| 183 |
{ |
| 184 |
@_SYSCALL_EXECVEAT_NAME |
| 185 |
@_SYSCALL_COMPAT_EXECVEAT_REGARGS |
| 186 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 187 |
|
| 188 |
} |
| 189 |
|
| 190 |
/* kernel 4.17+ */ |
| 191 |
probe nd2_syscall.compat_execveat = kprobe.function(@arch_syscall_prefix "compat_sys_execveat") ? |
| 192 |
{ |
| 193 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 194 |
@_SYSCALL_EXECVEAT_NAME |
| 195 |
@_SYSCALL_COMPAT_EXECVEAT_REGARGS |
| 196 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 197 |
} |
| 198 |
|
| 199 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 200 |
probe tp_syscall.compat_execveat = kernel.trace("sys_enter") |
| 201 |
{ |
| 202 |
__set_syscall_pt_regs($regs) |
| 203 |
@__compat_syscall_gate(@const("__NR_compat_execveat")) |
| 204 |
@_SYSCALL_EXECVEAT_NAME |
| 205 |
@_SYSCALL_COMPAT_EXECVEAT_REGARGS |
| 206 |
@_SYSCALL_EXECVEAT_ARGSTR |
| 207 |
} |
| 208 |
|
| 209 |
probe nd_syscall.compat_execveat.return = nd1_syscall.compat_execveat.return!, nd2_syscall.compat_execveat.return!, tp_syscall.compat_execveat.return |
| 210 |
{ } |
| 211 |
|
| 212 |
probe nd1_syscall.compat_execveat.return = |
| 213 |
kprobe.function("compat_sys_execveat").return ? |
| 214 |
{ |
| 215 |
@_SYSCALL_EXECVEAT_NAME |
| 216 |
@SYSC_RETVALSTR(returnval()) |
| 217 |
} |
| 218 |
|
| 219 |
/* kernel 4.17+ */ |
| 220 |
probe nd2_syscall.compat_execveat.return = kprobe.function(@arch_syscall_prefix "compat_sys_execveat").return ? |
| 221 |
{ |
| 222 |
@_SYSCALL_EXECVEAT_NAME |
| 223 |
@SYSC_RETVALSTR(returnval()) |
| 224 |
} |
| 225 |
|
| 226 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 227 |
probe tp_syscall.compat_execveat.return = kernel.trace("sys_exit") |
| 228 |
{ |
| 229 |
__set_syscall_pt_regs($regs) |
| 230 |
@__compat_syscall_gate(@const("__NR_compat_execveat")) |
| 231 |
@_SYSCALL_EXECVEAT_NAME |
| 232 |
@SYSC_RETVALSTR($ret) |
| 233 |
} |