Debian Codegraph @

tapset/linux/sysc_setuid.stp

raw
1 # setuid _____________________________________________________
2 #
3 # long sys_setuid(uid_t uid)
4 # long sys_setuid16(old_uid_t uid)
5 #
6
7 @define _SYSCALL_SETUID_NAME
8 %(
9 name = "setuid"
10 %)
11
12 @define _SYSCALL_SETUID_ARGSTR
13 %(
14 argstr = sprint(uid)
15 %)
16
17 @define _SYSCALL_GATE
18 %(
19 %( arch == "x86_64" %?
20 // There are actually 3 x86_64 setuid syscall numbers (which
21 // get mapped to 2 syscall functions:
22 // - __NR_setuid which gets mapped to sys_setuid()
23 // - __NR_ia32_setuid32 which also gets mapped to
24 // sys_setuid()
25 // - __NR_ia32_setuid which gets mapped to sys_setuid16()
26 // (which is a wrapper around sys_setuid())
27 // So, we need to avoid sys_setuid() calls that come from
28 // sys_setuid16().
29 @__syscall_compat_gate(@const("__NR_setuid"),
30 @const("__NR_ia32_setuid32"))
31 %:
32 %( arch == "i386" %?
33 // On i386, there are 2 setuid syscall numbers:
34 // - __NR_setuid which gets mapped to sys_setuid16
35 // - __NR_setuid32 which gets mapped to sys_setuid
36 // Since this gets called from a probe on sys_setuid, we'll
37 // make sure this is really __NR_setuid32.
38 @__syscall_nr_gate(@const("__NR_setuid32"))
39 %)
40 %)
41 %)
42
43 @define _SYSCALL_SETUID_REGARGS
44 %(
45 uid = int_arg(1)
46 %)
47
48 @define _SYSCALL_SETUID_REGARGS_STORE
49 %(
50 if (@probewrite(uid))
51 set_int_arg(1, uid)
52 %)
53
54 probe syscall.setuid = dw_syscall.setuid !, nd_syscall.setuid ? {}
55 probe syscall.setuid.return = dw_syscall.setuid.return !,
56 nd_syscall.setuid.return ? {}
57
58 # dw_setuid _____________________________________________________
59
60 probe dw_syscall.setuid = kernel.function("sys_setuid16").call ?,
61 __syscall.setuid ?
62 {
63 @_SYSCALL_SETUID_NAME
64 uid = __int32($uid)
65 @_SYSCALL_SETUID_ARGSTR
66 }
67 probe __syscall.setuid = kernel.function("sys_setuid").call ?
68 {
69 @_SYSCALL_GATE
70 }
71 probe dw_syscall.setuid.return = kernel.function("sys_setuid16").return ?,
72 __syscall.setuid.return ?
73 {
74 @_SYSCALL_SETUID_NAME
75 @SYSC_RETVALSTR($return)
76 }
77 probe __syscall.setuid.return = kernel.function("sys_setuid").return ?
78 {
79 @_SYSCALL_GATE
80 }
81
82 # nd_setuid _____________________________________________________
83
84 probe nd_syscall.setuid = nd1_syscall.setuid!, nd2_syscall.setuid!, tp_syscall.setuid
85 { }
86
87 probe nd1_syscall.setuid = kprobe.function("sys_setuid16") ?,
88 __nd1_syscall.setuid ?
89 {
90 @_SYSCALL_SETUID_NAME
91 asmlinkage()
92 @_SYSCALL_SETUID_REGARGS
93 @_SYSCALL_SETUID_ARGSTR
94 }
95 probe __nd1_syscall.setuid = kprobe.function("sys_setuid") ?
96 {
97 @_SYSCALL_GATE
98 }
99
100 /* kernel 4.17+ */
101 probe nd2_syscall.setuid = kprobe.function(@arch_syscall_prefix "sys_setuid") ?,
102 kprobe.function(@arch_syscall_prefix "sys_setuid16") ?
103 {
104 __set_syscall_pt_regs(pointer_arg(1))
105 @_SYSCALL_SETUID_NAME
106 @_SYSCALL_SETUID_REGARGS
107 @_SYSCALL_SETUID_ARGSTR
108 },
109 {
110 %( @_IS_SREG_KERNEL %? @_SYSCALL_SETUID_REGARGS_STORE %)
111 }
112
113 /* kernel 3.5+, but undesirable because it affects all syscalls */
114 probe tp_syscall.setuid = __tp_syscall.setuid, __tp_syscall.setuid16
115 {
116 __set_syscall_pt_regs($regs)
117 @_SYSCALL_SETUID_NAME
118 @_SYSCALL_SETUID_REGARGS
119 @_SYSCALL_SETUID_ARGSTR
120 },
121 {
122 %( @_IS_SREG_KERNEL %? @_SYSCALL_SETUID_REGARGS_STORE %)
123 }
124 probe __tp_syscall.setuid = kernel.trace("sys_enter")
125 {
126 @__syscall_compat_gate(@const("__NR_setuid"), @const("__NR_compat_setuid32"))
127 }
128 probe __tp_syscall.setuid16 = kernel.trace("sys_enter")
129 {
130 @__compat_syscall_gate(@const("__NR_compat_setuid"))
131 }
132
133 probe nd_syscall.setuid.return = nd1_syscall.setuid.return!, nd2_syscall.setuid.return!, tp_syscall.setuid.return
134 { }
135
136 probe nd1_syscall.setuid.return = kprobe.function("sys_setuid16").return ?,
137 __nd1_syscall.setuid.return ?
138 {
139 @_SYSCALL_SETUID_NAME
140 @SYSC_RETVALSTR(returnval())
141 }
142 probe __nd1_syscall.setuid.return = kprobe.function("sys_setuid").return ?
143 {
144 @_SYSCALL_GATE
145 }
146
147 /* kernel 4.17+ */
148 probe nd2_syscall.setuid.return =
149 kprobe.function(@arch_syscall_prefix "sys_setuid").return ?,
150 kprobe.function(@arch_syscall_prefix "sys_setuid16").return ?
151 {
152 @_SYSCALL_SETUID_NAME
153 @SYSC_RETVALSTR(returnval())
154 }
155
156 /* kernel 3.5+, but undesirable because it affects all syscalls */
157 probe tp_syscall.setuid.return = __tp_syscall.setuid.return, __tp_syscall.setuid16.return
158 {
159 __set_syscall_pt_regs($regs)
160 @_SYSCALL_SETUID_NAME
161 @SYSC_RETVALSTR($ret)
162 }
163 probe __tp_syscall.setuid.return = kernel.trace("sys_exit")
164 {
165 @__syscall_compat_gate(@const("__NR_setuid"), @const("__NR_compat_setuid32"))
166 }
167 probe __tp_syscall.setuid16.return = kernel.trace("sys_exit")
168 {
169 @__compat_syscall_gate(@const("__NR_compat_setuid"))
170 }