| 1 |
# open _______________________________________________________ |
| 2 |
# long sys_open(const char __user * filename, int flags, int mode) |
| 3 |
# (obsolete) long sys32_open(const char * filename, int flags, int mode) |
| 4 |
# |
| 5 |
|
| 6 |
@define _SYSCALL_OPEN_NAME |
| 7 |
%( |
| 8 |
name = "open" |
| 9 |
%) |
| 10 |
|
| 11 |
@define _SYSCALL_OPEN_ARGSTR |
| 12 |
%( |
| 13 |
if (flags & @const("O_CREAT")) |
| 14 |
argstr = sprintf("%s, %s, %#o", filename, flags_str, mode) |
| 15 |
else |
| 16 |
argstr = sprintf("%s, %s", filename, flags_str) |
| 17 |
%) |
| 18 |
|
| 19 |
@define _SYSCALL_OPEN_REGARGS |
| 20 |
%( |
| 21 |
filename = user_string_quoted(pointer_arg(1)) |
| 22 |
filename_unquoted = user_string_nofault(pointer_arg(1)) |
| 23 |
flags = int_arg(2) |
| 24 |
flags_str = _sys_open_flag_str(flags) |
| 25 |
mode = uint_arg(3) |
| 26 |
%) |
| 27 |
|
| 28 |
@define _SYSCALL_OPEN_REGARGS_STORE |
| 29 |
%( |
| 30 |
if (@probewrite(filename_unquoted)) |
| 31 |
set_user_string_arg(pointer_arg(1), filename_unquoted) |
| 32 |
|
| 33 |
if (@probewrite(flags)) |
| 34 |
set_int_arg(2, flags) |
| 35 |
|
| 36 |
if (@probewrite(mode)) |
| 37 |
set_uint_arg(3, mode) |
| 38 |
%) |
| 39 |
|
| 40 |
probe syscall.open = dw_syscall.open !, nd_syscall.open ? {} |
| 41 |
probe syscall.open.return = dw_syscall.open.return !, nd_syscall.open.return ? {} |
| 42 |
|
| 43 |
# dw_open _____________________________________________________ |
| 44 |
|
| 45 |
probe dw_syscall.open = __syscall.compat_open ?, __syscall.open |
| 46 |
{ |
| 47 |
@__syscall_compat_gate(@const("__NR_open"), @const("__NR_compat_open")) |
| 48 |
@_SYSCALL_OPEN_NAME |
| 49 |
flags = __int32($flags) |
| 50 |
flags_str = _sys_open_flag_str(flags) |
| 51 |
@_SYSCALL_OPEN_ARGSTR |
| 52 |
} |
| 53 |
probe __syscall.compat_open = kernel.function("compat_sys_open").call ?, |
| 54 |
kernel.function("sys32_open").call ? |
| 55 |
{ |
| 56 |
// On some platforms, $filename and $mode are longs on the |
| 57 |
// kernel side. Truncate these down to 32 bits. |
| 58 |
filename = user_string_quoted(__uint32($filename)) |
| 59 |
mode = __uint32($mode) |
| 60 |
} |
| 61 |
probe __syscall.open = kernel.function("sys_open").call |
| 62 |
{ |
| 63 |
filename = user_string_quoted($filename) |
| 64 |
mode = __uint32($mode) |
| 65 |
} |
| 66 |
probe dw_syscall.open.return = kernel.function("compat_sys_open").return ?, |
| 67 |
kernel.function("sys32_open").return ?, |
| 68 |
kernel.function("sys_open").return ? |
| 69 |
{ |
| 70 |
@__syscall_compat_gate(@const("__NR_open"), @const("__NR_compat_open")) |
| 71 |
@_SYSCALL_OPEN_NAME |
| 72 |
@SYSC_RETVALSTR($return) |
| 73 |
} |
| 74 |
|
| 75 |
# nd_open _____________________________________________________ |
| 76 |
|
| 77 |
probe nd_syscall.open = nd1_syscall.open!, nd2_syscall.open!, tp_syscall.open |
| 78 |
{ } |
| 79 |
|
| 80 |
probe nd1_syscall.open = kprobe.function("compat_sys_open") ?, |
| 81 |
kprobe.function("sys32_open") ?, |
| 82 |
kprobe.function("sys_open") ? |
| 83 |
{ |
| 84 |
@__syscall_compat_gate(@const("__NR_open"), @const("__NR_compat_open")) |
| 85 |
@_SYSCALL_OPEN_NAME |
| 86 |
asmlinkage() |
| 87 |
@_SYSCALL_OPEN_REGARGS |
| 88 |
@_SYSCALL_OPEN_ARGSTR |
| 89 |
} |
| 90 |
|
| 91 |
probe nd2_syscall.open = kprobe.function(@arch_syscall_prefix "compat_sys_open") ?, |
| 92 |
kprobe.function(@arch_syscall_prefix "sys_open") ? |
| 93 |
{ |
| 94 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 95 |
@_SYSCALL_OPEN_NAME |
| 96 |
@_SYSCALL_OPEN_REGARGS |
| 97 |
@_SYSCALL_OPEN_ARGSTR |
| 98 |
}, |
| 99 |
{ |
| 100 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_OPEN_REGARGS_STORE %) |
| 101 |
} |
| 102 |
|
| 103 |
/* kernel 3.5+, but undesirable because of it affects all syscalls */ |
| 104 |
probe tp_syscall.open = kernel.trace("sys_enter") |
| 105 |
{ |
| 106 |
__set_syscall_pt_regs($regs) |
| 107 |
@__syscall_compat_gate(@const("__NR_open"), @const("__NR_compat_open")) |
| 108 |
@_SYSCALL_OPEN_NAME |
| 109 |
@_SYSCALL_OPEN_REGARGS |
| 110 |
@_SYSCALL_OPEN_ARGSTR |
| 111 |
}, |
| 112 |
{ |
| 113 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_OPEN_REGARGS_STORE %) |
| 114 |
} |
| 115 |
|
| 116 |
probe nd_syscall.open.return = nd1_syscall.open.return!, nd2_syscall.open.return!, tp_syscall.open.return |
| 117 |
{ } |
| 118 |
|
| 119 |
probe nd1_syscall.open.return = kprobe.function("compat_sys_open").return ?, |
| 120 |
kprobe.function("sys32_open").return ?, |
| 121 |
kprobe.function("sys_open").return ? |
| 122 |
{ |
| 123 |
@__syscall_compat_gate(@const("__NR_open"), @const("__NR_compat_open")) |
| 124 |
@_SYSCALL_OPEN_NAME |
| 125 |
@SYSC_RETVALSTR(returnval()) |
| 126 |
} |
| 127 |
|
| 128 |
/* kernel 4.17+ */ |
| 129 |
probe nd2_syscall.open.return = kprobe.function(@arch_syscall_prefix "compat_sys_open").return ?, |
| 130 |
kprobe.function(@arch_syscall_prefix "sys_open").return ? |
| 131 |
{ |
| 132 |
@_SYSCALL_OPEN_NAME |
| 133 |
@SYSC_RETVALSTR(returnval()) |
| 134 |
} |
| 135 |
|
| 136 |
/* kernel 3.5+, but undesirable because of it affects all syscalls */ |
| 137 |
probe tp_syscall.open.return = kernel.trace("sys_exit") |
| 138 |
{ |
| 139 |
__set_syscall_pt_regs($regs) |
| 140 |
@__syscall_compat_gate(@const("__NR_open"), @const("__NR_compat_open")) |
| 141 |
@_SYSCALL_OPEN_NAME |
| 142 |
@SYSC_RETVALSTR($ret) |
| 143 |
} |