| 1 |
# chmod ______________________________________________________ |
| 2 |
# long sys_chmod(const char __user * filename, mode_t mode) |
| 3 |
|
| 4 |
@define _SYSCALL_CHMOD_NAME |
| 5 |
%( |
| 6 |
name = "chmod" |
| 7 |
%) |
| 8 |
|
| 9 |
@define _SYSCALL_CHMOD_ARGSTR |
| 10 |
%( |
| 11 |
argstr = sprintf("%s, %#o", path, mode) |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_CHMOD_REGARGS |
| 15 |
%( |
| 16 |
path = user_string_quoted(pointer_arg(1)) |
| 17 |
path_unquoted = user_string_nofault(pointer_arg(1)) |
| 18 |
mode = uint_arg(2) |
| 19 |
%) |
| 20 |
|
| 21 |
@define _SYSCALL_CHMOD_REGARGS_STORE |
| 22 |
%( |
| 23 |
if (@probewrite(path_unquoted)) |
| 24 |
set_user_string_arg(pointer_arg(1), path_unquoted) |
| 25 |
|
| 26 |
if (@probewrite(mode)) |
| 27 |
set_uint_arg(2, mode) |
| 28 |
%) |
| 29 |
|
| 30 |
probe syscall.chmod = dw_syscall.chmod !, nd_syscall.chmod ? {} |
| 31 |
probe syscall.chmod.return = dw_syscall.chmod.return !, nd_syscall.chmod.return ? {} |
| 32 |
|
| 33 |
# dw_chmod _____________________________________________________ |
| 34 |
|
| 35 |
probe dw_syscall.chmod = kernel.function("sys_chmod").call |
| 36 |
{ |
| 37 |
@_SYSCALL_CHMOD_NAME |
| 38 |
path = user_string_quoted($filename) |
| 39 |
%( arch == "i386" %? |
| 40 |
# Why @cast() here? Even though the user passes an unsigned |
| 41 |
# int (32-bits), some kernels (2.6.32-431.el6.i686) get an |
| 42 |
# unsigned short (16-bits). |
| 43 |
mode = @uint_cast(&$mode) |
| 44 |
%: |
| 45 |
mode = __uint32($mode) |
| 46 |
%) |
| 47 |
@_SYSCALL_CHMOD_ARGSTR |
| 48 |
} |
| 49 |
probe dw_syscall.chmod.return = kernel.function("sys_chmod").return |
| 50 |
{ |
| 51 |
@_SYSCALL_CHMOD_NAME |
| 52 |
@SYSC_RETVALSTR($return) |
| 53 |
} |
| 54 |
|
| 55 |
# nd_chmod _____________________________________________________ |
| 56 |
|
| 57 |
probe nd_syscall.chmod = nd1_syscall.chmod!, nd2_syscall.chmod!, tp_syscall.chmod |
| 58 |
{ } |
| 59 |
|
| 60 |
probe nd1_syscall.chmod = kprobe.function("sys_chmod") ? |
| 61 |
{ |
| 62 |
@_SYSCALL_CHMOD_NAME |
| 63 |
asmlinkage() |
| 64 |
@_SYSCALL_CHMOD_REGARGS |
| 65 |
@_SYSCALL_CHMOD_ARGSTR |
| 66 |
} |
| 67 |
|
| 68 |
/* kernel 4.17+ */ |
| 69 |
probe nd2_syscall.chmod = kprobe.function(@arch_syscall_prefix "sys_chmod") ? |
| 70 |
{ |
| 71 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 72 |
@_SYSCALL_CHMOD_NAME |
| 73 |
@_SYSCALL_CHMOD_REGARGS |
| 74 |
@_SYSCALL_CHMOD_ARGSTR |
| 75 |
}, |
| 76 |
{ |
| 77 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_CHMOD_REGARGS_STORE %) |
| 78 |
} |
| 79 |
|
| 80 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 81 |
probe tp_syscall.chmod = kernel.trace("sys_enter") |
| 82 |
{ |
| 83 |
__set_syscall_pt_regs($regs) |
| 84 |
@__syscall_compat_gate(@const("__NR_chmod"), @const("__NR_compat_chmod")) |
| 85 |
@_SYSCALL_CHMOD_NAME |
| 86 |
@_SYSCALL_CHMOD_REGARGS |
| 87 |
@_SYSCALL_CHMOD_ARGSTR |
| 88 |
}, |
| 89 |
{ |
| 90 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_CHMOD_REGARGS_STORE %) |
| 91 |
} |
| 92 |
|
| 93 |
probe nd_syscall.chmod.return = nd1_syscall.chmod.return!, nd2_syscall.chmod.return!, tp_syscall.chmod.return |
| 94 |
{ } |
| 95 |
|
| 96 |
probe nd1_syscall.chmod.return = kprobe.function("sys_chmod").return ? |
| 97 |
{ |
| 98 |
@_SYSCALL_CHMOD_NAME |
| 99 |
@SYSC_RETVALSTR(returnval()) |
| 100 |
} |
| 101 |
|
| 102 |
/* kernel 4.17+ */ |
| 103 |
probe nd2_syscall.chmod.return = kprobe.function(@arch_syscall_prefix "sys_chmod").return ? |
| 104 |
{ |
| 105 |
@_SYSCALL_CHMOD_NAME |
| 106 |
@SYSC_RETVALSTR(returnval()) |
| 107 |
} |
| 108 |
|
| 109 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 110 |
probe tp_syscall.chmod.return = kernel.trace("sys_exit") |
| 111 |
{ |
| 112 |
__set_syscall_pt_regs($regs) |
| 113 |
@__syscall_compat_gate(@const("__NR_chmod"), @const("__NR_compat_chmod")) |
| 114 |
@_SYSCALL_CHMOD_NAME |
| 115 |
@SYSC_RETVALSTR($ret) |
| 116 |
} |