| 1 |
# truncate ___________________________________________________ |
| 2 |
# |
| 3 |
# sys_truncate(const char __user * path, unsigned long length) |
| 4 |
# sys_truncate64(const char __user * path, loff_t length) |
| 5 |
# COMPAT_SYSCALL_DEFINE2(truncate, const char __user *, path, |
| 6 |
# compat_off_t, length) |
| 7 |
# |
| 8 |
|
| 9 |
@define _SYSCALL_TRUNCATE_NAME |
| 10 |
%( |
| 11 |
name = "truncate" |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_TRUNCATE_ARGSTR |
| 15 |
%( |
| 16 |
argstr = sprintf("%s, %d", path, length) |
| 17 |
%) |
| 18 |
|
| 19 |
@define _SYSCALL_GATE |
| 20 |
%( |
| 21 |
%( arch == "x86_64" || arch == "s390" %? |
| 22 |
// On x86_64 and s390x RHL6 kernels, the 32-bit compat |
| 23 |
// truncate syscall is hooked up directly to sys_truncate(), |
| 24 |
// instead of going through compat_sys_truncate(). |
| 25 |
@__syscall_compat_gate(@const("__NR_truncate"), |
| 26 |
@const("__NR_compat_truncate")) |
| 27 |
%: |
| 28 |
@__syscall_gate_compat_simple |
| 29 |
%) |
| 30 |
%) |
| 31 |
|
| 32 |
probe syscall.truncate = dw_syscall.truncate !, nd_syscall.truncate ? {} |
| 33 |
probe syscall.truncate.return = dw_syscall.truncate.return !, |
| 34 |
nd_syscall.truncate.return ? {} |
| 35 |
|
| 36 |
# dw_truncate _____________________________________________________ |
| 37 |
|
| 38 |
probe dw_syscall.truncate = __syscall.truncate ?, __syscall.truncate64 ?, |
| 39 |
__syscall.compat_truncate ? |
| 40 |
{ |
| 41 |
@_SYSCALL_TRUNCATE_NAME |
| 42 |
path_uaddr = @__pointer($path) |
| 43 |
path = user_string_quoted(path_uaddr) |
| 44 |
@_SYSCALL_TRUNCATE_ARGSTR |
| 45 |
} |
| 46 |
probe __syscall.truncate = kernel.function("sys_truncate").call ? |
| 47 |
{ |
| 48 |
@_SYSCALL_GATE |
| 49 |
length = @__compat_long($length) |
| 50 |
} |
| 51 |
probe __syscall.truncate64 = kernel.function("sys_truncate64").call ? |
| 52 |
{ |
| 53 |
length = $length |
| 54 |
} |
| 55 |
probe __syscall.compat_truncate = kernel.function("compat_sys_truncate").call ? |
| 56 |
{ |
| 57 |
length = __int32($length) |
| 58 |
} |
| 59 |
probe dw_syscall.truncate.return = __syscall.truncate.return ?, |
| 60 |
kernel.function("sys_truncate64").return ?, |
| 61 |
kernel.function("compat_sys_truncate").return ? |
| 62 |
{ |
| 63 |
@_SYSCALL_TRUNCATE_NAME |
| 64 |
@SYSC_RETVALSTR($return) |
| 65 |
} |
| 66 |
probe __syscall.truncate.return = kernel.function("sys_truncate").return ? |
| 67 |
{ |
| 68 |
@_SYSCALL_GATE |
| 69 |
} |
| 70 |
|
| 71 |
# nd_truncate _____________________________________________________ |
| 72 |
|
| 73 |
probe nd_syscall.truncate = nd1_syscall.truncate!, nd2_syscall.truncate!, tp_syscall.truncate |
| 74 |
{ } |
| 75 |
|
| 76 |
probe nd1_syscall.truncate = __nd1_syscall.truncate ?, |
| 77 |
__nd1_syscall.truncate64 ?, |
| 78 |
__nd1_syscall.compat_truncate ? |
| 79 |
{ |
| 80 |
@_SYSCALL_TRUNCATE_NAME |
| 81 |
asmlinkage() |
| 82 |
path_uaddr = pointer_arg(1) |
| 83 |
path = user_string_quoted(path_uaddr) |
| 84 |
@_SYSCALL_TRUNCATE_ARGSTR |
| 85 |
} |
| 86 |
probe __nd1_syscall.truncate = kprobe.function("sys_truncate") ? |
| 87 |
{ |
| 88 |
@_SYSCALL_GATE |
| 89 |
asmlinkage() |
| 90 |
length = long_arg(2) |
| 91 |
} |
| 92 |
probe __nd1_syscall.truncate64 = kprobe.function("sys_truncate64") ? |
| 93 |
{ |
| 94 |
asmlinkage() |
| 95 |
length = longlong_arg(2) |
| 96 |
} |
| 97 |
probe __nd1_syscall.compat_truncate = kprobe.function("compat_sys_truncate") ? |
| 98 |
{ |
| 99 |
asmlinkage() |
| 100 |
length = int_arg(2) |
| 101 |
} |
| 102 |
|
| 103 |
/* kernel 4.17+ */ |
| 104 |
probe nd2_syscall.truncate = __nd2_syscall.truncate ?, |
| 105 |
__nd2_syscall.compat_truncate ? |
| 106 |
{ |
| 107 |
@_SYSCALL_TRUNCATE_NAME |
| 108 |
@_SYSCALL_TRUNCATE_ARGSTR |
| 109 |
} |
| 110 |
probe __nd2_syscall.truncate = kprobe.function(@arch_syscall_prefix "sys_truncate") ? |
| 111 |
{ |
| 112 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 113 |
path_uaddr = pointer_arg(1) |
| 114 |
path = user_string_quoted(path_uaddr) |
| 115 |
path_unquoted = user_string_nofault(pointer_arg(1)) |
| 116 |
length = long_arg(2) |
| 117 |
}, |
| 118 |
{ |
| 119 |
%( @_IS_SREG_KERNEL %? |
| 120 |
if (@probewrite(path_uaddr)) |
| 121 |
set_pointer_arg(1, path_uaddr) |
| 122 |
|
| 123 |
if (@probewrite(path_unquoted)) |
| 124 |
set_user_string_arg(pointer_arg(1), path_unquoted) |
| 125 |
|
| 126 |
if (@probewrite(length)) |
| 127 |
set_long_arg(2, length) |
| 128 |
%) |
| 129 |
} |
| 130 |
probe __nd2_syscall.compat_truncate = kprobe.function(@arch_syscall_prefix "compat_sys_truncate") ? |
| 131 |
{ |
| 132 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 133 |
path_uaddr = pointer_arg(1) |
| 134 |
path = user_string_quoted(path_uaddr) |
| 135 |
path_unquoted = user_string_nofault(pointer_arg(1)) |
| 136 |
length = int_arg(2) |
| 137 |
}, |
| 138 |
{ |
| 139 |
%( @_IS_SREG_KERNEL %? |
| 140 |
if (@probewrite(path_uaddr)) |
| 141 |
set_pointer_arg(1, path_uaddr) |
| 142 |
|
| 143 |
if (@probewrite(path_unquoted)) |
| 144 |
set_user_string_arg(pointer_arg(1), path_unquoted) |
| 145 |
|
| 146 |
if (@probewrite(length)) |
| 147 |
set_int_arg(2, length) |
| 148 |
%) |
| 149 |
} |
| 150 |
|
| 151 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 152 |
probe tp_syscall.truncate = __tp_syscall.truncate ?, |
| 153 |
__tp_syscall.truncate64 ?, |
| 154 |
__tp_syscall.compat_truncate ? |
| 155 |
{ |
| 156 |
@_SYSCALL_TRUNCATE_NAME |
| 157 |
@_SYSCALL_TRUNCATE_ARGSTR |
| 158 |
} |
| 159 |
probe __tp_syscall.truncate = kernel.trace("sys_enter") |
| 160 |
{ |
| 161 |
__set_syscall_pt_regs($regs) |
| 162 |
@__syscall_gate(@const("__NR_truncate")) |
| 163 |
path_uaddr = pointer_arg(1) |
| 164 |
path = user_string_quoted(path_uaddr) |
| 165 |
path_unquoted = user_string_nofault(pointer_arg(1)) |
| 166 |
length = long_arg(2) |
| 167 |
}, |
| 168 |
{ |
| 169 |
%( @_IS_SREG_KERNEL %? |
| 170 |
if (@probewrite(path_uaddr)) |
| 171 |
set_pointer_arg(1, path_uaddr) |
| 172 |
|
| 173 |
if (@probewrite(path_unquoted)) |
| 174 |
set_user_string_arg(pointer_arg(1), path_unquoted) |
| 175 |
|
| 176 |
if (@probewrite(length)) |
| 177 |
set_long_arg(2, length) |
| 178 |
%) |
| 179 |
} |
| 180 |
|
| 181 |
probe __tp_syscall.truncate64 = kernel.trace("sys_enter") |
| 182 |
{ |
| 183 |
__set_syscall_pt_regs($regs) |
| 184 |
@__syscall_gate(@const("__NR_truncate64")) |
| 185 |
path_uaddr = pointer_arg(1) |
| 186 |
path = user_string_quoted(path_uaddr) |
| 187 |
path_unquoted = user_string_nofault(pointer_arg(1)) |
| 188 |
length = longlong_arg(2) |
| 189 |
}, |
| 190 |
{ |
| 191 |
%( @_IS_SREG_KERNEL %? |
| 192 |
if (@probewrite(path_uaddr)) |
| 193 |
set_pointer_arg(1, path_uaddr) |
| 194 |
|
| 195 |
if (@probewrite(path_unquoted)) |
| 196 |
set_user_string_arg(pointer_arg(1), path_unquoted) |
| 197 |
|
| 198 |
if (@probewrite(length)) |
| 199 |
set_longlong_arg(2, length) |
| 200 |
%) |
| 201 |
} |
| 202 |
|
| 203 |
probe __tp_syscall.compat_truncate = kernel.trace("sys_enter") |
| 204 |
{ |
| 205 |
__set_syscall_pt_regs($regs) |
| 206 |
@__compat_syscall_gate(@const("__NR_compat_truncate")) |
| 207 |
path_uaddr = pointer_arg(1) |
| 208 |
path = user_string_quoted(path_uaddr) |
| 209 |
path_unquoted = user_string_nofault(pointer_arg(1)) |
| 210 |
length = int_arg(2) |
| 211 |
}, |
| 212 |
{ |
| 213 |
%( @_IS_SREG_KERNEL %? |
| 214 |
if (@probewrite(path_uaddr)) |
| 215 |
set_pointer_arg(1, path_uaddr) |
| 216 |
|
| 217 |
if (@probewrite(path_unquoted)) |
| 218 |
set_user_string_arg(pointer_arg(1), path_unquoted) |
| 219 |
|
| 220 |
if (@probewrite(length)) |
| 221 |
set_int_arg(2, length) |
| 222 |
%) |
| 223 |
} |
| 224 |
|
| 225 |
probe nd_syscall.truncate.return = nd1_syscall.truncate.return!, nd2_syscall.truncate.return!, tp_syscall.truncate.return |
| 226 |
{ } |
| 227 |
|
| 228 |
probe nd1_syscall.truncate.return = __nd1_syscall.truncate.return ?, |
| 229 |
kprobe.function("sys_truncate64").return ?, |
| 230 |
kprobe.function("compat_sys_truncate").return ? |
| 231 |
{ |
| 232 |
@_SYSCALL_TRUNCATE_NAME |
| 233 |
@SYSC_RETVALSTR(returnval()) |
| 234 |
} |
| 235 |
probe __nd1_syscall.truncate.return = kprobe.function("sys_truncate").return ? |
| 236 |
{ |
| 237 |
@_SYSCALL_GATE |
| 238 |
} |
| 239 |
|
| 240 |
/* kernel 4.17+ */ |
| 241 |
probe nd2_syscall.truncate.return = |
| 242 |
kprobe.function(@arch_syscall_prefix "sys_truncate").return ?, |
| 243 |
kprobe.function(@arch_syscall_prefix "compat_sys_truncate").return ? |
| 244 |
{ |
| 245 |
@_SYSCALL_TRUNCATE_NAME |
| 246 |
@SYSC_RETVALSTR(returnval()) |
| 247 |
} |
| 248 |
|
| 249 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 250 |
probe tp_syscall.truncate.return = __tp_syscall.truncate.return, |
| 251 |
__tp_syscall.truncate64.return |
| 252 |
{ |
| 253 |
__set_syscall_pt_regs($regs) |
| 254 |
@_SYSCALL_TRUNCATE_NAME |
| 255 |
@SYSC_RETVALSTR($ret) |
| 256 |
} |
| 257 |
probe __tp_syscall.truncate.return = kernel.trace("sys_exit") |
| 258 |
{ |
| 259 |
@__syscall_compat_gate(@const("__NR_truncate"), @const("__NR_compat_truncate")) |
| 260 |
} |
| 261 |
probe __tp_syscall.truncate64.return = kernel.trace("sys_exit") |
| 262 |
{ |
| 263 |
@__syscall_gate(@const("__NR_truncate64")) |
| 264 |
} |