Debian Codegraph @

tapset/linux/sysc_sendmsg.stp

raw
1 # sendmsg ____________________________________________________
2 #
3 # long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags)
4 #
5
6 @define _SYSCALL_SENDMSG_NAME
7 %(
8 name = "sendmsg"
9 %)
10
11 @define _SYSCALL_SENDMSG_ARGSTR
12 %(
13 argstr = sprintf("%d, %p, %s", s, msg_uaddr, flags_str)
14 %)
15
16 @define _SYSCALL_SENDMSG_REGARGS
17 %(
18 s = int_arg(1)
19 msg_uaddr = pointer_arg(2)
20 flags = uint_arg(3)
21 %)
22
23 @define _SYSCALL_SENDMSG_REGARGS_STORE
24 %(
25 if (@probewrite(s))
26 set_int_arg(1, s)
27
28 if (@probewrite(msg_uaddr))
29 set_pointer_arg(2, msg_uaddr)
30
31 if (@probewrite(flags))
32 set_uint_arg(3, flags)
33 %)
34
35 @define _SYSCALL_SOCKETCALL_SENDMSG_REGARGS
36 %(
37 __args = &@ulong_cast(pointer_arg(2))
38 s = __int32(user_ulong(&@ulong_cast(__args)[0]))
39 msg_uaddr = user_ulong(&@ulong_cast(__args)[1])
40 flags = __uint32(user_ulong(&@ulong_cast(__args)[2]))
41 %)
42
43 @define _SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
44 %(
45 __args = &@uint_cast(pointer_arg(2))
46 s = user_int(&@uint_cast(__args)[0])
47 msg_uaddr = user_uint32(&@uint_cast(__args)[1])
48 flags = user_uint32(&@uint_cast(__args)[2])
49 flags_str = _msg_flags_str(flags)
50 %)
51
52 probe syscall.sendmsg = dw_syscall.sendmsg !, nd_syscall.sendmsg ? {}
53 probe syscall.sendmsg.return = dw_syscall.sendmsg.return !,
54 nd_syscall.sendmsg.return ? {}
55
56 # dw_sendmsg _____________________________________________________
57
58 probe dw_syscall.sendmsg = __syscall.sendmsg ?, __syscall.socketcall.sendmsg ?
59 {
60 # Avoid probe hits from compat_sys_socketcall() calling
61 # compat_sys_sendmsg(), which sometimes calls
62 # sys_sendmsg(). We could call __syscall_gate2() here with
63 # NR_sendmsg and NR_socketcall, but all we really need to
64 # check is that we're not in a compat task.
65 @__syscall_gate_compat_simple
66 @_SYSCALL_SENDMSG_NAME
67 flags_str = _msg_flags_str(flags)
68 @_SYSCALL_SENDMSG_ARGSTR
69 }
70 probe __syscall.sendmsg = kernel.function("sys_sendmsg").call ?
71 {
72 @__syscall_gate(@const("__NR_sendmsg"))
73 s = __int32($fd)
74 msg_uaddr = $msg
75 flags = __uint32($flags)
76 }
77 probe __syscall.socketcall.sendmsg = kernel.function("sys_socketcall").call ?
78 {
79 if (__int32($call) != @const("SYS_SENDMSG")) next;
80 s = __int32(user_ulong(&@ulong_cast($args)[0]))
81 msg_uaddr = user_ulong(&@ulong_cast($args)[1])
82 flags = __uint32(user_ulong(&@ulong_cast($args)[2]))
83 }
84 probe dw_syscall.sendmsg.return = __syscall.sendmsg.return ?,
85 __syscall.socketcall.sendmsg.return ?
86 {
87 # Avoid probe hits from compat_sys_socketcall() calling
88 # compat_sys_sendmsg(), which sometimes calls
89 # sys_sendmsg(). We could call __syscall_gate2() here with
90 # NR_sendmsg and NR_socketcall, but all we really need to
91 # check is that we're not in a compat task.
92 @__syscall_gate_compat_simple
93 @_SYSCALL_SENDMSG_NAME
94 @SYSC_RETVALSTR($return)
95 }
96 probe __syscall.sendmsg.return = kernel.function("sys_sendmsg").return ?
97 {
98 @__syscall_gate(@const("__NR_sendmsg"))
99 }
100 probe __syscall.socketcall.sendmsg.return =
101 kernel.function("sys_socketcall").return ?
102 {
103 if (__int32(@entry($call)) != @const("SYS_SENDMSG")) next;
104 }
105
106 # nd_sendmsg _____________________________________________________
107
108 probe nd_syscall.sendmsg = nd1_syscall.sendmsg!, nd2_syscall.sendmsg!, tp_syscall.sendmsg
109 { }
110
111 probe nd1_syscall.sendmsg = __nd1_syscall.sendmsg ?,
112 __nd1_syscall.socketcall.sendmsg ?
113 {
114 # Avoid probe hits from compat_sys_socketcall() calling
115 # compat_sys_sendmsg(), which sometimes calls
116 # sys_sendmsg(). We could call __syscall_gate2() here with
117 # NR_sendmsg and NR_socketcall, but all we really need to
118 # check is that we're not in a compat task.
119 @__syscall_gate_compat_simple
120
121 @_SYSCALL_SENDMSG_NAME
122 flags_str = _msg_flags_str(flags)
123 @_SYSCALL_SENDMSG_ARGSTR
124 }
125 probe __nd1_syscall.sendmsg = kprobe.function("sys_sendmsg") ?
126 {
127 @__syscall_gate(@const("__NR_sendmsg"))
128 asmlinkage()
129 @_SYSCALL_SENDMSG_REGARGS
130 }
131 probe __nd1_syscall.socketcall.sendmsg = kprobe.function("sys_socketcall").call ?
132 {
133 asmlinkage()
134 if (int_arg(1) != @const("SYS_SENDMSG")) next;
135 @_SYSCALL_SOCKETCALL_SENDMSG_REGARGS
136 }
137
138 /* kernel 4.17+ */
139 probe nd2_syscall.sendmsg = __nd2_syscall.sendmsg ?,
140 __nd2_syscall.socketcall.sendmsg ?
141 {
142 # Avoid probe hits from compat_sys_socketcall() calling
143 # compat_sys_sendmsg(), which sometimes calls
144 # sys_sendmsg(). We could call __syscall_gate2() here with
145 # NR_sendmsg and NR_socketcall, but all we really need to
146 # check is that we're not in a compat task.
147 @__syscall_gate_compat_simple
148
149 @_SYSCALL_SENDMSG_NAME
150 flags_str = _msg_flags_str(flags)
151 @_SYSCALL_SENDMSG_ARGSTR
152 }
153 probe __nd2_syscall.sendmsg = kprobe.function(@arch_syscall_prefix "sys_sendmsg") ?
154 {
155 __set_syscall_pt_regs(pointer_arg(1))
156 @_SYSCALL_SENDMSG_REGARGS
157 },
158 {
159 %( @_IS_SREG_KERNEL %? @_SYSCALL_SENDMSG_REGARGS_STORE %)
160 }
161 probe __nd2_syscall.socketcall.sendmsg = kprobe.function(@arch_syscall_prefix "sys_socketcall").call ?
162 {
163 __set_syscall_pt_regs(pointer_arg(1))
164 if (int_arg(1) != @const("SYS_SENDMSG")) next;
165 @_SYSCALL_SOCKETCALL_SENDMSG_REGARGS
166 }
167
168 /* kernel 3.5+, but undesirable because it affects all syscalls */
169 probe tp_syscall.sendmsg = __tp_syscall.sendmsg ?,
170 __tp_syscall.socketcall.sendmsg ?
171 {
172 # Avoid probe hits from compat_sys_socketcall() calling
173 # compat_sys_sendmsg(), which sometimes calls
174 # sys_sendmsg(). We could call __syscall_gate2() here with
175 # NR_sendmsg and NR_socketcall, but all we really need to
176 # check is that we're not in a compat task.
177 @__syscall_gate_compat_simple
178
179 @_SYSCALL_SENDMSG_NAME
180 flags_str = _msg_flags_str(flags)
181 @_SYSCALL_SENDMSG_ARGSTR
182 }
183 probe __tp_syscall.sendmsg = kernel.trace("sys_enter")
184 {
185 __set_syscall_pt_regs($regs)
186 @__syscall_gate(@const("__NR_sendmsg"))
187 @_SYSCALL_SENDMSG_REGARGS
188 },
189 {
190 %( @_IS_SREG_KERNEL %? @_SYSCALL_SENDMSG_REGARGS_STORE %)
191 }
192 probe __tp_syscall.socketcall.sendmsg = kernel.trace("sys_enter")
193 {
194 __set_syscall_pt_regs($regs)
195 @__syscall_gate(@const("__NR_socketcall"))
196 if (int_arg(1) != @const("SYS_SENDMSG")) next;
197 @_SYSCALL_SOCKETCALL_SENDMSG_REGARGS
198 }
199
200 probe nd_syscall.sendmsg.return = nd1_syscall.sendmsg.return!, nd2_syscall.sendmsg.return!, tp_syscall.sendmsg.return
201 { }
202
203 probe nd1_syscall.sendmsg.return = __nd1_syscall.sendmsg.return ?,
204 __nd1_syscall.socketcall.sendmsg.return ?
205 {
206 # Avoid probe hits from compat_sys_socketcall() calling
207 # compat_sys_sendmsg(), which sometimes calls
208 # sys_sendmsg(). We could call __syscall_gate2() here with
209 # NR_sendmsg and NR_socketcall, but all we really need to
210 # check is that we're not in a compat task.
211 @__syscall_gate_compat_simple
212
213 @_SYSCALL_SENDMSG_NAME
214 @SYSC_RETVALSTR(returnval())
215 }
216 probe __nd1_syscall.sendmsg.return = kprobe.function("sys_sendmsg").return ?
217 {
218 @__syscall_gate(@const("__NR_sendmsg"))
219 }
220 probe __nd1_syscall.socketcall.sendmsg.return =
221 kprobe.function("sys_socketcall").return ?
222 {
223 if (@entry(__asmlinkage_int_arg(1)) != @const("SYS_SENDMSG")) next;
224 }
225
226 /* kernel 4.17+ */
227 probe nd2_syscall.sendmsg.return =
228 kprobe.function(@arch_syscall_prefix "sys_sendmsg").return ?,
229 __nd2_syscall.socketcall.sendmsg.return ?
230 {
231 # Avoid probe hits from compat_sys_socketcall() calling
232 # compat_sys_sendmsg(), which sometimes calls
233 # sys_sendmsg(). We could call __syscall_gate2() here with
234 # NR_sendmsg and NR_socketcall, but all we really need to
235 # check is that we're not in a compat task.
236 @__syscall_gate_compat_simple
237
238 @_SYSCALL_SENDMSG_NAME
239 @SYSC_RETVALSTR(returnval())
240 }
241 probe __nd2_syscall.socketcall.sendmsg.return =
242 kprobe.function(@arch_syscall_prefix "sys_socketcall").return ?
243 {
244 __set_syscall_pt_regs(@entry(pointer_arg(1)))
245 if (int_arg(1) != @const("SYS_SENDMSG")) next;
246 }
247
248 /* kernel 3.5+, but undesirable because it affects all syscalls */
249 probe tp_syscall.sendmsg.return = __tp_syscall.sendmsg.return ?,
250 __tp_syscall.socketcall.sendmsg.return ?
251 {
252 # Avoid probe hits from compat_sys_socketcall() calling
253 # compat_sys_sendmsg(), which sometimes calls
254 # sys_sendmsg(). We could call __syscall_gate2() here with
255 # NR_sendmsg and NR_socketcall, but all we really need to
256 # check is that we're not in a compat task.
257 @__syscall_gate_compat_simple
258
259 @_SYSCALL_SENDMSG_NAME
260 @SYSC_RETVALSTR($ret)
261 }
262 probe __tp_syscall.sendmsg.return = kernel.trace("sys_exit")
263 {
264 @__syscall_gate(@const("__NR_sendmsg"))
265 }
266 probe __tp_syscall.socketcall.sendmsg.return = kernel.trace("sys_exit")
267 {
268 __set_syscall_pt_regs($regs)
269 @__syscall_gate(@const("__NR_socketcall"))
270 if (int_arg(1) != @const("SYS_SENDMSG")) next;
271 }
272
273 # compat_sys_sendmsg ________________________________________
274 #
275 # long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags)
276 #
277 # On all tested kernels/architectures, the compat sendmsg() syscall
278 # goes through compat_sys_socketcall(). compat_sys_socketcall() then
279 # calls an inlined version of compat_sys_sendmsg() on some
280 # architectures (like x86_64 and ppc64). So, the only reliable thing
281 # to do here is just probe compat_sys_socketcall().
282 #
283 # Note that this probe should have been either called
284 # 'syscall.compat_sendmsg' or just merged with 'syscall.sendmsg'.
285 #
286
287 probe syscall.compat_sys_sendmsg = dw_syscall.compat_sys_sendmsg !,
288 nd_syscall.compat_sys_sendmsg ? {}
289 probe syscall.compat_sys_sendmsg.return = dw_syscall.compat_sys_sendmsg.return !,
290 nd_syscall.compat_sys_sendmsg.return ? {}
291
292 # dw_compat_sys_sendmsg _____________________________________________________
293
294 probe dw_syscall.compat_sys_sendmsg =
295 kernel.function("compat_sys_socketcall").call ?
296 {
297 if (__int32($call) != @const("SYS_SENDMSG")) next;
298 @_SYSCALL_SENDMSG_NAME
299 s = user_int(&@uint_cast($args)[0])
300 msg_uaddr = user_uint32(&@uint_cast($args)[1])
301 flags = user_uint32(&@uint_cast($args)[2])
302 flags_str = _msg_flags_str(flags)
303 @_SYSCALL_SENDMSG_ARGSTR
304 }
305 probe dw_syscall.compat_sys_sendmsg.return =
306 kernel.function("compat_sys_socketcall").return ?
307 {
308 if (__int32(@entry($call)) != @const("SYS_SENDMSG")) next;
309 @_SYSCALL_SENDMSG_NAME
310 @SYSC_RETVALSTR($return)
311 }
312
313 # nd_compat_sys_sendmsg _____________________________________________________
314
315 probe nd_syscall.compat_sys_sendmsg = nd1_syscall.compat_sys_sendmsg!, nd2_syscall.compat_sys_sendmsg!, tp_syscall.compat_sys_sendmsg
316 { }
317
318 probe nd1_syscall.compat_sys_sendmsg =
319 kprobe.function("compat_sys_socketcall").call ?
320 {
321 asmlinkage()
322 if (int_arg(1) != @const("SYS_SENDMSG")) next;
323 @_SYSCALL_SENDMSG_NAME
324 @_SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
325 @_SYSCALL_SENDMSG_ARGSTR
326 }
327
328 /* kernel 4.17+ */
329 probe nd2_syscall.compat_sys_sendmsg =
330 kprobe.function(@arch_syscall_prefix "compat_sys_socketcall").call ?
331 {
332 __set_syscall_pt_regs(pointer_arg(1))
333 if (int_arg(1) != @const("SYS_SENDMSG")) next;
334 @_SYSCALL_SENDMSG_NAME
335 @_SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
336 @_SYSCALL_SENDMSG_ARGSTR
337 }
338
339 /* kernel 3.5+, but undesirable because it affects all syscalls */
340 probe tp_syscall.compat_sys_sendmsg = kernel.trace("sys_enter")
341 {
342 __set_syscall_pt_regs($regs)
343 @__compat_syscall_gate(@const("__NR_compat_socketcall"))
344 if (int_arg(1) != @const("SYS_SENDMSG")) next;
345 @_SYSCALL_SENDMSG_NAME
346 @_SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
347 @_SYSCALL_SENDMSG_ARGSTR
348 }
349
350 probe nd_syscall.compat_sys_sendmsg.return = nd1_syscall.compat_sys_sendmsg.return!, nd2_syscall.compat_sys_sendmsg.return!, tp_syscall.compat_sys_sendmsg.return
351 { }
352
353 probe nd1_syscall.compat_sys_sendmsg.return =
354 kprobe.function("compat_sys_socketcall").return ?
355 {
356 if (@entry(__asmlinkage_int_arg(1)) != @const("SYS_SENDMSG")) next;
357 @_SYSCALL_SENDMSG_NAME
358 @SYSC_RETVALSTR(returnval())
359 }
360
361 /* kernel 4.17+ */
362 probe nd2_syscall.compat_sys_sendmsg.return =
363 kprobe.function(@arch_syscall_prefix "compat_sys_socketcall").return ?
364 {
365 __set_syscall_pt_regs(@entry(pointer_arg(1)))
366 if (int_arg(1) != @const("SYS_SENDMSG")) next;
367 @_SYSCALL_SENDMSG_NAME
368 @SYSC_RETVALSTR(returnval())
369 }
370
371 /* kernel 3.5+, but undesirable because it affects all syscalls */
372 probe tp_syscall.compat_sys_sendmsg.return = kernel.trace("sys_exit")
373 {
374 __set_syscall_pt_regs($regs)
375 @__compat_syscall_gate(@const("__NR_compat_socketcall"))
376 if (int_arg(1) != @const("SYS_SENDMSG")) next;
377 @_SYSCALL_SENDMSG_NAME
378 @SYSC_RETVALSTR($ret)
379 }