| 1 |
# msgrcv _____________________________________________________ |
| 2 |
# long sys_msgrcv (int msqid, |
| 3 |
# struct msgbuf __user *msgp, |
| 4 |
# size_t msgsz, |
| 5 |
# long msgtyp, |
| 6 |
# int msgflg) |
| 7 |
# |
| 8 |
|
| 9 |
@define _SYSCALL_MSGRCV_NAME |
| 10 |
%( |
| 11 |
name = "msgrcv" |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_MSGRCV_ARGSTR |
| 15 |
%( |
| 16 |
argstr = sprintf("%d, %p, %u, %d, %s", msqid, msgp_uaddr, msgsz, |
| 17 |
msgtyp, msgflg_str) |
| 18 |
%) |
| 19 |
|
| 20 |
@define _SYSCALL_MSGRCV_REGARGS |
| 21 |
%( |
| 22 |
msqid = int_arg(1) |
| 23 |
msgp_uaddr = pointer_arg(2) |
| 24 |
msgsz = ulong_arg(3) |
| 25 |
msgtyp = long_arg(4) |
| 26 |
msgflg = int_arg(5) |
| 27 |
msgflg_str = _stp_msgflg_str(msgflg) |
| 28 |
%) |
| 29 |
|
| 30 |
@define _SYSCALL_MSGRCV_REGARGS_STORE |
| 31 |
%( |
| 32 |
if (@probewrite(msqid)) |
| 33 |
set_int_arg(1, msqid) |
| 34 |
|
| 35 |
if (@probewrite(msgp_uaddr)) |
| 36 |
set_pointer_arg(2, msgp_uaddr) |
| 37 |
|
| 38 |
if (@probewrite(msgsz)) |
| 39 |
set_ulong_arg(3, msgsz) |
| 40 |
|
| 41 |
if (@probewrite(msgtyp)) |
| 42 |
set_long_arg(4, msgtyp) |
| 43 |
|
| 44 |
if (@probewrite(msgflg)) |
| 45 |
set_int_arg(5, msgflg) |
| 46 |
%) |
| 47 |
|
| 48 |
probe syscall.msgrcv = dw_syscall.msgrcv !, nd_syscall.msgrcv ? {} |
| 49 |
probe syscall.msgrcv.return = dw_syscall.msgrcv.return !, |
| 50 |
nd_syscall.msgrcv.return ? {} |
| 51 |
|
| 52 |
# dw_msgrcv _____________________________________________________ |
| 53 |
|
| 54 |
probe dw_syscall.msgrcv = kernel.function("sys_msgrcv").call ? |
| 55 |
{ |
| 56 |
@__syscall_gate_compat_simple |
| 57 |
@_SYSCALL_MSGRCV_NAME |
| 58 |
msqid = __int32($msqid) |
| 59 |
msgp_uaddr = $msgp |
| 60 |
msgsz = __ulong($msgsz) |
| 61 |
msgtyp = $msgtyp |
| 62 |
msgflg = __int32($msgflg) |
| 63 |
msgflg_str = _stp_msgflg_str(__int32($msgflg)) |
| 64 |
@_SYSCALL_MSGRCV_ARGSTR |
| 65 |
} |
| 66 |
probe dw_syscall.msgrcv.return = kernel.function("sys_msgrcv").return ? |
| 67 |
{ |
| 68 |
@__syscall_gate_compat_simple |
| 69 |
@_SYSCALL_MSGRCV_NAME |
| 70 |
@SYSC_RETVALSTR($return) |
| 71 |
} |
| 72 |
|
| 73 |
# nd_msgrcv _____________________________________________________ |
| 74 |
|
| 75 |
probe nd_syscall.msgrcv = nd1_syscall.msgrcv!, nd2_syscall.msgrcv!, tp_syscall.msgrcv |
| 76 |
{ } |
| 77 |
|
| 78 |
probe nd1_syscall.msgrcv = kprobe.function("sys_msgrcv") ? |
| 79 |
{ |
| 80 |
@__syscall_gate_compat_simple |
| 81 |
@_SYSCALL_MSGRCV_NAME |
| 82 |
asmlinkage() |
| 83 |
@_SYSCALL_MSGRCV_REGARGS |
| 84 |
@_SYSCALL_MSGRCV_ARGSTR |
| 85 |
} |
| 86 |
|
| 87 |
/* kernel 4.17+ */ |
| 88 |
probe nd2_syscall.msgrcv = kprobe.function(@arch_syscall_prefix "sys_msgrcv") ? |
| 89 |
{ |
| 90 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 91 |
@_SYSCALL_MSGRCV_NAME |
| 92 |
@_SYSCALL_MSGRCV_REGARGS |
| 93 |
@_SYSCALL_MSGRCV_ARGSTR |
| 94 |
}, |
| 95 |
{ |
| 96 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_MSGRCV_REGARGS_STORE %) |
| 97 |
} |
| 98 |
|
| 99 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 100 |
probe tp_syscall.msgrcv = kernel.trace("sys_enter") |
| 101 |
{ |
| 102 |
__set_syscall_pt_regs($regs) |
| 103 |
@__syscall_gate(@const("__NR_msgrcv")) |
| 104 |
@_SYSCALL_MSGRCV_NAME |
| 105 |
@_SYSCALL_MSGRCV_REGARGS |
| 106 |
@_SYSCALL_MSGRCV_ARGSTR |
| 107 |
}, |
| 108 |
{ |
| 109 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_MSGRCV_REGARGS_STORE %) |
| 110 |
} |
| 111 |
|
| 112 |
probe nd_syscall.msgrcv.return = nd1_syscall.msgrcv.return!, nd2_syscall.msgrcv.return!, tp_syscall.msgrcv.return |
| 113 |
{ } |
| 114 |
|
| 115 |
probe nd1_syscall.msgrcv.return = kprobe.function("sys_msgrcv").return ? |
| 116 |
{ |
| 117 |
@__syscall_gate_compat_simple |
| 118 |
@_SYSCALL_MSGRCV_NAME |
| 119 |
@SYSC_RETVALSTR(returnval()) |
| 120 |
} |
| 121 |
|
| 122 |
/* kernel 4.17+ */ |
| 123 |
probe nd2_syscall.msgrcv.return = kprobe.function(@arch_syscall_prefix "sys_msgrcv").return ? |
| 124 |
{ |
| 125 |
@_SYSCALL_MSGRCV_NAME |
| 126 |
@SYSC_RETVALSTR(returnval()) |
| 127 |
} |
| 128 |
|
| 129 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 130 |
probe tp_syscall.msgrcv.return = kernel.trace("sys_exit") |
| 131 |
{ |
| 132 |
__set_syscall_pt_regs($regs) |
| 133 |
@__syscall_gate(@const("__NR_msgrcv")) |
| 134 |
@_SYSCALL_MSGRCV_NAME |
| 135 |
@SYSC_RETVALSTR($ret) |
| 136 |
} |
| 137 |
|
| 138 |
# compat_sys_msgrcv ________________________________________ |
| 139 |
# |
| 140 |
# long compat_sys_msgrcv(int first, int second, int msgtyp, int third, |
| 141 |
# int version, void __user *uptr) |
| 142 |
# COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp, |
| 143 |
# compat_ssize_t, msgsz, long, msgtyp, int, msgflg) |
| 144 |
# ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC |
| 145 |
# COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second, |
| 146 |
# u32, third, compat_uptr_t, ptr, u32, fifth) |
| 147 |
# endif |
| 148 |
# |
| 149 |
|
| 150 |
probe syscall.compat_sys_msgrcv = dw_syscall.compat_sys_msgrcv !, |
| 151 |
nd_syscall.compat_sys_msgrcv ? {} |
| 152 |
probe syscall.compat_sys_msgrcv.return = dw_syscall.compat_sys_msgrcv.return !, |
| 153 |
nd_syscall.compat_sys_msgrcv.return ? {} |
| 154 |
|
| 155 |
# dw_compat_sys_msgrcv _____________________________________________________ |
| 156 |
|
| 157 |
probe dw_syscall.compat_sys_msgrcv = __syscall.compat_msgrcv ?, |
| 158 |
__syscall.compat_ipc.msgrcv ? |
| 159 |
{ |
| 160 |
@_SYSCALL_MSGRCV_NAME |
| 161 |
msgflg_str = _stp_msgflg_str(msgflg) |
| 162 |
@_SYSCALL_MSGRCV_ARGSTR |
| 163 |
} |
| 164 |
probe __syscall.compat_msgrcv = kernel.function("compat_sys_msgrcv").call ? |
| 165 |
{ |
| 166 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 167 |
msqid = __int32(@choose_defined($msqid, $first)) |
| 168 |
if (@defined($version)) { |
| 169 |
msgp_uaddr = _stp_compat_msgrcv_msgbuf($uptr, $version) |
| 170 |
msgtyp = _stp_compat_msgrcv_msgtyp($uptr, $version, $msgtyp) |
| 171 |
} |
| 172 |
else { |
| 173 |
msgp_uaddr = $msgp |
| 174 |
msgtyp = __int32($msgtyp) |
| 175 |
} |
| 176 |
msgsz = __uint32(@choose_defined($msgsz, $second)) |
| 177 |
msgflg = __int32(@choose_defined($msgflg, $third)) |
| 178 |
} |
| 179 |
probe __syscall.compat_ipc.msgrcv = kernel.function("compat_sys_ipc").call ?, |
| 180 |
kernel.function("sys32_ipc").call ? |
| 181 |
{ |
| 182 |
if (($call & 0xffff) != @const("MSGRCV")) next; |
| 183 |
msqid = __int32($first) |
| 184 |
msgsz = __uint32($second) |
| 185 |
msgflg = __int32($third) |
| 186 |
|
| 187 |
# __version isn't quite correct (it should be shifted down 16 |
| 188 |
# bits), but all we really need is zero/non-zero. |
| 189 |
__version = $call & 0xffff0000 |
| 190 |
msgp_uaddr = _stp_compat_msgrcv_msgbuf($ptr, __version) |
| 191 |
msgtyp = _stp_compat_msgrcv_msgtyp($ptr, __version, |
| 192 |
@choose_defined($fifth, 0)) |
| 193 |
} |
| 194 |
probe dw_syscall.compat_sys_msgrcv.return = |
| 195 |
__syscall.compat_sys_msgrcv.return ?, |
| 196 |
__syscall.compat_ipc.msgrcv.return ? |
| 197 |
{ |
| 198 |
@_SYSCALL_MSGRCV_NAME |
| 199 |
@SYSC_RETVALSTR($return) |
| 200 |
} |
| 201 |
probe __syscall.compat_sys_msgrcv.return = |
| 202 |
kernel.function("compat_sys_msgrcv").return ? |
| 203 |
{ |
| 204 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 205 |
} |
| 206 |
probe __syscall.compat_ipc.msgrcv.return = |
| 207 |
kernel.function("compat_sys_ipc").return ?, |
| 208 |
kernel.function("sys32_ipc").return ? |
| 209 |
{ |
| 210 |
if ((@entry($call) & 0xffff) != @const("MSGRCV")) next; |
| 211 |
} |
| 212 |
|
| 213 |
# nd_compat_sys_msgrcv _____________________________________________________ |
| 214 |
|
| 215 |
probe nd_syscall.compat_sys_msgrcv = nd1_syscall.compat_sys_msgrcv!, nd2_syscall.compat_sys_msgrcv!, tp_syscall.compat_sys_msgrcv |
| 216 |
{ } |
| 217 |
|
| 218 |
probe nd1_syscall.compat_sys_msgrcv = __nd1_syscall.compat_msgrcv ?, |
| 219 |
__nd1_syscall.compat_ipc.msgrcv ? |
| 220 |
{ |
| 221 |
@_SYSCALL_MSGRCV_NAME |
| 222 |
msgflg_str = _stp_msgflg_str(msgflg) |
| 223 |
@_SYSCALL_MSGRCV_ARGSTR |
| 224 |
} |
| 225 |
probe __nd1_syscall.compat_msgrcv = kprobe.function("compat_sys_msgrcv") ? |
| 226 |
{ |
| 227 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 228 |
asmlinkage() |
| 229 |
msqid = int_arg(1) |
| 230 |
%(kernel_v >= "3.15.0" %? |
| 231 |
msgp_uaddr = pointer_arg(2) |
| 232 |
msgsz = uint_arg(3) |
| 233 |
msgtyp = long_arg(4) |
| 234 |
msgflg = int_arg(5) |
| 235 |
%: |
| 236 |
__version = int_arg(5) |
| 237 |
__uptr = pointer_arg(6) |
| 238 |
msgp_uaddr = _stp_compat_msgrcv_msgbuf(__uptr, __version) |
| 239 |
msgtyp = _stp_compat_msgrcv_msgtyp(__uptr, __version, int_arg(3)) |
| 240 |
msgsz = uint_arg(2) |
| 241 |
msgflg = int_arg(4) |
| 242 |
%) |
| 243 |
} |
| 244 |
|
| 245 |
// What is going on here? compat_sys_ipc() takes 6 arguments and |
| 246 |
// sys32_ipc() takes 5. That last extra argument is passed to |
| 247 |
// _stp_compat_msgrcv_msgtype(). So, we'll need to break this down |
| 248 |
// into 2 subprobes. To make sure we keep things in sync, we'll put the |
| 249 |
// common code in a macro. |
| 250 |
@define __ND_SYSCALL_COMPAT_IPC_MSGRCV_CODE |
| 251 |
%( |
| 252 |
asmlinkage() |
| 253 |
if ((uint_arg(1) & 0xffff) != @const("MSGRCV")) next; |
| 254 |
msqid = int_arg(2) |
| 255 |
msgsz = uint_arg(3) |
| 256 |
msgflg = int_arg(4) |
| 257 |
|
| 258 |
# __version isn't quite correct (it should be shifted down 16 |
| 259 |
# bits), but all we really need is zero/non-zero. |
| 260 |
__version = uint_arg(1) & 0xffff0000 |
| 261 |
__uptr = pointer_arg(5) |
| 262 |
msgp_uaddr = _stp_compat_msgrcv_msgbuf(__uptr, __version) |
| 263 |
%) |
| 264 |
|
| 265 |
@define _SYSCALL_COMPAT_IPC_MSGRCV_REGARGS_STORE |
| 266 |
%( |
| 267 |
if (@probewrite(__version)) |
| 268 |
set_uint_arg(1, __version) |
| 269 |
|
| 270 |
if (@probewrite(msqid)) |
| 271 |
set_int_arg(2, msqid) |
| 272 |
|
| 273 |
if (@probewrite(msgsz)) |
| 274 |
set_uint_arg(3, msgsz) |
| 275 |
|
| 276 |
if (@probewrite(msgflg)) |
| 277 |
set_int_arg(4, msgflg) |
| 278 |
|
| 279 |
if (@probewrite(__uptr)) |
| 280 |
set_ponter_arg(5, __uptr) |
| 281 |
%) |
| 282 |
|
| 283 |
probe __nd1_syscall.compat_ipc.msgrcv = __nd1_syscall.compat_sys_ipc.msgrcv ?, |
| 284 |
__nd1_syscall.sys32_ipc.msgrcv ? |
| 285 |
{ |
| 286 |
} |
| 287 |
probe __nd1_syscall.compat_sys_ipc.msgrcv = kprobe.function("compat_sys_ipc") ? |
| 288 |
{ |
| 289 |
@__ND_SYSCALL_COMPAT_IPC_MSGRCV_CODE |
| 290 |
msgtyp = _stp_compat_msgrcv_msgtyp(__uptr, __version, int_arg(6)) |
| 291 |
} |
| 292 |
probe __nd1_syscall.sys32_ipc.msgrcv = kprobe.function("sys32_ipc") ? |
| 293 |
{ |
| 294 |
@__ND_SYSCALL_COMPAT_IPC_MSGRCV_CODE |
| 295 |
msgtyp = _stp_compat_msgrcv_msgtyp(__uptr, __version, 0) |
| 296 |
} |
| 297 |
|
| 298 |
/* kernel 4.17+ */ |
| 299 |
probe nd2_syscall.compat_sys_msgrcv = kprobe.function(@arch_syscall_prefix "compat_sys_ipc") ? |
| 300 |
{ |
| 301 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 302 |
@_SYSCALL_MSGRCV_NAME |
| 303 |
@__ND_SYSCALL_COMPAT_IPC_MSGRCV_CODE |
| 304 |
msgtyp = _stp_compat_msgrcv_msgtyp(__uptr, __version, int_arg(6)) |
| 305 |
msgflg_str = _stp_msgflg_str(msgflg) |
| 306 |
@_SYSCALL_MSGRCV_ARGSTR |
| 307 |
}, |
| 308 |
{ |
| 309 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_COMPAT_IPC_MSGRCV_REGARGS_STORE %) |
| 310 |
} |
| 311 |
|
| 312 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 313 |
probe tp_syscall.compat_sys_msgrcv = kernel.trace("sys_enter") |
| 314 |
{ |
| 315 |
__set_syscall_pt_regs($regs) |
| 316 |
@__compat_syscall_gate(@const("__NR_compat_ipc")) |
| 317 |
if ((uint_arg(1) & 0xffff) != @const("MSGRCV")) next; |
| 318 |
@_SYSCALL_MSGRCV_NAME |
| 319 |
@__ND_SYSCALL_COMPAT_IPC_MSGRCV_CODE |
| 320 |
msgtyp = _stp_compat_msgrcv_msgtyp(__uptr, __version, int_arg(6)) |
| 321 |
msgflg_str = _stp_msgflg_str(msgflg) |
| 322 |
@_SYSCALL_MSGRCV_ARGSTR |
| 323 |
}, |
| 324 |
{ |
| 325 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_COMPAT_IPC_MSGRCV_REGARGS_STORE %) |
| 326 |
} |
| 327 |
|
| 328 |
probe nd_syscall.compat_sys_msgrcv.return = nd1_syscall.compat_sys_msgrcv.return!, nd2_syscall.compat_sys_msgrcv.return!, tp_syscall.compat_sys_msgrcv.return |
| 329 |
{ } |
| 330 |
|
| 331 |
probe nd1_syscall.compat_sys_msgrcv.return = |
| 332 |
__nd1_syscall.compat_sys_msgrcv.return ?, |
| 333 |
__nd1_syscall.compat_ipc.msgrcv.return ? |
| 334 |
{ |
| 335 |
@_SYSCALL_MSGRCV_NAME |
| 336 |
@SYSC_RETVALSTR(returnval()) |
| 337 |
} |
| 338 |
probe __nd1_syscall.compat_sys_msgrcv.return = |
| 339 |
kprobe.function("compat_sys_msgrcv").return ? |
| 340 |
{ |
| 341 |
@__compat_syscall_gate_negative(@const("__NR_compat_ipc")) |
| 342 |
} |
| 343 |
probe __nd1_syscall.compat_ipc.msgrcv.return = |
| 344 |
kprobe.function("compat_sys_ipc").return ?, |
| 345 |
kprobe.function("sys32_ipc").return ? |
| 346 |
{ |
| 347 |
if ((@entry(__asmlinkage_int_arg(1)) & 0xffff) != @const("MSGRCV")) next; |
| 348 |
} |
| 349 |
|
| 350 |
/* kernel 4.17+ */ |
| 351 |
probe nd2_syscall.compat_sys_msgrcv.return = |
| 352 |
kprobe.function(@arch_syscall_prefix "compat_sys_ipc").return ? |
| 353 |
{ |
| 354 |
__set_syscall_pt_regs(@entry(pointer_arg(1))) |
| 355 |
if ((uint_arg(1) & 0xffff) != @const("MSGRCV")) next; |
| 356 |
@_SYSCALL_MSGRCV_NAME |
| 357 |
@SYSC_RETVALSTR(returnval()) |
| 358 |
} |
| 359 |
|
| 360 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 361 |
probe tp_syscall.compat_sys_msgrcv.return = kernel.trace("sys_exit") |
| 362 |
{ |
| 363 |
__set_syscall_pt_regs($regs) |
| 364 |
@__compat_syscall_gate(@const("__NR_compat_ipc")) |
| 365 |
if ((uint_arg(1) & 0xffff) != @const("MSGRCV")) next; |
| 366 |
@_SYSCALL_MSGRCV_NAME |
| 367 |
@SYSC_RETVALSTR($ret) |
| 368 |
} |