| 1 |
# faccessat2 __________________________________________________ |
| 2 |
# new function faccessat2() was added to Linux in version 5.8. |
| 3 |
# with commit c8ffd8bcdd28296a198f237cc595148a8d4adfbe |
| 4 |
# |
| 5 |
# from man faccessat2: the raw Linux faccessat() system call does not have a |
| 6 |
# flags argument. To allow for a proper implementation, Linux 5.8 added |
| 7 |
# the faccessat2() system call, which supports the flags argument and allows |
| 8 |
# a correct implementation of the faccessat() wrapper function (in glibc) |
| 9 |
# |
| 10 |
# long sys_faccessat2(int dfd, const char __user *filename, int mode, int flags) |
| 11 |
|
| 12 |
@define _SYSCALL_FACCESSAT2_NAME |
| 13 |
%( |
| 14 |
name = "faccessat2" |
| 15 |
%) |
| 16 |
|
| 17 |
@define _SYSCALL_FACCESSAT2_ARGSTR |
| 18 |
%( |
| 19 |
argstr = sprintf("%s, %s, %s, %s", dirfd_str, pathname, mode_str, flags_str) |
| 20 |
%) |
| 21 |
|
| 22 |
@define _SYSCALL_FACCESSAT2_REGARGS |
| 23 |
%( |
| 24 |
dirfd = int_arg(1) |
| 25 |
dirfd_str = _dfd_str(dirfd) |
| 26 |
pathname = user_string_quoted(pointer_arg(2)) |
| 27 |
pathname_unquoted = user_string_nofault(pointer_arg(2)) |
| 28 |
mode = int_arg(3) |
| 29 |
mode_str = _access_mode_str(mode) |
| 30 |
flags = int_arg(4) |
| 31 |
flags_str = _faccessat2_flags_str(flags) |
| 32 |
%) |
| 33 |
|
| 34 |
@define _SYSCALL_FACCESSAT2_REGARGS_STORE |
| 35 |
%( |
| 36 |
if (@probewrite(dirfd)) |
| 37 |
set_int_arg(1, dirfd) |
| 38 |
|
| 39 |
if (@probewrite(pathname_unquoted)) |
| 40 |
set_user_string_arg(pointer_arg(2), pathname_unquoted) |
| 41 |
|
| 42 |
if (@probewrite(mode)) |
| 43 |
set_int_arg(3, mode) |
| 44 |
|
| 45 |
if (@probewrite(flags)) |
| 46 |
set_int_arg(4, flags) |
| 47 |
%) |
| 48 |
|
| 49 |
probe syscall.faccessat2 = dw_syscall.faccessat2 !, nd_syscall.faccessat2 ? {} |
| 50 |
probe syscall.faccessat2.return = dw_syscall.faccessat2.return !, nd_syscall.faccessat2.return ? {} |
| 51 |
|
| 52 |
# dw_faccessat2 _____________________________________________________ |
| 53 |
|
| 54 |
probe dw_syscall.faccessat2 = kernel.function("sys_faccessat2").call ? |
| 55 |
{ |
| 56 |
@__syscall_compat_gate(@const("__NR_faccessat2"), |
| 57 |
@const("__NR_compat_faccessat2")) |
| 58 |
@_SYSCALL_FACCESSAT2_NAME |
| 59 |
dirfd = __int32($dfd) |
| 60 |
dirfd_str = _dfd_str(__int32($dfd)) |
| 61 |
pathname = user_string_quoted($filename) |
| 62 |
mode = __int32($mode) |
| 63 |
mode_str = _access_mode_str(__int32($mode)) |
| 64 |
flags = __int32($flags) |
| 65 |
flags_str = _faccessat2_flags_str(__int32($flags)) |
| 66 |
@_SYSCALL_FACCESSAT2_ARGSTR |
| 67 |
} |
| 68 |
probe dw_syscall.faccessat2.return = kernel.function("sys_faccessat2").return ? |
| 69 |
{ |
| 70 |
@__syscall_compat_gate(@const("__NR_faccessat2"), |
| 71 |
@const("__NR_compat_faccessat2")) |
| 72 |
@_SYSCALL_FACCESSAT2_NAME |
| 73 |
@SYSC_RETVALSTR($return) |
| 74 |
} |
| 75 |
|
| 76 |
# nd_faccessat2 _____________________________________________________ |
| 77 |
|
| 78 |
probe nd_syscall.faccessat2 = nd1_syscall.faccessat2!, nd2_syscall.faccessat2!, tp_syscall.faccessat2 |
| 79 |
{ } |
| 80 |
|
| 81 |
probe nd1_syscall.faccessat2 = kprobe.function("sys_faccessat2") ? |
| 82 |
{ |
| 83 |
@__syscall_compat_gate(@const("__NR_faccessat2"), |
| 84 |
@const("__NR_compat_faccessat2")) |
| 85 |
@_SYSCALL_FACCESSAT2_NAME |
| 86 |
asmlinkage() |
| 87 |
@_SYSCALL_FACCESSAT2_REGARGS |
| 88 |
@_SYSCALL_FACCESSAT2_ARGSTR |
| 89 |
} |
| 90 |
|
| 91 |
/* kernel 4.17+ */ |
| 92 |
probe nd2_syscall.faccessat2 = kprobe.function(@arch_syscall_prefix "sys_faccessat2") ? |
| 93 |
{ |
| 94 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 95 |
@_SYSCALL_FACCESSAT2_NAME |
| 96 |
@_SYSCALL_FACCESSAT2_REGARGS |
| 97 |
@_SYSCALL_FACCESSAT2_ARGSTR |
| 98 |
}, |
| 99 |
{ |
| 100 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_FACCESSAT2_REGARGS_STORE %) |
| 101 |
} |
| 102 |
|
| 103 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 104 |
probe tp_syscall.faccessat2 = kernel.trace("sys_enter") |
| 105 |
{ |
| 106 |
__set_syscall_pt_regs($regs) |
| 107 |
@__syscall_compat_gate(@const("__NR_faccessat2"), |
| 108 |
@const("__NR_compat_faccessat2")) |
| 109 |
@_SYSCALL_FACCESSAT2_NAME |
| 110 |
@_SYSCALL_FACCESSAT2_REGARGS |
| 111 |
@_SYSCALL_FACCESSAT2_ARGSTR |
| 112 |
}, |
| 113 |
{ |
| 114 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_FACCESSAT2_REGARGS_STORE %) |
| 115 |
} |
| 116 |
|
| 117 |
probe nd_syscall.faccessat2.return = nd1_syscall.faccessat2.return!, nd2_syscall.faccessat2.return!, tp_syscall.faccessat2.return |
| 118 |
{ } |
| 119 |
|
| 120 |
probe nd1_syscall.faccessat2.return = kprobe.function("sys_faccessat2").return ? |
| 121 |
{ |
| 122 |
@__syscall_compat_gate(@const("__NR_faccessat2"), |
| 123 |
@const("__NR_compat_faccessat2")) |
| 124 |
@_SYSCALL_FACCESSAT2_NAME |
| 125 |
@SYSC_RETVALSTR(returnval()) |
| 126 |
} |
| 127 |
|
| 128 |
/* kernel 4.17+ */ |
| 129 |
probe nd2_syscall.faccessat2.return = kprobe.function(@arch_syscall_prefix "sys_faccessat2").return ? |
| 130 |
{ |
| 131 |
@_SYSCALL_FACCESSAT2_NAME |
| 132 |
@SYSC_RETVALSTR(returnval()) |
| 133 |
} |
| 134 |
|
| 135 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 136 |
probe tp_syscall.faccessat2.return = kernel.trace("sys_exit") |
| 137 |
{ |
| 138 |
__set_syscall_pt_regs($regs) |
| 139 |
@__syscall_compat_gate(@const("__NR_faccessat2"), |
| 140 |
@const("__NR_compat_faccessat2")) |
| 141 |
@_SYSCALL_FACCESSAT2_NAME |
| 142 |
@SYSC_RETVALSTR($ret) |
| 143 |
} |