| 1 |
# setreuid ___________________________________________________ |
| 2 |
# long sys_setreuid(uid_t ruid, uid_t euid) |
| 3 |
# |
| 4 |
|
| 5 |
@define _SYSCALL_SETREUID_NAME |
| 6 |
%( |
| 7 |
name = "setreuid" |
| 8 |
%) |
| 9 |
|
| 10 |
@define _SYSCALL_SETREUID_ARGSTR |
| 11 |
%( |
| 12 |
argstr = sprintf("%d, %d", ruid, euid) |
| 13 |
%) |
| 14 |
|
| 15 |
@define _SYSCALL_GATE |
| 16 |
%( |
| 17 |
%( arch == "x86_64" %? |
| 18 |
// There are actually 3 x86_64 setreuid syscall numbers (which |
| 19 |
// get mapped to 2 syscall functions: |
| 20 |
// - __NR_setreuid which gets mapped to sys_setreuid() |
| 21 |
// - __NR_ia32_setreuid32 which also gets mapped to |
| 22 |
// sys_setreuid() |
| 23 |
// - __NR_ia32_setreuid which gets mapped to sys_setreuid16() |
| 24 |
// (which is a wrapper around sys_setreuid()) |
| 25 |
// So, we need to avoid sys_setreuid() calls that come from |
| 26 |
// sys_setreuid16(). |
| 27 |
@__syscall_compat_gate(@const("__NR_setreuid"), |
| 28 |
@const("__NR_ia32_setreuid32")) |
| 29 |
%: |
| 30 |
%( arch == "i386" %? |
| 31 |
// On i386, there are 2 setreuid syscall numbers: |
| 32 |
// - __NR_setreuid which gets mapped to sys_setreuid16 |
| 33 |
// - __NR_setreuid32 which gets mapped to sys_setreuid |
| 34 |
// Since this gets called from a probe on sys_setreuid, we'll |
| 35 |
// make sure this is really __NR_setreuid32. |
| 36 |
@__syscall_nr_gate(@const("__NR_setreuid32")) |
| 37 |
%) |
| 38 |
%) |
| 39 |
%) |
| 40 |
|
| 41 |
@define _SYSCALL_SETREUID_REGARGS |
| 42 |
%( |
| 43 |
ruid = __int32(uint_arg(1)) |
| 44 |
euid = __int32(uint_arg(2)) |
| 45 |
%) |
| 46 |
|
| 47 |
@define _SYSCALL_SETREUID_REGARGS_STORE |
| 48 |
%( |
| 49 |
if (@probewrite(ruid)) |
| 50 |
set_uint_arg(1, __int32(ruid)) |
| 51 |
|
| 52 |
if (@probewrite(euid)) |
| 53 |
set_uint_arg(2, __int32(euid)) |
| 54 |
%) |
| 55 |
|
| 56 |
@define _SYSCALL_SETREUID16_REGARGS |
| 57 |
%( |
| 58 |
ruid = __short(uint_arg(1)) |
| 59 |
euid = __short(uint_arg(2)) |
| 60 |
%) |
| 61 |
|
| 62 |
@define _SYSCALL_SETREUID16_REGARGS_STORE |
| 63 |
%( |
| 64 |
if (@probewrite(ruid)) |
| 65 |
set_uint_arg(1, __short(ruid)) |
| 66 |
|
| 67 |
if (@probewrite(euid)) |
| 68 |
set_uint_arg(2, __short(euid)) |
| 69 |
%) |
| 70 |
probe syscall.setreuid = dw_syscall.setreuid !, nd_syscall.setreuid ? {} |
| 71 |
probe syscall.setreuid.return = dw_syscall.setreuid.return !, |
| 72 |
nd_syscall.setreuid.return ? {} |
| 73 |
|
| 74 |
# dw_setreuid _____________________________________________________ |
| 75 |
|
| 76 |
probe dw_syscall.setreuid = kernel.function("sys_setreuid").call |
| 77 |
{ |
| 78 |
@_SYSCALL_GATE |
| 79 |
@_SYSCALL_SETREUID_NAME |
| 80 |
ruid = __int32($ruid) |
| 81 |
euid = __int32($euid) |
| 82 |
@_SYSCALL_SETREUID_ARGSTR |
| 83 |
} |
| 84 |
probe dw_syscall.setreuid.return = kernel.function("sys_setreuid").return |
| 85 |
{ |
| 86 |
@_SYSCALL_GATE |
| 87 |
@_SYSCALL_SETREUID_NAME |
| 88 |
@SYSC_RETVALSTR($return) |
| 89 |
} |
| 90 |
|
| 91 |
# nd_setreuid _____________________________________________________ |
| 92 |
|
| 93 |
probe nd_syscall.setreuid = nd1_syscall.setreuid!, nd2_syscall.setreuid!, tp_syscall.setreuid |
| 94 |
{ } |
| 95 |
|
| 96 |
probe nd1_syscall.setreuid = kprobe.function("sys_setreuid") ? |
| 97 |
{ |
| 98 |
@_SYSCALL_GATE |
| 99 |
@_SYSCALL_SETREUID_NAME |
| 100 |
asmlinkage() |
| 101 |
@_SYSCALL_SETREUID_REGARGS |
| 102 |
@_SYSCALL_SETREUID_ARGSTR |
| 103 |
} |
| 104 |
|
| 105 |
/* kernel 4.17+ */ |
| 106 |
probe nd2_syscall.setreuid = kprobe.function(@arch_syscall_prefix "sys_setreuid") ? |
| 107 |
{ |
| 108 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 109 |
@_SYSCALL_SETREUID_NAME |
| 110 |
@_SYSCALL_SETREUID_REGARGS |
| 111 |
@_SYSCALL_SETREUID_ARGSTR |
| 112 |
}, |
| 113 |
{ |
| 114 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SETREUID_REGARGS_STORE %) |
| 115 |
} |
| 116 |
|
| 117 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 118 |
probe tp_syscall.setreuid = kernel.trace("sys_enter") |
| 119 |
{ |
| 120 |
__set_syscall_pt_regs($regs) |
| 121 |
@__syscall_compat_gate(@const("__NR_setreuid"), @const("__NR_compat_setreuid32")) |
| 122 |
@_SYSCALL_SETREUID_NAME |
| 123 |
@_SYSCALL_SETREUID_REGARGS |
| 124 |
@_SYSCALL_SETREUID_ARGSTR |
| 125 |
}, |
| 126 |
{ |
| 127 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SETREUID_REGARGS_STORE %) |
| 128 |
} |
| 129 |
|
| 130 |
probe nd_syscall.setreuid.return = nd1_syscall.setreuid.return!, nd2_syscall.setreuid.return!, tp_syscall.setreuid.return |
| 131 |
{ } |
| 132 |
|
| 133 |
probe nd1_syscall.setreuid.return = kprobe.function("sys_setreuid").return ? |
| 134 |
{ |
| 135 |
@_SYSCALL_GATE |
| 136 |
@_SYSCALL_SETREUID_NAME |
| 137 |
@SYSC_RETVALSTR(returnval()) |
| 138 |
} |
| 139 |
|
| 140 |
/* kernel 4.17+ */ |
| 141 |
probe nd2_syscall.setreuid.return = kprobe.function(@arch_syscall_prefix "sys_setreuid").return ? |
| 142 |
{ |
| 143 |
@_SYSCALL_SETREUID_NAME |
| 144 |
@SYSC_RETVALSTR(returnval()) |
| 145 |
} |
| 146 |
|
| 147 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 148 |
probe tp_syscall.setreuid.return = kernel.trace("sys_exit") |
| 149 |
{ |
| 150 |
__set_syscall_pt_regs($regs) |
| 151 |
@__syscall_compat_gate(@const("__NR_setreuid"), @const("__NR_compat_setreuid32")) |
| 152 |
@_SYSCALL_SETREUID_NAME |
| 153 |
@SYSC_RETVALSTR($ret) |
| 154 |
} |
| 155 |
|
| 156 |
# setreuid16 _________________________________________________ |
| 157 |
# long sys_setreuid16(old_uid_t ruid, old_uid_t euid) |
| 158 |
# |
| 159 |
|
| 160 |
probe syscall.setreuid16 = dw_syscall.setreuid16 !, nd_syscall.setreuid16 ? {} |
| 161 |
probe syscall.setreuid16.return = dw_syscall.setreuid16.return !, |
| 162 |
nd_syscall.setreuid16.return ? {} |
| 163 |
|
| 164 |
# dw_setreuid16 _____________________________________________________ |
| 165 |
|
| 166 |
probe dw_syscall.setreuid16 = kernel.function("sys_setreuid16").call ? |
| 167 |
{ |
| 168 |
@_SYSCALL_SETREUID_NAME |
| 169 |
ruid = __short($ruid) |
| 170 |
euid = __short($euid) |
| 171 |
@_SYSCALL_SETREUID_ARGSTR |
| 172 |
} |
| 173 |
probe dw_syscall.setreuid16.return = kernel.function("sys_setreuid16").return ? |
| 174 |
{ |
| 175 |
@_SYSCALL_SETREUID_NAME |
| 176 |
@SYSC_RETVALSTR($return) |
| 177 |
} |
| 178 |
|
| 179 |
# nd_setreuid16 _____________________________________________________ |
| 180 |
|
| 181 |
probe nd_syscall.setreuid16 = nd1_syscall.setreuid16!, nd2_syscall.setreuid16!, tp_syscall.setreuid16 |
| 182 |
{ } |
| 183 |
|
| 184 |
probe nd1_syscall.setreuid16 = kprobe.function("sys_setreuid16") ? |
| 185 |
{ |
| 186 |
@_SYSCALL_SETREUID_NAME |
| 187 |
asmlinkage() |
| 188 |
@_SYSCALL_SETREUID16_REGARGS |
| 189 |
@_SYSCALL_SETREUID_ARGSTR |
| 190 |
} |
| 191 |
|
| 192 |
/* kernel 4.17+ */ |
| 193 |
probe nd2_syscall.setreuid16 = kprobe.function(@arch_syscall_prefix "sys_setreuid16") ? |
| 194 |
{ |
| 195 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 196 |
@_SYSCALL_SETREUID_NAME |
| 197 |
@_SYSCALL_SETREUID16_REGARGS |
| 198 |
@_SYSCALL_SETREUID_ARGSTR |
| 199 |
}, |
| 200 |
{ |
| 201 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SETREUID16_REGARGS_STORE %) |
| 202 |
} |
| 203 |
|
| 204 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 205 |
probe tp_syscall.setreuid16 = kernel.trace("sys_enter") |
| 206 |
{ |
| 207 |
__set_syscall_pt_regs($regs) |
| 208 |
@__compat_syscall_gate(@const("__NR_compat_setreuid")) |
| 209 |
@_SYSCALL_SETREUID_NAME |
| 210 |
@_SYSCALL_SETREUID16_REGARGS |
| 211 |
@_SYSCALL_SETREUID_ARGSTR |
| 212 |
}, |
| 213 |
{ |
| 214 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SETREUID16_REGARGS_STORE %) |
| 215 |
} |
| 216 |
|
| 217 |
probe nd_syscall.setreuid16.return = nd1_syscall.setreuid16.return!, nd2_syscall.setreuid16.return!, tp_syscall.setreuid16.return |
| 218 |
{ } |
| 219 |
|
| 220 |
probe nd1_syscall.setreuid16.return = kprobe.function("sys_setreuid16").return ? |
| 221 |
{ |
| 222 |
@_SYSCALL_SETREUID_NAME |
| 223 |
@SYSC_RETVALSTR(returnval()) |
| 224 |
} |
| 225 |
|
| 226 |
/* kernel 4.17+ */ |
| 227 |
probe nd2_syscall.setreuid16.return = kprobe.function(@arch_syscall_prefix "sys_setreuid16").return ? |
| 228 |
{ |
| 229 |
@_SYSCALL_SETREUID_NAME |
| 230 |
@SYSC_RETVALSTR(returnval()) |
| 231 |
} |
| 232 |
|
| 233 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 234 |
probe tp_syscall.setreuid16.return = kernel.trace("sys_exit") |
| 235 |
{ |
| 236 |
__set_syscall_pt_regs($regs) |
| 237 |
@__compat_syscall_gate(@const("__NR_compat_setreuid")) |
| 238 |
@_SYSCALL_SETREUID_NAME |
| 239 |
@SYSC_RETVALSTR($ret) |
| 240 |
} |