| 1 |
# pwrite64 ___________________________________________________ |
| 2 |
# |
| 3 |
# ssize_t sys_pwrite64(unsigned int fd, |
| 4 |
# const char __user *buf, |
| 5 |
# size_t count, |
| 6 |
# loff_t pos) |
| 7 |
# |
| 8 |
|
| 9 |
@define _SYSCALL_PWRITE_NAME |
| 10 |
%( |
| 11 |
name = "pwrite" |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_PWRITE_ARGSTR |
| 15 |
%( |
| 16 |
argstr = sprintf("%d, %s, %u, %d", fd, buf_str, count, offset) |
| 17 |
%) |
| 18 |
|
| 19 |
@define _SYSCALL_PWRITE_REGARGS |
| 20 |
%( |
| 21 |
fd = int_arg(1) |
| 22 |
buf_uaddr = pointer_arg(2) |
| 23 |
count = ulong_arg(3) |
| 24 |
buf_str = user_buffer_quoted(buf_uaddr, count, syscall_string_trunc) |
| 25 |
%) |
| 26 |
|
| 27 |
@define _SYSCALL_PWRITE_REGARGS_STORE |
| 28 |
%( |
| 29 |
if (@probewrite(fd)) |
| 30 |
set_int_arg(1, fd) |
| 31 |
|
| 32 |
if (@probewrite(buf_uaddr)) |
| 33 |
set_pointer_arg(2, buf_uaddr) |
| 34 |
|
| 35 |
if (@probewrite(count)) |
| 36 |
set_ulong_arg(3, count) |
| 37 |
%) |
| 38 |
|
| 39 |
probe syscall.pwrite = dw_syscall.pwrite !, nd_syscall.pwrite ? {} |
| 40 |
probe syscall.pwrite.return = dw_syscall.pwrite.return !, |
| 41 |
nd_syscall.pwrite.return ? {} |
| 42 |
|
| 43 |
# dw_pwrite _____________________________________________________ |
| 44 |
|
| 45 |
probe dw_syscall.pwrite = kernel.function("sys_pwrite64").call |
| 46 |
{ |
| 47 |
%( arch == "s390" || arch == "x86_64" %? |
| 48 |
@__syscall_gate(@const("__NR_pwrite64")) |
| 49 |
%) |
| 50 |
@_SYSCALL_PWRITE_NAME |
| 51 |
fd = __int32($fd) |
| 52 |
buf_uaddr = $buf |
| 53 |
count = @__compat_ulong($count) |
| 54 |
buf_str = user_buffer_quoted(buf_uaddr, count, syscall_string_trunc) |
| 55 |
offset = $pos |
| 56 |
@_SYSCALL_PWRITE_ARGSTR |
| 57 |
} |
| 58 |
probe dw_syscall.pwrite.return = kernel.function("sys_pwrite64").return |
| 59 |
{ |
| 60 |
%( arch == "s390" || arch == "x86_64" %? |
| 61 |
@__syscall_gate(@const("__NR_pwrite64")) |
| 62 |
%) |
| 63 |
@_SYSCALL_PWRITE_NAME |
| 64 |
@SYSC_RETVALSTR($return) |
| 65 |
} |
| 66 |
|
| 67 |
# nd_pwrite _____________________________________________________ |
| 68 |
|
| 69 |
probe nd_syscall.pwrite = nd1_syscall.pwrite!, nd2_syscall.pwrite!, tp_syscall.pwrite |
| 70 |
{ } |
| 71 |
|
| 72 |
probe nd1_syscall.pwrite = kprobe.function("sys_pwrite64") ? |
| 73 |
{ |
| 74 |
%( arch == "s390" || arch == "x86_64" %? |
| 75 |
@__syscall_gate(@const("__NR_pwrite64")) |
| 76 |
%) |
| 77 |
@_SYSCALL_PWRITE_NAME |
| 78 |
asmlinkage() |
| 79 |
@_SYSCALL_PWRITE_REGARGS |
| 80 |
offset = longlong_arg(4) |
| 81 |
@_SYSCALL_PWRITE_ARGSTR |
| 82 |
} |
| 83 |
|
| 84 |
/* kernel 4.17+ */ |
| 85 |
probe nd2_syscall.pwrite = kprobe.function(@arch_syscall_prefix "sys_pwrite64") ? |
| 86 |
{ |
| 87 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 88 |
@_SYSCALL_PWRITE_NAME |
| 89 |
@_SYSCALL_PWRITE_REGARGS |
| 90 |
offset = longlong_arg(4) |
| 91 |
@_SYSCALL_PWRITE_ARGSTR |
| 92 |
}, |
| 93 |
{ |
| 94 |
%( @_IS_SREG_KERNEL %? |
| 95 |
@_SYSCALL_PWRITE_REGARGS_STORE |
| 96 |
|
| 97 |
if (@probewrite(offset)) |
| 98 |
set_longlong_arg(4, offset) |
| 99 |
%) |
| 100 |
} |
| 101 |
|
| 102 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 103 |
probe tp_syscall.pwrite = kernel.trace("sys_enter") |
| 104 |
{ |
| 105 |
__set_syscall_pt_regs($regs) |
| 106 |
@__syscall_gate(@const("__NR_pwrite64")) |
| 107 |
@_SYSCALL_PWRITE_NAME |
| 108 |
@_SYSCALL_PWRITE_REGARGS |
| 109 |
offset = longlong_arg(4) |
| 110 |
@_SYSCALL_PWRITE_ARGSTR |
| 111 |
}, |
| 112 |
{ |
| 113 |
%( @_IS_SREG_KERNEL %? |
| 114 |
@_SYSCALL_PWRITE_REGARGS_STORE |
| 115 |
|
| 116 |
if (@probewrite(offset)) |
| 117 |
set_longlong_arg(4, offset) |
| 118 |
%) |
| 119 |
} |
| 120 |
|
| 121 |
probe nd_syscall.pwrite.return = nd1_syscall.pwrite.return!, nd2_syscall.pwrite.return!, tp_syscall.pwrite.return |
| 122 |
{ } |
| 123 |
|
| 124 |
probe nd1_syscall.pwrite.return = kprobe.function("sys_pwrite64").return ? |
| 125 |
{ |
| 126 |
%( arch == "s390" || arch == "x86_64" %? |
| 127 |
@__syscall_gate(@const("__NR_pwrite64")) |
| 128 |
%) |
| 129 |
@_SYSCALL_PWRITE_NAME |
| 130 |
@SYSC_RETVALSTR(returnval()) |
| 131 |
} |
| 132 |
|
| 133 |
/* kernel 4.17+ */ |
| 134 |
probe nd2_syscall.pwrite.return = kprobe.function(@arch_syscall_prefix "sys_pwrite64").return ? |
| 135 |
{ |
| 136 |
@_SYSCALL_PWRITE_NAME |
| 137 |
@SYSC_RETVALSTR(returnval()) |
| 138 |
} |
| 139 |
|
| 140 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 141 |
probe tp_syscall.pwrite.return = kernel.trace("sys_exit") |
| 142 |
{ |
| 143 |
__set_syscall_pt_regs($regs) |
| 144 |
@__syscall_gate(@const("__NR_pwrite64")) |
| 145 |
@_SYSCALL_PWRITE_NAME |
| 146 |
@SYSC_RETVALSTR($ret) |
| 147 |
} |
| 148 |
|
| 149 |
# long sys32_pwrite64(unsigned int fd, const char __user *ubuf, |
| 150 |
# size_t count, u32 poshi, u32 poslo) |
| 151 |
# COMPAT_SYSCALL_DEFINE5(s390_pwrite64, unsigned int, fd, |
| 152 |
# const char __user *, ubuf, |
| 153 |
# compat_size_t, count, u32, high, u32, low) |
| 154 |
|
| 155 |
probe syscall.pwrite32 = dw_syscall.pwrite32 !, nd_syscall.pwrite32 ? {} |
| 156 |
probe syscall.pwrite32.return = dw_syscall.pwrite32.return !, |
| 157 |
nd_syscall.pwrite32.return ? {} |
| 158 |
|
| 159 |
# dw_pwrite32 _____________________________________________________ |
| 160 |
|
| 161 |
probe dw_syscall.pwrite32 = |
| 162 |
%( arch == "s390" %? |
| 163 |
kernel.function("compat_sys_s390_pwrite64").call ?, |
| 164 |
%) |
| 165 |
%( arch == "x86_64" %? |
| 166 |
kernel.function("compat_sys_x86_pwrite64").call ?, |
| 167 |
%) |
| 168 |
kernel.function("sys32_pwrite64").call ? |
| 169 |
{ |
| 170 |
@_SYSCALL_PWRITE_NAME |
| 171 |
fd = __int32($fd) |
| 172 |
count = @__compat_ulong($count) |
| 173 |
offset = ((@choose_defined($poshi, $high) << 32) |
| 174 |
+ __uint32(@choose_defined($poslo, $low))) |
| 175 |
buf_uaddr = @__pointer(@choose_defined($buf, $ubuf)) |
| 176 |
buf_str = user_buffer_quoted(buf_uaddr, count, syscall_string_trunc) |
| 177 |
@_SYSCALL_PWRITE_ARGSTR |
| 178 |
} |
| 179 |
probe dw_syscall.pwrite32.return = |
| 180 |
%( arch == "s390" %? |
| 181 |
kernel.function("compat_sys_s390_pwrite64").return ?, |
| 182 |
%) |
| 183 |
%( arch == "x86_64" %? |
| 184 |
kernel.function("compat_sys_x86_pwrite64").return ?, |
| 185 |
%) |
| 186 |
kernel.function("sys32_pwrite64").return ? |
| 187 |
{ |
| 188 |
@_SYSCALL_PWRITE_NAME |
| 189 |
@SYSC_RETVALSTR($return) |
| 190 |
} |
| 191 |
|
| 192 |
# nd_pwrite32 _____________________________________________________ |
| 193 |
|
| 194 |
probe nd_syscall.pwrite32 = nd1_syscall.pwrite32!, nd2_syscall.pwrite32!, tp_syscall.pwrite32 |
| 195 |
{ } |
| 196 |
|
| 197 |
probe nd1_syscall.pwrite32 = |
| 198 |
%( arch == "s390" %? |
| 199 |
kprobe.function("compat_sys_s390_pwrite64") ?, |
| 200 |
%) |
| 201 |
%( arch == "x86_64" %? |
| 202 |
kprobe.function("compat_sys_x86_pwrite64") ?, |
| 203 |
%) |
| 204 |
kprobe.function("sys32_pwrite64") ? |
| 205 |
{ |
| 206 |
@_SYSCALL_PWRITE_NAME |
| 207 |
asmlinkage() |
| 208 |
@_SYSCALL_PWRITE_REGARGS |
| 209 |
offset = (u32_arg(4) << 32) + u32_arg(5) |
| 210 |
@_SYSCALL_PWRITE_ARGSTR |
| 211 |
} |
| 212 |
|
| 213 |
/* kernel 4.17+ */ |
| 214 |
probe nd2_syscall.pwrite32 = kprobe.function(@arch_syscall_prefix "compat_sys_x86_pwrite") ? |
| 215 |
{ |
| 216 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 217 |
@_SYSCALL_PWRITE_NAME |
| 218 |
@_SYSCALL_PWRITE_REGARGS |
| 219 |
offset = (u32_arg(5) << 32) + u32_arg(4) |
| 220 |
@_SYSCALL_PWRITE_ARGSTR |
| 221 |
}, |
| 222 |
{ |
| 223 |
%( @_IS_SREG_KERNEL %? |
| 224 |
@_SYSCALL_PWRITE_REGARGS_STORE |
| 225 |
|
| 226 |
if (@probewrite(offset)) { |
| 227 |
set_u32_arg(4, offset & 0xffffffff) |
| 228 |
set_u32_arg(5, offset >> 32) |
| 229 |
} |
| 230 |
%) |
| 231 |
} |
| 232 |
|
| 233 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 234 |
probe tp_syscall.pwrite32 = kernel.trace("sys_enter") |
| 235 |
{ |
| 236 |
__set_syscall_pt_regs($regs) |
| 237 |
@__compat_syscall_gate(@const("__NR_compat_pwrite64")) |
| 238 |
@_SYSCALL_PWRITE_NAME |
| 239 |
@_SYSCALL_PWRITE_REGARGS |
| 240 |
offset = (u32_arg(5) << 32) + u32_arg(4) |
| 241 |
@_SYSCALL_PWRITE_ARGSTR |
| 242 |
}, |
| 243 |
{ |
| 244 |
%( @_IS_SREG_KERNEL %? |
| 245 |
@_SYSCALL_PWRITE_REGARGS_STORE |
| 246 |
|
| 247 |
if (@probewrite(offset)) { |
| 248 |
set_u32_arg(4, offset & 0xffffffff) |
| 249 |
set_u32_arg(5, offset >> 32) |
| 250 |
} |
| 251 |
%) |
| 252 |
} |
| 253 |
|
| 254 |
probe nd_syscall.pwrite32.return = nd1_syscall.pwrite32.return!, nd2_syscall.pwrite32.return!, tp_syscall.pwrite32.return |
| 255 |
{ } |
| 256 |
|
| 257 |
probe nd1_syscall.pwrite32.return = |
| 258 |
%( arch == "s390" %? |
| 259 |
kprobe.function("compat_sys_s390_pwrite64").return ?, |
| 260 |
%) |
| 261 |
%( arch == "x86_64" %? |
| 262 |
kprobe.function("compat_sys_x86_pwrite64").return ?, |
| 263 |
%) |
| 264 |
kprobe.function("sys32_pwrite64").return ? |
| 265 |
{ |
| 266 |
@_SYSCALL_PWRITE_NAME |
| 267 |
@SYSC_RETVALSTR(returnval()) |
| 268 |
} |
| 269 |
|
| 270 |
/* kernel 4.17+ */ |
| 271 |
probe nd2_syscall.pwrite32.return = |
| 272 |
kprobe.function(@arch_syscall_prefix "compat_sys_x86_pwrite").return ? |
| 273 |
{ |
| 274 |
@_SYSCALL_PWRITE_NAME |
| 275 |
@SYSC_RETVALSTR(returnval()) |
| 276 |
} |
| 277 |
|
| 278 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 279 |
probe tp_syscall.pwrite32.return = kernel.trace("sys_exit") |
| 280 |
{ |
| 281 |
__set_syscall_pt_regs($regs) |
| 282 |
@__compat_syscall_gate(@const("__NR_compat_pwrite64")) |
| 283 |
@_SYSCALL_PWRITE_NAME |
| 284 |
@SYSC_RETVALSTR($ret) |
| 285 |
} |