| 1 |
# semtimedop _________________________________________________ |
| 2 |
# |
| 3 |
# long sys_semtimedop(int semid, |
| 4 |
# struct sembuf __user *tsops, |
| 5 |
# unsigned nsops, |
| 6 |
# const struct timespec __user *timeout) |
| 7 |
# |
| 8 |
|
| 9 |
@define _SYSCALL_SEMTIMEDOP_NAME |
| 10 |
%( |
| 11 |
name = "semtimedop" |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_SEMTIMEDOP_ARGSTR |
| 15 |
%( |
| 16 |
argstr = sprintf("%d, %p, %u, %s", semid, sops_uaddr, nsops, timeout_str) |
| 17 |
%) |
| 18 |
|
| 19 |
@define _SYSCALL_SEMTIMEDOP_REGARGS_STORE |
| 20 |
%( |
| 21 |
if (@probewrite(semid)) |
| 22 |
set_int_arg(1, semid) |
| 23 |
|
| 24 |
if (@probewrite(sops_uaddr)) |
| 25 |
set_pointer_arg(2, sops_uaddr) |
| 26 |
|
| 27 |
if (@probewrite(nsops)) |
| 28 |
set_uint_arg(3, nsops) |
| 29 |
|
| 30 |
if (@probewrite(timeout_uaddr)) |
| 31 |
set_pointer_arg(4, timeout_uaddr) |
| 32 |
%) |
| 33 |
|
| 34 |
|
| 35 |
@define _SYSCALL_COMPAT_SEMTIMEDOP_REGARGS_STORE |
| 36 |
%( |
| 37 |
if (@probewrite(semid)) |
| 38 |
set_int_arg(2, semid) |
| 39 |
|
| 40 |
if (@probewrite(sops_uaddr)) |
| 41 |
set_pointer_arg(5, sops_uaddr) |
| 42 |
|
| 43 |
if (@probewrite(nsops)) |
| 44 |
set_uint_arg(3, nsops) |
| 45 |
|
| 46 |
if (@probewrite(timeout_uaddr)) |
| 47 |
set_pointer_arg(6, timeout_uaddr) |
| 48 |
%) |
| 49 |
|
| 50 |
probe syscall.semtimedop = dw_syscall.semtimedop !, nd_syscall.semtimedop ? {} |
| 51 |
probe syscall.semtimedop.return = dw_syscall.semtimedop.return !, |
| 52 |
nd_syscall.semtimedop.return ? {} |
| 53 |
|
| 54 |
# dw_semtimedop _____________________________________________________ |
| 55 |
|
| 56 |
probe dw_syscall.semtimedop = kernel.function("sys_semtimedop").call ? |
| 57 |
{ |
| 58 |
# Since semop() can be implemented via semtimedop(), we need |
| 59 |
# to make sure this is a real semtimedop syscall (or a |
| 60 |
# multiplexed one via ipc()). |
| 61 |
@__syscall_gate2(@const("__NR_semtimedop"), @const("__NR_ipc")) |
| 62 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 63 |
semid = __int32($semid) |
| 64 |
sops_uaddr = $tsops |
| 65 |
nsops = __uint32($nsops) |
| 66 |
timeout_uaddr = $timeout |
| 67 |
timeout_str = _struct_timespec_u(timeout_uaddr, 1) |
| 68 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 69 |
} |
| 70 |
probe dw_syscall.semtimedop.return = kernel.function("sys_semtimedop").return ? |
| 71 |
{ |
| 72 |
@__syscall_gate2(@const("__NR_semtimedop"), @const("__NR_ipc")) |
| 73 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 74 |
@SYSC_RETVALSTR($return) |
| 75 |
} |
| 76 |
|
| 77 |
# nd_semtimedop _____________________________________________________ |
| 78 |
|
| 79 |
probe nd_syscall.semtimedop = nd1_syscall.semtimedop!, nd2_syscall.semtimedop!, tp_syscall.semtimedop |
| 80 |
{ } |
| 81 |
|
| 82 |
probe nd1_syscall.semtimedop = kprobe.function("sys_semtimedop") ? |
| 83 |
{ |
| 84 |
@__syscall_gate2(@const("__NR_semtimedop"), @const("__NR_ipc")) |
| 85 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 86 |
asmlinkage() |
| 87 |
semid = int_arg(1) |
| 88 |
sops_uaddr = pointer_arg(2) |
| 89 |
nsops = uint_arg(3) |
| 90 |
timeout_uaddr = pointer_arg(4) |
| 91 |
timeout_str = _struct_timespec_u(timeout_uaddr, 1) |
| 92 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 93 |
} |
| 94 |
|
| 95 |
/* kernel 4.17+ */ |
| 96 |
probe nd2_syscall.semtimedop = kprobe.function(@arch_syscall_prefix "sys_semtimedop") ? |
| 97 |
{ |
| 98 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 99 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 100 |
semid = int_arg(1) |
| 101 |
sops_uaddr = pointer_arg(2) |
| 102 |
nsops = uint_arg(3) |
| 103 |
timeout_uaddr = pointer_arg(4) |
| 104 |
timeout_str = _struct_timespec_u(timeout_uaddr, 1) |
| 105 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 106 |
}, |
| 107 |
{ |
| 108 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SEMTIMEDOP_REGARGS_STORE %) |
| 109 |
} |
| 110 |
|
| 111 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 112 |
probe tp_syscall.semtimedop = kernel.trace("sys_enter") |
| 113 |
{ |
| 114 |
__set_syscall_pt_regs($regs) |
| 115 |
@__syscall_gate(@const("__NR_semtimedop")) |
| 116 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 117 |
semid = int_arg(1) |
| 118 |
sops_uaddr = pointer_arg(2) |
| 119 |
nsops = uint_arg(3) |
| 120 |
timeout_uaddr = pointer_arg(4) |
| 121 |
timeout_str = _struct_timespec_u(timeout_uaddr, 1) |
| 122 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 123 |
}, |
| 124 |
{ |
| 125 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SEMTIMEDOP_REGARGS_STORE %) |
| 126 |
} |
| 127 |
|
| 128 |
probe nd_syscall.semtimedop.return = nd1_syscall.semtimedop.return!, nd2_syscall.semtimedop.return!, tp_syscall.semtimedop.return |
| 129 |
{ } |
| 130 |
|
| 131 |
probe nd1_syscall.semtimedop.return = kprobe.function("sys_semtimedop").return ? |
| 132 |
{ |
| 133 |
@__syscall_gate2(@const("__NR_semtimedop"), @const("__NR_ipc")) |
| 134 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 135 |
@SYSC_RETVALSTR(returnval()) |
| 136 |
} |
| 137 |
|
| 138 |
/* kernel 4.17+ */ |
| 139 |
probe nd2_syscall.semtimedop.return = kprobe.function(@arch_syscall_prefix "sys_semtimedop").return ? |
| 140 |
{ |
| 141 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 142 |
@SYSC_RETVALSTR(returnval()) |
| 143 |
} |
| 144 |
|
| 145 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 146 |
probe tp_syscall.semtimedop.return = kernel.trace("sys_exit") |
| 147 |
{ |
| 148 |
__set_syscall_pt_regs($regs) |
| 149 |
@__syscall_gate(@const("__NR_semtimedop")) |
| 150 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 151 |
@SYSC_RETVALSTR($ret) |
| 152 |
} |
| 153 |
|
| 154 |
# compat_sys_semtimedop ________________________________________ |
| 155 |
# |
| 156 |
# long compat_sys_semtimedop(int semid, struct sembuf __user *tsems, |
| 157 |
# unsigned nsops, const struct compat_timespec __user *timeout) |
| 158 |
# |
| 159 |
|
| 160 |
probe syscall.compat_sys_semtimedop = dw_syscall.compat_sys_semtimedop !, |
| 161 |
nd_syscall.compat_sys_semtimedop ? {} |
| 162 |
probe syscall.compat_sys_semtimedop.return = dw_syscall.compat_sys_semtimedop.return !, |
| 163 |
nd_syscall.compat_sys_semtimedop.return ? {} |
| 164 |
|
| 165 |
# dw_compat_sys_semtimedop _____________________________________________________ |
| 166 |
|
| 167 |
probe dw_syscall.compat_sys_semtimedop = __syscall.compat_semtimedop ?, |
| 168 |
__syscall.compat_ipc.semtimedop ? |
| 169 |
{ |
| 170 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 171 |
timeout_str = _struct_compat_timespec_u(timeout_uaddr, 1) |
| 172 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 173 |
} |
| 174 |
probe __syscall.compat_semtimedop = |
| 175 |
kernel.function("compat_sys_semtimedop").call ? |
| 176 |
{ |
| 177 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 178 |
semid = __int32($semid) |
| 179 |
sops_uaddr = $tsems |
| 180 |
nsops = __uint32($nsops) |
| 181 |
timeout_uaddr = $timeout |
| 182 |
} |
| 183 |
probe __syscall.compat_ipc.semtimedop = |
| 184 |
kernel.function("compat_sys_ipc").call ?, |
| 185 |
kernel.function("sys32_ipc").call ? |
| 186 |
{ |
| 187 |
if ($call != @const("SEMTIMEDOP")) next; |
| 188 |
semid = __int32($first) |
| 189 |
sops_uaddr = $ptr |
| 190 |
nsops = __uint32($second) |
| 191 |
timeout_uaddr = @choose_defined($fifth, $third) |
| 192 |
} |
| 193 |
probe dw_syscall.compat_sys_semtimedop.return = |
| 194 |
__syscall.compat_sys_semtimedop.return ?, |
| 195 |
__syscall.compat_ipc.semtimedop.return ? |
| 196 |
{ |
| 197 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 198 |
@SYSC_RETVALSTR($return) |
| 199 |
} |
| 200 |
probe __syscall.compat_sys_semtimedop.return = |
| 201 |
kernel.function("compat_sys_semtimedop").return ? |
| 202 |
{ |
| 203 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 204 |
} |
| 205 |
probe __syscall.compat_ipc.semtimedop.return = |
| 206 |
kernel.function("compat_sys_ipc").return ?, |
| 207 |
kernel.function("sys32_ipc").return ? |
| 208 |
{ |
| 209 |
if (@entry($call) != @const("SEMTIMEDOP")) next; |
| 210 |
} |
| 211 |
|
| 212 |
# nd_compat_sys_semtimedop _____________________________________________________ |
| 213 |
|
| 214 |
probe nd_syscall.compat_sys_semtimedop = nd1_syscall.compat_sys_semtimedop!, nd2_syscall.compat_sys_semtimedop!, tp_syscall.compat_sys_semtimedop |
| 215 |
{ } |
| 216 |
|
| 217 |
probe nd1_syscall.compat_sys_semtimedop = __nd1_syscall.compat_semtimedop ?, |
| 218 |
__nd1_syscall.compat_ipc.semtimedop ? |
| 219 |
{ |
| 220 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 221 |
timeout_str = _struct_compat_timespec_u(timeout_uaddr, 1) |
| 222 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 223 |
} |
| 224 |
probe __nd1_syscall.compat_semtimedop = |
| 225 |
kprobe.function("compat_sys_semtimedop") ? |
| 226 |
{ |
| 227 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 228 |
semid = int_arg(1) |
| 229 |
sops_uaddr = pointer_arg(2) |
| 230 |
nsops = uint_arg(3) |
| 231 |
timeout_uaddr = pointer_arg(4) |
| 232 |
} |
| 233 |
probe __nd1_syscall.compat_ipc.semtimedop = |
| 234 |
__nd1_syscall.compat_ipc.semtimedop.sys_ipc ?, |
| 235 |
__nd1_syscall.compat_ipc.semtimedop.sys32_ipc ? |
| 236 |
{ |
| 237 |
if (int_arg(1) != @const("SEMTIMEDOP")) next; |
| 238 |
semid = int_arg(2) |
| 239 |
sops_uaddr = pointer_arg(5) |
| 240 |
nsops = uint_arg(3) |
| 241 |
} |
| 242 |
probe __nd1_syscall.compat_ipc.semtimedop.sys_ipc = |
| 243 |
kprobe.function("compat_sys_ipc") ? |
| 244 |
{ |
| 245 |
timeout_uaddr = pointer_arg(6) |
| 246 |
} |
| 247 |
probe __nd1_syscall.compat_ipc.semtimedop.sys32_ipc = |
| 248 |
kprobe.function("sys32_ipc") ? |
| 249 |
{ |
| 250 |
%( arch == "s390" %? |
| 251 |
timeout_uaddr = pointer_arg(4) |
| 252 |
%: |
| 253 |
timeout_uaddr = pointer_arg(6) |
| 254 |
%) |
| 255 |
} |
| 256 |
|
| 257 |
/* kernel 4.17+ */ |
| 258 |
probe nd2_syscall.compat_sys_semtimedop = |
| 259 |
kprobe.function(@arch_syscall_prefix "compat_sys_ipc") ? |
| 260 |
{ |
| 261 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 262 |
if (int_arg(1) != @const("SEMTIMEDOP")) next; |
| 263 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 264 |
semid = int_arg(2) |
| 265 |
sops_uaddr = pointer_arg(5) |
| 266 |
nsops = uint_arg(3) |
| 267 |
timeout_uaddr = pointer_arg(6) |
| 268 |
timeout_str = _struct_compat_timespec_u(timeout_uaddr, 1) |
| 269 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 270 |
}, |
| 271 |
{ |
| 272 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_COMPAT_SEMTIMEDOP_REGARGS_STORE %) |
| 273 |
} |
| 274 |
|
| 275 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 276 |
probe tp_syscall.compat_sys_semtimedop = kernel.trace("sys_enter") |
| 277 |
{ |
| 278 |
__set_syscall_pt_regs($regs) |
| 279 |
@__compat_syscall_gate(@const("__NR_compat_ipc")) |
| 280 |
if (int_arg(1) != @const("SEMTIMEDOP")) next; |
| 281 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 282 |
semid = int_arg(2) |
| 283 |
sops_uaddr = pointer_arg(5) |
| 284 |
nsops = uint_arg(3) |
| 285 |
timeout_uaddr = pointer_arg(6) |
| 286 |
timeout_str = _struct_compat_timespec_u(timeout_uaddr, 1) |
| 287 |
@_SYSCALL_SEMTIMEDOP_ARGSTR |
| 288 |
}, |
| 289 |
{ |
| 290 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_COMPAT_SEMTIMEDOP_REGARGS_STORE %) |
| 291 |
} |
| 292 |
|
| 293 |
probe nd_syscall.compat_sys_semtimedop.return = nd1_syscall.compat_sys_semtimedop.return!, nd2_syscall.compat_sys_semtimedop.return!, tp_syscall.compat_sys_semtimedop.return |
| 294 |
{ } |
| 295 |
|
| 296 |
probe nd1_syscall.compat_sys_semtimedop.return = |
| 297 |
__nd1_syscall.compat_sys_semtimedop.return ?, |
| 298 |
__nd1_syscall.compat_ipc.semtimedop.return ? |
| 299 |
{ |
| 300 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 301 |
@SYSC_RETVALSTR(returnval()) |
| 302 |
} |
| 303 |
probe __nd1_syscall.compat_sys_semtimedop.return = |
| 304 |
kprobe.function("compat_sys_semtimedop").return ? |
| 305 |
{ |
| 306 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 307 |
} |
| 308 |
probe __nd1_syscall.compat_ipc.semtimedop.return = |
| 309 |
kprobe.function("compat_sys_ipc").return ?, |
| 310 |
kprobe.function("sys32_ipc").return ? |
| 311 |
{ |
| 312 |
if (@entry(int_arg(1)) != @const("SEMTIMEDOP")) next; |
| 313 |
} |
| 314 |
|
| 315 |
/* kernel 4.17+ */ |
| 316 |
probe nd2_syscall.compat_sys_semtimedop.return = |
| 317 |
kprobe.function(@arch_syscall_prefix "compat_sys_ipc").return ? |
| 318 |
{ |
| 319 |
__set_syscall_pt_regs(@entry(pointer_arg(1))) |
| 320 |
if (int_arg(1) != @const("SEMTIMEDOP")) next; |
| 321 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 322 |
@SYSC_RETVALSTR(returnval()) |
| 323 |
} |
| 324 |
|
| 325 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 326 |
probe tp_syscall.compat_sys_semtimedop.return = kernel.trace("sys_exit") |
| 327 |
{ |
| 328 |
__set_syscall_pt_regs($regs) |
| 329 |
@__compat_syscall_gate(@const("__NR_compat_ipc")) |
| 330 |
if (int_arg(1) != @const("SEMTIMEDOP")) next; |
| 331 |
@_SYSCALL_SEMTIMEDOP_NAME |
| 332 |
@SYSC_RETVALSTR($ret) |
| 333 |
} |