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