| 1 |
%( kernel_v >= "2.6.33" %? |
| 2 |
# In newer kernels (2.6.33+), all the sys_mmap() variants are just |
| 3 |
# wrappers around sys_mmap_pgoff(), which is in arch-generic code. |
| 4 |
# |
| 5 |
# long sys_mmap_pgoff(unsigned long addr, unsigned long len, |
| 6 |
# unsigned long prot, unsigned long flags, |
| 7 |
# unsigned long fd, unsigned long pgoff) |
| 8 |
|
| 9 |
@define _SYSCALL_MMAP2_NAME |
| 10 |
%( |
| 11 |
name = "mmap2" |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_MMAP2_ARGSTR |
| 15 |
%( |
| 16 |
argstr = sprintf("%p, %u, %s, %s, %d, %d", start, length, |
| 17 |
prot_str, flags_str, fd, pgoffset) |
| 18 |
%) |
| 19 |
|
| 20 |
@define _SYSCALL_MMAP2_REGARGS_STORE |
| 21 |
%( |
| 22 |
if (@probewrite(start)) |
| 23 |
set_ulong_arg(1, start) |
| 24 |
|
| 25 |
if (@probewrite(length)) |
| 26 |
set_ulong_arg(2, length) |
| 27 |
|
| 28 |
if (@probewrite(prot)) |
| 29 |
set_ulong_arg(3, prot) |
| 30 |
|
| 31 |
if (@probewrite(flags)) |
| 32 |
set_ulong_arg(4, flags) |
| 33 |
|
| 34 |
if (@probewrite(fd)) |
| 35 |
set_int_arg(5, fd) |
| 36 |
|
| 37 |
if (@probewrite(pgoffset)) |
| 38 |
set_ulong_arg(6, pgoffset) |
| 39 |
%) |
| 40 |
|
| 41 |
probe syscall.mmap2 = dw_syscall.mmap2 !, nd_syscall.mmap2 ? {} |
| 42 |
probe syscall.mmap2.return = dw_syscall.mmap2.return !, nd_syscall.mmap2.return ? {} |
| 43 |
|
| 44 |
# dw_mmap2 _____________________________________________________ |
| 45 |
|
| 46 |
probe dw_syscall.mmap2 = kernel.function("sys_mmap_pgoff") ? |
| 47 |
{ |
| 48 |
@_SYSCALL_MMAP2_NAME |
| 49 |
start = $addr |
| 50 |
length = __ulong($len) |
| 51 |
prot = $prot |
| 52 |
prot_str = _mprotect_prot_str(prot) |
| 53 |
flags = $flags |
| 54 |
flags_str = _mmap_flags(flags) |
| 55 |
# Although the kernel gets an unsigned long fd, on the |
| 56 |
# user-side it is a signed int. Fix this. |
| 57 |
fd = __int32($fd) |
| 58 |
# $pgoff is the number of pages. Convert this back into a |
| 59 |
# number of bytes. |
| 60 |
pgoffset = $pgoff * @const("PAGE_SIZE") |
| 61 |
@_SYSCALL_MMAP2_ARGSTR |
| 62 |
} |
| 63 |
probe dw_syscall.mmap2.return = kernel.function("sys_mmap_pgoff").return ? |
| 64 |
{ |
| 65 |
@_SYSCALL_MMAP2_NAME |
| 66 |
@SYSC_RETVALSTR2($return) |
| 67 |
} |
| 68 |
|
| 69 |
# nd_mmap2 _____________________________________________________ |
| 70 |
|
| 71 |
probe nd_syscall.mmap2 = nd1_syscall.mmap2!, nd2_syscall.mmap2!, tp_syscall.mmap2 |
| 72 |
{ } |
| 73 |
|
| 74 |
probe nd1_syscall.mmap2 = kprobe.function("sys_mmap_pgoff") ? |
| 75 |
{ |
| 76 |
@_SYSCALL_MMAP2_NAME |
| 77 |
asmlinkage() |
| 78 |
start = ulong_arg(1) |
| 79 |
length = ulong_arg(2) |
| 80 |
prot = ulong_arg(3) |
| 81 |
prot_str = _mprotect_prot_str(prot) |
| 82 |
flags = ulong_arg(4) |
| 83 |
flags_str = _mmap_flags(flags) |
| 84 |
# Although the kernel gets an unsigned long fd, on the |
| 85 |
# user-side it is a signed int. Fix this. |
| 86 |
fd = int_arg(5) |
| 87 |
# $pgoff is the number of pages. Convert this back into a |
| 88 |
# number of bytes. |
| 89 |
pgoffset = ulong_arg(6) * @const("PAGE_SIZE") |
| 90 |
@_SYSCALL_MMAP2_ARGSTR |
| 91 |
} |
| 92 |
|
| 93 |
/* kernel 4.17+ */ |
| 94 |
probe nd2_syscall.mmap2 = __nd2_syscall.mmap, __nd2_syscall.mmap_pgoff |
| 95 |
{ |
| 96 |
} |
| 97 |
probe __nd2_syscall.mmap = kprobe.function(@arch_syscall_prefix "sys_mmap") ? |
| 98 |
{ |
| 99 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 100 |
@_SYSCALL_MMAP2_NAME |
| 101 |
start = ulong_arg(1) |
| 102 |
length = ulong_arg(2) |
| 103 |
prot = ulong_arg(3) |
| 104 |
prot_str = _mprotect_prot_str(prot) |
| 105 |
flags = ulong_arg(4) |
| 106 |
flags_str = _mmap_flags(flags) |
| 107 |
# Although the kernel gets an unsigned long fd, on the |
| 108 |
# user-side it is a signed int. Fix this. |
| 109 |
fd = int_arg(5) |
| 110 |
# Here $pgoff is the number of bytes, no conversion needed |
| 111 |
pgoffset = ulong_arg(6) |
| 112 |
@_SYSCALL_MMAP2_ARGSTR |
| 113 |
}, |
| 114 |
{ |
| 115 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %) |
| 116 |
} |
| 117 |
probe __nd2_syscall.mmap_pgoff = kprobe.function(@arch_syscall_prefix "sys_mmap_pgoff") ? |
| 118 |
{ |
| 119 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 120 |
@_SYSCALL_MMAP2_NAME |
| 121 |
start = ulong_arg(1) |
| 122 |
length = ulong_arg(2) |
| 123 |
prot = ulong_arg(3) |
| 124 |
prot_str = _mprotect_prot_str(prot) |
| 125 |
flags = ulong_arg(4) |
| 126 |
flags_str = _mmap_flags(flags) |
| 127 |
# Although the kernel gets an unsigned long fd, on the |
| 128 |
# user-side it is a signed int. Fix this. |
| 129 |
fd = int_arg(5) |
| 130 |
# $pgoff is the number of pages. Convert this back into a |
| 131 |
# number of bytes. |
| 132 |
pgoffset = ulong_arg(6) * @const("PAGE_SIZE") |
| 133 |
@_SYSCALL_MMAP2_ARGSTR |
| 134 |
}, |
| 135 |
{ |
| 136 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %) |
| 137 |
} |
| 138 |
|
| 139 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 140 |
probe tp_syscall.mmap2 = __tp_syscall.mmap, __tp_syscall.mmap_pgoff |
| 141 |
{ |
| 142 |
} |
| 143 |
probe __tp_syscall.mmap = kernel.trace("sys_enter") |
| 144 |
{ |
| 145 |
__set_syscall_pt_regs($regs) |
| 146 |
@__syscall_gate(@const("__NR_mmap")) |
| 147 |
@_SYSCALL_MMAP2_NAME |
| 148 |
start = ulong_arg(1) |
| 149 |
length = ulong_arg(2) |
| 150 |
prot = ulong_arg(3) |
| 151 |
prot_str = _mprotect_prot_str(prot) |
| 152 |
flags = ulong_arg(4) |
| 153 |
flags_str = _mmap_flags(flags) |
| 154 |
# Although the kernel gets an unsigned long fd, on the |
| 155 |
# user-side it is a signed int. Fix this. |
| 156 |
fd = int_arg(5) |
| 157 |
# Here $pgoff is the number of bytes, no conversion needed |
| 158 |
pgoffset = ulong_arg(6) |
| 159 |
@_SYSCALL_MMAP2_ARGSTR |
| 160 |
}, |
| 161 |
{ |
| 162 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %) |
| 163 |
} |
| 164 |
probe __tp_syscall.mmap_pgoff = kernel.trace("sys_enter") |
| 165 |
{ |
| 166 |
__set_syscall_pt_regs($regs) |
| 167 |
@__syscall_compat_gate(@const("__NR_mmap2"), @const("__NR_compat_mmap2")) |
| 168 |
@_SYSCALL_MMAP2_NAME |
| 169 |
start = ulong_arg(1) |
| 170 |
length = ulong_arg(2) |
| 171 |
prot = ulong_arg(3) |
| 172 |
prot_str = _mprotect_prot_str(prot) |
| 173 |
flags = ulong_arg(4) |
| 174 |
flags_str = _mmap_flags(flags) |
| 175 |
# Although the kernel gets an unsigned long fd, on the |
| 176 |
# user-side it is a signed int. Fix this. |
| 177 |
fd = int_arg(5) |
| 178 |
# $pgoff is the number of pages. Convert this back into a |
| 179 |
# number of bytes. |
| 180 |
pgoffset = ulong_arg(6) * @const("PAGE_SIZE") |
| 181 |
@_SYSCALL_MMAP2_ARGSTR |
| 182 |
}, |
| 183 |
{ |
| 184 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %) |
| 185 |
} |
| 186 |
|
| 187 |
probe nd_syscall.mmap2.return = nd1_syscall.mmap2.return!, nd2_syscall.mmap2.return!, tp_syscall.mmap2.return |
| 188 |
{ } |
| 189 |
|
| 190 |
probe nd1_syscall.mmap2.return = kprobe.function("sys_mmap_pgoff").return ? |
| 191 |
{ |
| 192 |
@_SYSCALL_MMAP2_NAME |
| 193 |
@SYSC_RETVALSTR2(returnval()) |
| 194 |
} |
| 195 |
|
| 196 |
/* kernel 4.17+ */ |
| 197 |
probe nd2_syscall.mmap2.return = kprobe.function(@arch_syscall_prefix "sys_mmap").return ?, |
| 198 |
kprobe.function(@arch_syscall_prefix "sys_mmap_pgoff").return ? |
| 199 |
{ |
| 200 |
@_SYSCALL_MMAP2_NAME |
| 201 |
@SYSC_RETVALSTR2(returnval()) |
| 202 |
} |
| 203 |
|
| 204 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 205 |
probe tp_syscall.mmap2.return = __tp_syscall.mmap.return, __tp_syscall.mmap_pgoff.return |
| 206 |
{ |
| 207 |
} |
| 208 |
probe __tp_syscall.mmap.return = kernel.trace("sys_exit") |
| 209 |
{ |
| 210 |
__set_syscall_pt_regs($regs) |
| 211 |
@__syscall_gate(@const("__NR_mmap")) |
| 212 |
@_SYSCALL_MMAP2_NAME |
| 213 |
@SYSC_RETVALSTR2($ret) |
| 214 |
} |
| 215 |
probe __tp_syscall.mmap_pgoff.return = kernel.trace("sys_exit") |
| 216 |
{ |
| 217 |
__set_syscall_pt_regs($regs) |
| 218 |
@__syscall_compat_gate(@const("__NR_mmap2"), @const("__NR_compat_mmap2")) |
| 219 |
@_SYSCALL_MMAP2_NAME |
| 220 |
@SYSC_RETVALSTR2($ret) |
| 221 |
} |
| 222 |
%) |