File: sysc_sendmsg.stp

package info (click to toggle)
systemtap 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,436 kB
  • sloc: cpp: 72,388; ansic: 58,430; xml: 47,797; exp: 40,417; sh: 10,793; python: 2,759; perl: 2,252; tcl: 1,305; makefile: 1,119; lisp: 105; java: 102; awk: 101; asm: 91; sed: 16
file content (361 lines) | stat: -rw-r--r-- 11,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# sendmsg ____________________________________________________
#
# long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags)
#

@define _SYSCALL_SENDMSG_NAME
%(
	name = "sendmsg"
%)

@define _SYSCALL_SENDMSG_ARGSTR
%(
	argstr = sprintf("%d, %p, %s", s, msg_uaddr, flags_str)
%)

@define _SYSCALL_SENDMSG_REGARGS
%(
	s = int_arg(1)
	msg_uaddr = pointer_arg(2)
	flags = uint_arg(3)
%)

@define _SYSCALL_SOCKETCALL_SENDMSG_REGARGS
%(
	__args = &@ulong_cast(pointer_arg(2))
	s = __int32(user_ulong(&@ulong_cast(__args)[0]))
	msg_uaddr = user_ulong(&@ulong_cast(__args)[1])
	flags = __uint32(user_ulong(&@ulong_cast(__args)[2]))
%)

@define _SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
%(
	__args = &@uint_cast(pointer_arg(2))
	s = user_int(&@uint_cast(__args)[0])
	msg_uaddr = user_uint32(&@uint_cast(__args)[1])
	flags = user_uint32(&@uint_cast(__args)[2])
	flags_str = _msg_flags_str(flags)
%)

probe syscall.sendmsg = dw_syscall.sendmsg !, nd_syscall.sendmsg ? {}
probe syscall.sendmsg.return = dw_syscall.sendmsg.return !,
                               nd_syscall.sendmsg.return ? {}

# dw_sendmsg _____________________________________________________

probe dw_syscall.sendmsg = __syscall.sendmsg ?, __syscall.socketcall.sendmsg ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple
	@_SYSCALL_SENDMSG_NAME
	flags_str = _msg_flags_str(flags)
	@_SYSCALL_SENDMSG_ARGSTR
}
probe __syscall.sendmsg = kernel.function("sys_sendmsg").call ?
{
	@__syscall_gate(@const("__NR_sendmsg"))
	s = __int32($fd)
	msg_uaddr = $msg
	flags = __uint32($flags)
}
probe __syscall.socketcall.sendmsg = kernel.function("sys_socketcall").call ?
{
	if (__int32($call) != @const("SYS_SENDMSG")) next;
	s = __int32(user_ulong(&@ulong_cast($args)[0]))
	msg_uaddr = user_ulong(&@ulong_cast($args)[1])
	flags = __uint32(user_ulong(&@ulong_cast($args)[2]))
}
probe dw_syscall.sendmsg.return = __syscall.sendmsg.return ?,
	__syscall.socketcall.sendmsg.return ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple
	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR($return)
}
probe __syscall.sendmsg.return = kernel.function("sys_sendmsg").return ?
{
	@__syscall_gate(@const("__NR_sendmsg"))
}
probe __syscall.socketcall.sendmsg.return =
	kernel.function("sys_socketcall").return ?
{
	if (__int32(@entry($call)) != @const("SYS_SENDMSG")) next;
}

# nd_sendmsg _____________________________________________________

probe nd_syscall.sendmsg = nd1_syscall.sendmsg!, nd2_syscall.sendmsg!, tp_syscall.sendmsg
  { }

probe nd1_syscall.sendmsg = __nd1_syscall.sendmsg ?,
	__nd1_syscall.socketcall.sendmsg ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple

	@_SYSCALL_SENDMSG_NAME
	flags_str = _msg_flags_str(flags)
	@_SYSCALL_SENDMSG_ARGSTR
}
probe __nd1_syscall.sendmsg = kprobe.function("sys_sendmsg") ?
{
	@__syscall_gate(@const("__NR_sendmsg"))
	asmlinkage()
	@_SYSCALL_SENDMSG_REGARGS
}
probe __nd1_syscall.socketcall.sendmsg = kprobe.function("sys_socketcall").call ?
{
	asmlinkage()
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SOCKETCALL_SENDMSG_REGARGS
}

/* kernel 4.17+ */
probe nd2_syscall.sendmsg = __nd2_syscall.sendmsg ?,
	__nd2_syscall.socketcall.sendmsg ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple

	@_SYSCALL_SENDMSG_NAME
	flags_str = _msg_flags_str(flags)
	@_SYSCALL_SENDMSG_ARGSTR
}
probe __nd2_syscall.sendmsg = kprobe.function(@arch_syscall_prefix "sys_sendmsg") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_SENDMSG_REGARGS
}
probe __nd2_syscall.socketcall.sendmsg = kprobe.function(@arch_syscall_prefix "sys_socketcall").call ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SOCKETCALL_SENDMSG_REGARGS
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sendmsg = __tp_syscall.sendmsg ?,
	__tp_syscall.socketcall.sendmsg ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple

	@_SYSCALL_SENDMSG_NAME
	flags_str = _msg_flags_str(flags)
	@_SYSCALL_SENDMSG_ARGSTR
}
probe __tp_syscall.sendmsg = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_sendmsg"))
	@_SYSCALL_SENDMSG_REGARGS
}
probe __tp_syscall.socketcall.sendmsg = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_socketcall"))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SOCKETCALL_SENDMSG_REGARGS
}

probe nd_syscall.sendmsg.return = nd1_syscall.sendmsg.return!, nd2_syscall.sendmsg.return!, tp_syscall.sendmsg.return
  { }

probe nd1_syscall.sendmsg.return = __nd1_syscall.sendmsg.return ?,
	__nd1_syscall.socketcall.sendmsg.return ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple

	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR(returnval())
}
probe __nd1_syscall.sendmsg.return = kprobe.function("sys_sendmsg").return ?
{
	@__syscall_gate(@const("__NR_sendmsg"))
}
probe __nd1_syscall.socketcall.sendmsg.return =
	kprobe.function("sys_socketcall").return ?
{
	if (@entry(__asmlinkage_int_arg(1)) != @const("SYS_SENDMSG")) next;
}

/* kernel 4.17+ */
probe nd2_syscall.sendmsg.return =
	kprobe.function(@arch_syscall_prefix "sys_sendmsg").return ?,
	__nd2_syscall.socketcall.sendmsg.return ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple

	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR(returnval())
}
probe __nd2_syscall.socketcall.sendmsg.return =
	kprobe.function(@arch_syscall_prefix "sys_socketcall").return ?
{
	__set_syscall_pt_regs(@entry(pointer_arg(1)))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sendmsg.return = __tp_syscall.sendmsg.return ?,
	__tp_syscall.socketcall.sendmsg.return ?
{
	# Avoid probe hits from compat_sys_socketcall() calling
	# compat_sys_sendmsg(), which sometimes calls
	# sys_sendmsg(). We could call __syscall_gate2() here with
	# NR_sendmsg and NR_socketcall, but all we really need to
	# check is that we're not in a compat task.
	@__syscall_gate_compat_simple

	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR($ret)
}
probe __tp_syscall.sendmsg.return = kernel.trace("sys_exit")
{
	@__syscall_gate(@const("__NR_sendmsg"))
}
probe __tp_syscall.socketcall.sendmsg.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_socketcall"))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
}

# compat_sys_sendmsg ________________________________________
#
# long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags)
#
# On all tested kernels/architectures, the compat sendmsg() syscall
# goes through compat_sys_socketcall(). compat_sys_socketcall() then
# calls an inlined version of compat_sys_sendmsg() on some
# architectures (like x86_64 and ppc64). So, the only reliable thing
# to do here is just probe compat_sys_socketcall().
#
# Note that this probe should have been either called
# 'syscall.compat_sendmsg' or just merged with 'syscall.sendmsg'.
#

probe syscall.compat_sys_sendmsg = dw_syscall.compat_sys_sendmsg !,
                                   nd_syscall.compat_sys_sendmsg ? {}
probe syscall.compat_sys_sendmsg.return = dw_syscall.compat_sys_sendmsg.return !,
                                          nd_syscall.compat_sys_sendmsg.return ? {}

# dw_compat_sys_sendmsg _____________________________________________________

probe dw_syscall.compat_sys_sendmsg =
	kernel.function("compat_sys_socketcall").call ?
{
	if (__int32($call) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	s = user_int(&@uint_cast($args)[0])
	msg_uaddr = user_uint32(&@uint_cast($args)[1])
	flags = user_uint32(&@uint_cast($args)[2])
	flags_str = _msg_flags_str(flags)
	@_SYSCALL_SENDMSG_ARGSTR
}
probe dw_syscall.compat_sys_sendmsg.return =
 	kernel.function("compat_sys_socketcall").return ?
{
	if (__int32(@entry($call)) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR($return)
}

# nd_compat_sys_sendmsg _____________________________________________________

probe nd_syscall.compat_sys_sendmsg = nd1_syscall.compat_sys_sendmsg!, nd2_syscall.compat_sys_sendmsg!, tp_syscall.compat_sys_sendmsg
  { }

probe nd1_syscall.compat_sys_sendmsg =
	kprobe.function("compat_sys_socketcall").call ?
{
	asmlinkage()
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	@_SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
	@_SYSCALL_SENDMSG_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.compat_sys_sendmsg =
	kprobe.function(@arch_syscall_prefix "compat_sys_socketcall").call ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	@_SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
	@_SYSCALL_SENDMSG_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.compat_sys_sendmsg = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__compat_syscall_gate(@const("__NR_compat_socketcall"))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	@_SYSCALL_COMPAT_SOCKETCALL_SENDMSG_REGARGS
	@_SYSCALL_SENDMSG_ARGSTR
}

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
  { }

probe nd1_syscall.compat_sys_sendmsg.return =
	kprobe.function("compat_sys_socketcall").return ?
{
	if (@entry(__asmlinkage_int_arg(1)) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.compat_sys_sendmsg.return =
	kprobe.function(@arch_syscall_prefix "compat_sys_socketcall").return ?
{
	__set_syscall_pt_regs(@entry(pointer_arg(1)))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.compat_sys_sendmsg.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__compat_syscall_gate(@const("__NR_compat_socketcall"))
	if (int_arg(1) != @const("SYS_SENDMSG")) next;
	@_SYSCALL_SENDMSG_NAME
	@SYSC_RETVALSTR($ret)
}