Debian Codegraph @

tapset/linux/sysc_ptrace.stp

raw
1 # ptrace _____________________________________________________
2 #
3 # int sys_ptrace(long request,
4 # long pid,
5 # long addr,
6 # long data)
7 #
8
9 @define _SYSCALL_PTRACE_NAME
10 %(
11 name = "ptrace"
12 %)
13
14 @define _SYSCALL_PTRACE_ARGSTR
15 %(
16 argstr = _ptrace_argstr(request, pid, addr, data)
17 %)
18
19 @define _SYSCALL_PTRACE_REGARGS
20 %(
21 request = long_arg(1)
22 pid = int_arg(2)
23 addr = ulong_arg(3)
24 data = ulong_arg(4)
25 %)
26
27 @define _SYSCALL_PTRACE_REGARGS_STORE
28 %(
29 if (@probewrite(request))
30 set_long_arg(1, request)
31
32 if (@probewrite(pid))
33 set_int_arg(2, pid)
34
35 if (@probewrite(addr))
36 set_ulong_arg(3, addr)
37
38 if (@probewrite(data))
39 set_ulong_arg(4, data)
40 %)
41
42 probe syscall.ptrace = dw_syscall.ptrace !, nd_syscall.ptrace ? {}
43 probe syscall.ptrace.return = dw_syscall.ptrace.return !,
44 nd_syscall.ptrace.return ? {}
45
46 # dw_ptrace _____________________________________________________
47
48 probe dw_syscall.ptrace = kernel.function("sys_ptrace").call ?,
49 kernel.function("compat_sys_ptrace").call ?
50 {
51 @_SYSCALL_PTRACE_NAME
52 request = @__compat_ulong($request)
53 pid = __int32($pid)
54 addr = @__compat_ulong($addr)
55 data = @__compat_ulong(@choose_defined($data, $cdata))
56 @_SYSCALL_PTRACE_ARGSTR
57 }
58 probe dw_syscall.ptrace.return = kernel.function("sys_ptrace").return ?,
59 kernel.function("compat_sys_ptrace").return ?
60 {
61 @_SYSCALL_PTRACE_NAME
62 @SYSC_RETVALSTR($return)
63
64 geteventmsg_data = _ptrace_return_geteventmsg_data(@entry($request), @entry($data))
65 arch_prctl_addr = _ptrace_return_arch_prctl_addr(@entry($request), @entry($addr), @entry($data))
66 }
67
68 # nd_ptrace _____________________________________________________
69
70 probe nd_syscall.ptrace = nd1_syscall.ptrace!, nd2_syscall.ptrace!, tp_syscall.ptrace
71 { }
72
73 probe nd1_syscall.ptrace = kprobe.function("sys_ptrace") ?,
74 kprobe.function("compat_sys_ptrace") ?
75 {
76 @_SYSCALL_PTRACE_NAME
77 asmlinkage()
78 @_SYSCALL_PTRACE_REGARGS
79 @_SYSCALL_PTRACE_ARGSTR
80 }
81
82 /* kernel 4.17+ */
83 probe nd2_syscall.ptrace = kprobe.function(@arch_syscall_prefix "sys_ptrace") ?,
84 kprobe.function(@arch_syscall_prefix "compat_sys_ptrace") ?
85 {
86 __set_syscall_pt_regs(pointer_arg(1))
87 @_SYSCALL_PTRACE_NAME
88 @_SYSCALL_PTRACE_REGARGS
89 @_SYSCALL_PTRACE_ARGSTR
90 },
91 {
92 %( @_IS_SREG_KERNEL %? @_SYSCALL_PTRACE_REGARGS_STORE %)
93 }
94
95 /* kernel 3.5+, but undesirable because it affects all syscalls */
96 probe tp_syscall.ptrace = kernel.trace("sys_enter")
97 {
98 __set_syscall_pt_regs($regs)
99 @__syscall_compat_gate(@const("__NR_ptrace"), @const("__NR_compat_ptrace"))
100 @_SYSCALL_PTRACE_NAME
101 @_SYSCALL_PTRACE_REGARGS
102 @_SYSCALL_PTRACE_ARGSTR
103 },
104 {
105 %( @_IS_SREG_KERNEL %? @_SYSCALL_PTRACE_REGARGS_STORE %)
106 }
107
108 probe nd_syscall.ptrace.return = nd1_syscall.ptrace.return!, nd2_syscall.ptrace.return!, tp_syscall.ptrace.return
109 { }
110
111 probe nd1_syscall.ptrace.return = kprobe.function("sys_ptrace").return ?,
112 kprobe.function("compat_sys_ptrace").return ?
113 {
114 @_SYSCALL_PTRACE_NAME
115 @SYSC_RETVALSTR(returnval())
116
117 geteventmsg_data = 0
118 arch_prctl_addr = 0
119 }
120
121 /* kernel 4.17+ */
122 probe nd2_syscall.ptrace.return = kprobe.function(@arch_syscall_prefix "sys_ptrace").return ?,
123 kprobe.function(@arch_syscall_prefix "compat_sys_ptrace").return ?
124 {
125 @_SYSCALL_PTRACE_NAME
126 @SYSC_RETVALSTR(returnval())
127
128 geteventmsg_data = 0
129 arch_prctl_addr = 0
130 }
131
132 /* kernel 3.5+, but undesirable because it affects all syscalls */
133 probe tp_syscall.ptrace.return = kernel.trace("sys_exit")
134 {
135 __set_syscall_pt_regs($regs)
136 @__syscall_compat_gate(@const("__NR_ptrace"), @const("__NR_compat_ptrace"))
137 @_SYSCALL_PTRACE_NAME
138 @SYSC_RETVALSTR($ret)
139
140 geteventmsg_data = 0
141 arch_prctl_addr = 0
142 }