| 1 |
# stat _______________________________________________________ |
| 2 |
# long sys_stat(char __user * filename, struct __old_stat __user * statbuf) |
| 3 |
# long sys32_stat64(char __user * filename, struct stat64 __user *statbuf) |
| 4 |
# long sys_stat64(char __user * filename, struct stat64 __user * statbuf) |
| 5 |
# long sys_oabi_stat64(char __user * filename, struct oldabi_stat64 __user * statbuf) |
| 6 |
# long compat_sys_newstat(char __user * filename, struct compat_stat __user *statbuf) |
| 7 |
# COMPAT_SYSCALL_DEFINE2(s390_stat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf) |
| 8 |
# |
| 9 |
|
| 10 |
@define _SYSCALL_STAT_NAME |
| 11 |
%( |
| 12 |
name = "stat" |
| 13 |
%) |
| 14 |
|
| 15 |
@define _SYSCALL_STAT_ARGSTR |
| 16 |
%( |
| 17 |
argstr = sprintf("%s, %p", filename, buf_uaddr) |
| 18 |
%) |
| 19 |
|
| 20 |
@define _SYSCALL_STAT_REGARGS |
| 21 |
%( |
| 22 |
filename_uaddr = pointer_arg(1) |
| 23 |
filename = user_string_quoted(filename_uaddr) |
| 24 |
filename_unquoted = user_string_nofault(pointer_arg(1)) |
| 25 |
buf_uaddr = pointer_arg(2) |
| 26 |
%) |
| 27 |
|
| 28 |
@define _SYSCALL_STAT_REGARGS_STORE |
| 29 |
%( |
| 30 |
if (@probewrite(filename_uaddr)) |
| 31 |
set_pointer_arg(1, filename_uaddr) |
| 32 |
|
| 33 |
if (@probewrite(filename_unquoted)) |
| 34 |
set_user_string_arg(pointer_arg(1), filename_unquoted) |
| 35 |
|
| 36 |
if (@probewrite(buf_uaddr)) |
| 37 |
set_pointer_arg(2, buf_uaddr) |
| 38 |
%) |
| 39 |
|
| 40 |
probe syscall.stat = dw_syscall.stat !, nd_syscall.stat ? {} |
| 41 |
probe syscall.stat.return = dw_syscall.stat.return !, nd_syscall.stat.return ? {} |
| 42 |
|
| 43 |
# dw_stat _____________________________________________________ |
| 44 |
|
| 45 |
probe dw_syscall.stat = kernel.function("sys_stat").call ?, |
| 46 |
kernel.function("sys_newstat").call ?, |
| 47 |
kernel.function("sys32_stat64").call ?, |
| 48 |
kernel.function("sys_stat64").call ?, |
| 49 |
kernel.function("sys_oabi_stat64").call ?, |
| 50 |
%( arch == "s390" %? |
| 51 |
kernel.function("compat_sys_s390_stat64").call ?, |
| 52 |
%) |
| 53 |
%( arch == "x86_64" %? |
| 54 |
kernel.function("compat_sys_x86_stat64").call ?, |
| 55 |
%) |
| 56 |
kernel.function("compat_sys_newstat").call ? |
| 57 |
{ |
| 58 |
@_SYSCALL_STAT_NAME |
| 59 |
filename_uaddr = $filename |
| 60 |
filename = user_string_quoted($filename) |
| 61 |
buf_uaddr = $statbuf |
| 62 |
@_SYSCALL_STAT_ARGSTR |
| 63 |
} |
| 64 |
probe dw_syscall.stat.return = kernel.function("sys_stat").return ?, |
| 65 |
kernel.function("sys_newstat").return ?, |
| 66 |
kernel.function("sys32_stat64").return ?, |
| 67 |
kernel.function("sys_stat64").return ?, |
| 68 |
kernel.function("sys_oabi_stat64").return ?, |
| 69 |
%( arch == "s390" %? |
| 70 |
kernel.function("compat_sys_s390_stat64").return ?, |
| 71 |
%) |
| 72 |
%( arch == "x86_64" %? |
| 73 |
kernel.function("compat_sys_x86_stat64").return ?, |
| 74 |
%) |
| 75 |
kernel.function("compat_sys_newstat").return ? |
| 76 |
{ |
| 77 |
@_SYSCALL_STAT_NAME |
| 78 |
@SYSC_RETVALSTR($return) |
| 79 |
} |
| 80 |
|
| 81 |
# nd_stat _____________________________________________________ |
| 82 |
|
| 83 |
probe nd_syscall.stat = nd1_syscall.stat!, nd2_syscall.stat!, tp_syscall.stat |
| 84 |
{ } |
| 85 |
|
| 86 |
probe nd1_syscall.stat = kprobe.function("sys_stat") ?, |
| 87 |
kprobe.function("sys_newstat") ?, |
| 88 |
kprobe.function("sys32_stat64") ?, |
| 89 |
kprobe.function("sys_stat64") ?, |
| 90 |
kprobe.function("sys_oabi_stat64") ?, |
| 91 |
%( arch == "s390" %? |
| 92 |
kprobe.function("compat_sys_s390_stat64") ?, |
| 93 |
%) |
| 94 |
%( arch == "x86_64" %? |
| 95 |
kprobe.function("compat_sys_x86_stat64") ?, |
| 96 |
%) |
| 97 |
kprobe.function("compat_sys_newstat") ? |
| 98 |
{ |
| 99 |
@_SYSCALL_STAT_NAME |
| 100 |
asmlinkage() |
| 101 |
@_SYSCALL_STAT_REGARGS |
| 102 |
@_SYSCALL_STAT_ARGSTR |
| 103 |
} |
| 104 |
|
| 105 |
/* kernel 4.17+ */ |
| 106 |
probe nd2_syscall.stat = |
| 107 |
kprobe.function(@arch_syscall_prefix "sys_stat") ?, |
| 108 |
kprobe.function(@arch_syscall_prefix "sys_newstat") ?, |
| 109 |
kprobe.function(@arch_syscall_prefix "compat_sys_newstat") ?, |
| 110 |
kprobe.function(@arch_syscall_prefix "compat_sys_x86_stat64") ? |
| 111 |
{ |
| 112 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 113 |
@_SYSCALL_STAT_NAME |
| 114 |
@_SYSCALL_STAT_REGARGS |
| 115 |
@_SYSCALL_STAT_ARGSTR |
| 116 |
}, |
| 117 |
{ |
| 118 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_STAT_REGARGS_STORE %) |
| 119 |
} |
| 120 |
|
| 121 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 122 |
probe tp_syscall.stat = __tp_syscall.stat, |
| 123 |
__tp_syscall.stat64, |
| 124 |
__tp_syscall.newstat |
| 125 |
{ |
| 126 |
__set_syscall_pt_regs($regs) |
| 127 |
@_SYSCALL_STAT_NAME |
| 128 |
@_SYSCALL_STAT_REGARGS |
| 129 |
@_SYSCALL_STAT_ARGSTR |
| 130 |
}, |
| 131 |
{ |
| 132 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_STAT_REGARGS_STORE %) |
| 133 |
} |
| 134 |
probe __tp_syscall.stat = kernel.trace("sys_enter") |
| 135 |
{ |
| 136 |
@__syscall_compat_gate(@const("__NR_oldstat"), @const("__NR_compat_oldstat")) |
| 137 |
} |
| 138 |
probe __tp_syscall.stat64 = kernel.trace("sys_enter") |
| 139 |
{ |
| 140 |
@__syscall_compat_gate(@const("__NR_stat64"), @const("__NR_compat_stat64")) |
| 141 |
} |
| 142 |
probe __tp_syscall.newstat = kernel.trace("sys_enter") |
| 143 |
{ |
| 144 |
@__syscall_compat_gate(@const("__NR_stat"), @const("__NR_compat_stat")) |
| 145 |
} |
| 146 |
|
| 147 |
probe nd_syscall.stat.return = nd1_syscall.stat.return!, nd2_syscall.stat.return!, tp_syscall.stat.return |
| 148 |
{ } |
| 149 |
|
| 150 |
probe nd1_syscall.stat.return = kprobe.function("sys_stat").return ?, |
| 151 |
kprobe.function("sys_newstat").return ?, |
| 152 |
kprobe.function("sys32_stat64").return ?, |
| 153 |
kprobe.function("sys_stat64").return ?, |
| 154 |
kprobe.function("sys_oabi_stat64").return ?, |
| 155 |
%( arch == "s390" %? |
| 156 |
kprobe.function("compat_sys_s390_stat64").return ?, |
| 157 |
%) |
| 158 |
%( arch == "x86_64" %? |
| 159 |
kprobe.function("compat_sys_x86_stat64").return ?, |
| 160 |
%) |
| 161 |
kprobe.function("compat_sys_newstat").return ? |
| 162 |
{ |
| 163 |
@_SYSCALL_STAT_NAME |
| 164 |
@SYSC_RETVALSTR(returnval()) |
| 165 |
} |
| 166 |
|
| 167 |
/* kernel 4.17+ */ |
| 168 |
probe nd2_syscall.stat.return = |
| 169 |
kprobe.function(@arch_syscall_prefix "sys_stat").return ?, |
| 170 |
kprobe.function(@arch_syscall_prefix "sys_newstat").return ?, |
| 171 |
kprobe.function(@arch_syscall_prefix "compat_sys_newstat").return ?, |
| 172 |
kprobe.function(@arch_syscall_prefix "compat_sys_x86_stat64").return |
| 173 |
{ |
| 174 |
@_SYSCALL_STAT_NAME |
| 175 |
@SYSC_RETVALSTR(returnval()) |
| 176 |
} |
| 177 |
|
| 178 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 179 |
probe tp_syscall.stat.return = __tp_syscall.stat.return, |
| 180 |
__tp_syscall.stat64.return, |
| 181 |
__tp_syscall.newstat.return |
| 182 |
{ |
| 183 |
__set_syscall_pt_regs($regs) |
| 184 |
@_SYSCALL_STAT_NAME |
| 185 |
@SYSC_RETVALSTR($ret) |
| 186 |
} |
| 187 |
probe __tp_syscall.stat.return = kernel.trace("sys_exit") |
| 188 |
{ |
| 189 |
@__syscall_compat_gate(@const("__NR_oldstat"), @const("__NR_compat_oldstat")) |
| 190 |
} |
| 191 |
probe __tp_syscall.stat64.return = kernel.trace("sys_exit") |
| 192 |
{ |
| 193 |
@__syscall_compat_gate(@const("__NR_stat64"), @const("__NR_compat_stat64")) |
| 194 |
} |
| 195 |
probe __tp_syscall.newstat.return = kernel.trace("sys_exit") |
| 196 |
{ |
| 197 |
@__syscall_compat_gate(@const("__NR_stat"), @const("__NR_compat_stat")) |
| 198 |
} |