Debian Codegraph @

tapset/linux/sysc_sendto.stp

raw
1 # sendto _____________________________________________________
2 #
3 # long sys_sendto(int fd,
4 # void __user * buff,
5 # size_t len,
6 # unsigned flags,
7 # struct sockaddr __user *addr,
8 # int addr_len)
9 #
10
11 @define _SYSCALL_SENDTO_NAME
12 %(
13 name = "sendto"
14 %)
15
16 @define _SYSCALL_SENDTO_ARGSTR
17 %(
18 argstr = sprintf("%d, %s, %u, %s, %s, %u", s, buf, len, flags_str, to_str, tolen)
19 %)
20
21 @define _SYSCALL_SENDTO_REGARGS
22 %(
23 s = int_arg(1)
24 buf_uaddr = pointer_arg(2)
25 len = ulong_arg(3)
26 flags = uint_arg(4)
27 to_uaddr = pointer_arg(5)
28 tolen = uint_arg(6)
29 %)
30
31 @define _SYSCALL_SENDTO_REGARGS_STORE
32 %(
33 if (@probewrite(s))
34 set_int_arg(1, s)
35
36 if (@probewrite(buf_uaddr))
37 set_pointer_arg(2, buf_uaddr)
38
39 if (@probewrite(len))
40 set_ulong_arg(3, len)
41
42 if (@probewrite(flags))
43 set_uint_arg(4, flags)
44
45 if (@probewrite(to_uaddr))
46 set_pointer_arg(5, to_uaddr)
47
48 if (@probewrite(tolen))
49 set_uint_arg(6, tolen)
50 %)
51
52 @define _SYSCALL_SOCKETCALL_SENDTO_REGARGS
53 %(
54 __args = &@ulong_cast(pointer_arg(2))
55 s = __int32(user_ulong(&@ulong_cast(__args)[0]))
56 buf_uaddr = user_ulong(&@ulong_cast(__args)[1])
57 len = user_ulong(&@ulong_cast(__args)[2])
58 flags = __uint32(user_ulong(&@ulong_cast(__args)[3]))
59 to_uaddr = user_ulong(&@ulong_cast(__args)[4])
60 tolen = __uint32(user_ulong(&@ulong_cast(__args)[5]))
61 %)
62
63 @define _SYSCALL_COMPAT_SOCKETCALL_SENDTO_REGARGS
64 %(
65 __args = &@uint_cast(pointer_arg(2))
66 s = user_int(&@uint_cast(__args)[0])
67 buf_uaddr = user_uint32(&@uint_cast(__args)[1])
68 len = user_uint32(&@uint_cast(__args)[2])
69 flags = user_uint32(&@uint_cast(__args)[3])
70 to_uaddr = user_uint32(&@uint_cast(__args)[4])
71 tolen = user_uint32(&@uint_cast(__args)[5])
72 %)
73
74 probe syscall.sendto = dw_syscall.sendto !, nd_syscall.sendto ? {}
75 probe syscall.sendto.return = dw_syscall.sendto.return !,
76 nd_syscall.sendto.return ? {}
77
78 # dw_sendto _____________________________________________________
79
80 probe dw_syscall.sendto = __syscall.sendto ?, __syscall.socketcall.sendto ?,
81 __syscall.compat_socketcall.sendto ?
82 {
83 @_SYSCALL_SENDTO_NAME
84 flags_str = _msg_flags_str(flags)
85 buf = user_buffer_quoted(buf_uaddr, len, syscall_string_trunc)
86 to_str = _struct_sockaddr_u(to_uaddr, tolen)
87 @_SYSCALL_SENDTO_ARGSTR
88 }
89 probe __syscall.sendto = kernel.function("sys_sendto").call ?
90 {
91 @__syscall_gate(@const("__NR_sendto"))
92 s = __int32($fd)
93 buf_uaddr = $buff
94 len = __ulong($len)
95 flags = __uint32($flags)
96 to_uaddr = $addr
97 tolen = __uint32($addr_len)
98 }
99 probe __syscall.socketcall.sendto = kernel.function("sys_socketcall").call ?
100 {
101 if (__int32($call) != @const("SYS_SENDTO")) next;
102 s = __int32(user_ulong(&@ulong_cast($args)[0]))
103 buf_uaddr = user_ulong(&@ulong_cast($args)[1])
104 len = user_ulong(&@ulong_cast($args)[2])
105 flags = __uint32(user_ulong(&@ulong_cast($args)[3]))
106 to_uaddr = user_ulong(&@ulong_cast($args)[4])
107 tolen = __uint32(user_ulong(&@ulong_cast($args)[5]))
108 }
109 probe __syscall.compat_socketcall.sendto =
110 kernel.function("compat_sys_socketcall").call ?
111 {
112 if (__int32($call) != @const("SYS_SENDTO")) next;
113 s = user_int(&@uint_cast($args)[0])
114 buf_uaddr = user_uint32(&@uint_cast($args)[1])
115 len = user_uint32(&@uint_cast($args)[2])
116 flags = user_uint32(&@uint_cast($args)[3])
117 to_uaddr = user_uint32(&@uint_cast($args)[4])
118 tolen = user_uint32(&@uint_cast($args)[5])
119 }
120 probe dw_syscall.sendto.return = kernel.function("sys_sendto").return ?,
121 kernel.function("sys_socketcall").return ?,
122 kernel.function("compat_sys_socketcall").return ?
123 {
124 if (@defined(@entry($call))) {
125 if (__int32(@entry($call)) != @const("SYS_SENDTO")) next;
126 }
127 else {
128 @__syscall_gate(@const("__NR_sendto"))
129 }
130 @_SYSCALL_SENDTO_NAME
131 @SYSC_RETVALSTR($return)
132 }
133
134 # nd_sendto _____________________________________________________
135
136 probe nd_syscall.sendto = nd1_syscall.sendto!, nd2_syscall.sendto!, tp_syscall.sendto
137 { }
138
139 probe nd1_syscall.sendto = __nd1_syscall.sendto ?,
140 __nd1_syscall.socketcall.sendto ?,
141 __nd1_syscall.compat_socketcall.sendto ?
142 {
143 @_SYSCALL_SENDTO_NAME
144 flags_str = _msg_flags_str(flags)
145 buf = user_buffer_quoted(buf_uaddr, len, syscall_string_trunc)
146 to_str = _struct_sockaddr_u(to_uaddr, tolen)
147 @_SYSCALL_SENDTO_ARGSTR
148 }
149 probe __nd1_syscall.sendto = kprobe.function("sys_sendto").call ?
150 {
151 asmlinkage()
152 @__syscall_gate(@const("__NR_sendto"))
153 @_SYSCALL_SENDTO_REGARGS
154 }
155 probe __nd1_syscall.socketcall.sendto = kprobe.function("sys_socketcall").call ?
156 {
157 asmlinkage()
158 if (int_arg(1) != @const("SYS_SENDTO")) next;
159 @_SYSCALL_SOCKETCALL_SENDTO_REGARGS
160 }
161 probe __nd1_syscall.compat_socketcall.sendto =
162 kprobe.function("compat_sys_socketcall").call ?
163 {
164 asmlinkage()
165 if (int_arg(1) != @const("SYS_SENDTO")) next;
166 @_SYSCALL_COMPAT_SOCKETCALL_SENDTO_REGARGS
167 }
168
169 /* kernel 4.17+ */
170 probe nd2_syscall.sendto = __nd2_syscall.sendto ?,
171 __nd2_syscall.socketcall.sendto ?,
172 __nd2_syscall.compat_socketcall.sendto ?
173 {
174 @_SYSCALL_SENDTO_NAME
175 flags_str = _msg_flags_str(flags)
176 buf = user_buffer_quoted(buf_uaddr, len, syscall_string_trunc)
177 to_str = _struct_sockaddr_u(to_uaddr, tolen)
178 @_SYSCALL_SENDTO_ARGSTR
179 }
180 probe __nd2_syscall.sendto = kprobe.function(@arch_syscall_prefix "sys_sendto") ?
181 {
182 __set_syscall_pt_regs(pointer_arg(1))
183 @_SYSCALL_SENDTO_REGARGS
184 },
185 {
186 %( @_IS_SREG_KERNEL %? @_SYSCALL_SENDTO_REGARGS_STORE %)
187 }
188 probe __nd2_syscall.socketcall.sendto = kprobe.function(@arch_syscall_prefix "sys_socketcall").call ?
189 {
190 __set_syscall_pt_regs(pointer_arg(1))
191 if (int_arg(1) != @const("SYS_SENDTO")) next;
192 @_SYSCALL_SOCKETCALL_SENDTO_REGARGS
193 }
194 probe __nd2_syscall.compat_socketcall.sendto =
195 kprobe.function(@arch_syscall_prefix "compat_sys_socketcall").call ?
196 {
197 __set_syscall_pt_regs(pointer_arg(1))
198 if (int_arg(1) != @const("SYS_SENDTO")) next;
199 @_SYSCALL_COMPAT_SOCKETCALL_SENDTO_REGARGS
200 }
201
202 /* kernel 3.5+, but undesirable because it affects all syscalls */
203 probe tp_syscall.sendto = __tp_syscall.sendto ?,
204 __tp_syscall.socketcall.sendto ?
205 {
206 @_SYSCALL_SENDTO_NAME
207 flags_str = _msg_flags_str(flags)
208 buf = user_buffer_quoted(buf_uaddr, len, syscall_string_trunc)
209 to_str = _struct_sockaddr_u(to_uaddr, tolen)
210 @_SYSCALL_SENDTO_ARGSTR
211 }
212 probe __tp_syscall.sendto = kernel.trace("sys_enter")
213 {
214 __set_syscall_pt_regs($regs)
215 @__syscall_gate(@const("__NR_sendto"))
216 @_SYSCALL_SENDTO_REGARGS
217 },
218 {
219 %( @_IS_SREG_KERNEL %? @_SYSCALL_SENDTO_REGARGS_STORE %)
220 }
221 probe __tp_syscall.socketcall.sendto = kernel.trace("sys_enter")
222 {
223 __set_syscall_pt_regs($regs)
224 @__syscall_compat_gate(@const("__NR_socketcall"), @const("__NR_compat_socketcall"))
225 if (int_arg(1) != @const("SYS_SENDTO")) next;
226 if (@__compat_task) {
227 @_SYSCALL_COMPAT_SOCKETCALL_SENDTO_REGARGS
228 }
229 else {
230 @_SYSCALL_SOCKETCALL_SENDTO_REGARGS
231 }
232 }
233
234 probe nd_syscall.sendto.return = nd1_syscall.sendto.return!, nd2_syscall.sendto.return!, tp_syscall.sendto.return
235 { }
236
237 probe nd1_syscall.sendto.return = __nd1_syscall.sendto.return ?,
238 __nd1_syscall.socketcall.sendto.return ?
239 {
240 @_SYSCALL_SENDTO_NAME
241 @SYSC_RETVALSTR(returnval())
242 }
243 probe __nd1_syscall.sendto.return = kprobe.function("sys_sendto").return ?
244 {
245 @__syscall_gate(@const("__NR_sendto"))
246 }
247 probe __nd1_syscall.socketcall.recv.return =
248 kprobe.function("sys_socketcall").return ?,
249 kprobe.function("compat_sys_socketcall").return ?
250 {
251 if (@entry(__asmlinkage_int_arg(1)) != @const("SYS_SENDTO")) next;
252 }
253
254 /* kernel 4.17+ */
255 probe nd2_syscall.sendto.return =
256 kprobe.function(@arch_syscall_prefix "sys_sendto").return ?,
257 __nd2_syscall.socketcall.sendto.return ?
258 {
259 @_SYSCALL_SENDTO_NAME
260 @SYSC_RETVALSTR(returnval())
261 }
262 probe __nd2_syscall.socketcall.sendto.return =
263 kprobe.function(@arch_syscall_prefix "sys_socketcall").return ?,
264 kprobe.function(@arch_syscall_prefix "compat_sys_socketcall").return ?
265 {
266 __set_syscall_pt_regs(@entry(pointer_arg(1)))
267 if (int_arg(1) != @const("SYS_SENDTO")) next;
268 }
269
270 /* kernel 3.5+, but undesirable because it affects all syscalls */
271 probe tp_syscall.sendto.return = __tp_syscall.sendto.return ?,
272 __tp_syscall.socketcall.sendto.return ?
273 {
274 @_SYSCALL_SENDTO_NAME
275 @SYSC_RETVALSTR($ret)
276 }
277 probe __tp_syscall.sendto.return = kernel.trace("sys_exit")
278 {
279 @__syscall_gate(@const("__NR_sendto"))
280 }
281 probe __tp_syscall.socketcall.sendto.return = kernel.trace("sys_exit")
282 {
283 __set_syscall_pt_regs($regs)
284 @__syscall_compat_gate(@const("__NR_socketcall"), @const("__NR_compat_socketcall"))
285 if (int_arg(1) != @const("SYS_SENDTO")) next;
286 }