| 1 |
# setgid _____________________________________________________ |
| 2 |
# |
| 3 |
# long sys_setgid(gid_t gid) |
| 4 |
# long sys_setgid16(old_gid_t gid) |
| 5 |
# |
| 6 |
|
| 7 |
@define _SYSCALL_SETGID_NAME |
| 8 |
%( |
| 9 |
name = "setgid" |
| 10 |
%) |
| 11 |
|
| 12 |
@define _SYSCALL_SETGID_ARGSTR |
| 13 |
%( |
| 14 |
argstr = sprint(gid) |
| 15 |
%) |
| 16 |
|
| 17 |
@define _SYSCALL_GATE |
| 18 |
%( |
| 19 |
%( arch == "x86_64" %? |
| 20 |
// There are actually 3 x86_64 setgid syscalls numbers (which |
| 21 |
// get mapped to 2 syscall functions: |
| 22 |
// - __NR_setgid which gets mapped to sys_setgid() |
| 23 |
// - __NR_ia32_setgid32 which also gets mapped to |
| 24 |
// sys_setgid() |
| 25 |
// - __NR_ia32_setgid which gets mapped to sys_setgid16() |
| 26 |
// (which is a wrapper around sys_setgid()) |
| 27 |
// So, we need to avoid sys_setgid() calls that come from |
| 28 |
// sys_setgid16(). |
| 29 |
@__syscall_compat_gate(@const("__NR_setgid"), |
| 30 |
@const("__NR_ia32_setgid32")) |
| 31 |
%: |
| 32 |
%( arch == "i386" %? |
| 33 |
// On i386, there are 2 setgid syscall numbers: |
| 34 |
// - __NR_setgid which gets mapped to sys_setgid16 |
| 35 |
// - __NR_setgid32 which gets mapped to sys_setgid |
| 36 |
// Since this gets called from a probe on sys_setgid, we'll |
| 37 |
// make sure this is really __NR_setgid32. |
| 38 |
@__syscall_nr_gate(@const("__NR_setgid32")) |
| 39 |
%) |
| 40 |
%) |
| 41 |
%) |
| 42 |
|
| 43 |
@define _SYSCALL_SETGID_REGARGS |
| 44 |
%( |
| 45 |
gid = int_arg(1) |
| 46 |
%) |
| 47 |
|
| 48 |
@define _SYSCALL_SETGID_REGARGS_STORE |
| 49 |
%( |
| 50 |
if (@probewrite(gid)) |
| 51 |
set_int_arg(1, gid) |
| 52 |
%) |
| 53 |
|
| 54 |
probe syscall.setgid = dw_syscall.setgid !, nd_syscall.setgid ? {} |
| 55 |
probe syscall.setgid.return = dw_syscall.setgid.return !, |
| 56 |
nd_syscall.setgid.return ? {} |
| 57 |
|
| 58 |
# dw_setgid _____________________________________________________ |
| 59 |
|
| 60 |
probe dw_syscall.setgid = kernel.function("sys_setgid16").call ?, |
| 61 |
__syscall.setgid ? |
| 62 |
{ |
| 63 |
@_SYSCALL_SETGID_NAME |
| 64 |
gid = __int32($gid) |
| 65 |
@_SYSCALL_SETGID_ARGSTR |
| 66 |
} |
| 67 |
probe __syscall.setgid = kernel.function("sys_setgid").call ? |
| 68 |
{ |
| 69 |
@_SYSCALL_GATE |
| 70 |
} |
| 71 |
probe dw_syscall.setgid.return = kernel.function("sys_setgid16").return ?, |
| 72 |
__syscall.setgid.return ? |
| 73 |
{ |
| 74 |
@_SYSCALL_SETGID_NAME |
| 75 |
@SYSC_RETVALSTR($return) |
| 76 |
} |
| 77 |
probe __syscall.setgid.return = kernel.function("sys_setgid").return ? |
| 78 |
{ |
| 79 |
@_SYSCALL_GATE |
| 80 |
} |
| 81 |
|
| 82 |
# nd_setgid _____________________________________________________ |
| 83 |
|
| 84 |
probe nd_syscall.setgid = nd1_syscall.setgid!, nd2_syscall.setgid!, tp_syscall.setgid |
| 85 |
{ } |
| 86 |
|
| 87 |
probe nd1_syscall.setgid = kprobe.function("sys_setgid16") ?, |
| 88 |
__nd1_syscall.setgid ? |
| 89 |
{ |
| 90 |
@_SYSCALL_SETGID_NAME |
| 91 |
asmlinkage() |
| 92 |
@_SYSCALL_SETGID_REGARGS |
| 93 |
@_SYSCALL_SETGID_ARGSTR |
| 94 |
} |
| 95 |
probe __nd1_syscall.setgid = kprobe.function("sys_setgid") ? |
| 96 |
{ |
| 97 |
@_SYSCALL_GATE |
| 98 |
} |
| 99 |
|
| 100 |
/* kernel 4.17+ */ |
| 101 |
probe nd2_syscall.setgid = kprobe.function(@arch_syscall_prefix "sys_setgid") ?, |
| 102 |
kprobe.function(@arch_syscall_prefix "sys_setgid16") ? |
| 103 |
{ |
| 104 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 105 |
@_SYSCALL_SETGID_NAME |
| 106 |
@_SYSCALL_SETGID_REGARGS |
| 107 |
@_SYSCALL_SETGID_ARGSTR |
| 108 |
}, |
| 109 |
{ |
| 110 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SETGID_REGARGS_STORE %) |
| 111 |
} |
| 112 |
|
| 113 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 114 |
probe tp_syscall.setgid = __tp_syscall.setgid, __tp_syscall.setgid16 |
| 115 |
{ |
| 116 |
__set_syscall_pt_regs($regs) |
| 117 |
@_SYSCALL_SETGID_NAME |
| 118 |
@_SYSCALL_SETGID_REGARGS |
| 119 |
@_SYSCALL_SETGID_ARGSTR |
| 120 |
}, |
| 121 |
{ |
| 122 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SETGID_REGARGS_STORE %) |
| 123 |
} |
| 124 |
probe __tp_syscall.setgid = kernel.trace("sys_enter") |
| 125 |
{ |
| 126 |
@__syscall_compat_gate(@const("__NR_setgid"), @const("__NR_compat_setgid32")) |
| 127 |
} |
| 128 |
probe __tp_syscall.setgid16 = kernel.trace("sys_enter") |
| 129 |
{ |
| 130 |
@__compat_syscall_gate(@const("__NR_compat_setgid")) |
| 131 |
} |
| 132 |
|
| 133 |
probe nd_syscall.setgid.return = nd1_syscall.setgid.return!, nd2_syscall.setgid.return!, tp_syscall.setgid.return |
| 134 |
{ } |
| 135 |
|
| 136 |
probe nd1_syscall.setgid.return = kprobe.function("sys_setgid16").return ?, |
| 137 |
__nd1_syscall.setgid.return ? |
| 138 |
{ |
| 139 |
@_SYSCALL_SETGID_NAME |
| 140 |
@SYSC_RETVALSTR(returnval()) |
| 141 |
} |
| 142 |
probe __nd1_syscall.setgid.return = kprobe.function("sys_setgid").return ? |
| 143 |
{ |
| 144 |
@_SYSCALL_GATE |
| 145 |
} |
| 146 |
|
| 147 |
/* kernel 4.17+ */ |
| 148 |
probe nd2_syscall.setgid.return = |
| 149 |
kprobe.function(@arch_syscall_prefix "sys_setgid").return ?, |
| 150 |
kprobe.function(@arch_syscall_prefix "sys_setgid16").return ? |
| 151 |
{ |
| 152 |
@_SYSCALL_SETGID_NAME |
| 153 |
@SYSC_RETVALSTR(returnval()) |
| 154 |
} |
| 155 |
|
| 156 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 157 |
probe tp_syscall.setgid.return = __tp_syscall.setgid.return, __tp_syscall.setgid16.return |
| 158 |
{ |
| 159 |
__set_syscall_pt_regs($regs) |
| 160 |
@_SYSCALL_SETGID_NAME |
| 161 |
@SYSC_RETVALSTR($ret) |
| 162 |
} |
| 163 |
probe __tp_syscall.setgid.return = kernel.trace("sys_exit") |
| 164 |
{ |
| 165 |
@__syscall_compat_gate(@const("__NR_setgid"), @const("__NR_compat_setgid32")) |
| 166 |
} |
| 167 |
probe __tp_syscall.setgid16.return = kernel.trace("sys_exit") |
| 168 |
{ |
| 169 |
@__compat_syscall_gate(@const("__NR_compat_setgid")) |
| 170 |
} |