Debian Codegraph @

tapset/linux/sysc_setresgid.stp

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