File: sysc_setreuid.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 (211 lines) | stat: -rw-r--r-- 5,981 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
# setreuid ___________________________________________________
# long sys_setreuid(uid_t ruid, uid_t euid)
#

@define _SYSCALL_SETREUID_NAME
%(
	name = "setreuid"
%)

@define _SYSCALL_SETREUID_ARGSTR
%(
	argstr = sprintf("%d, %d", ruid, euid)
%)

@define _SYSCALL_GATE
%(
    %( arch == "x86_64" %?
	// There are actually 3 x86_64 setreuid syscall numbers (which
	// get mapped to 2 syscall functions:
	//   - __NR_setreuid which gets mapped to sys_setreuid()
	//   - __NR_ia32_setreuid32 which also gets mapped to
	//     sys_setreuid() 
	//   - __NR_ia32_setreuid which gets mapped to sys_setreuid16()
	//     (which is a wrapper around sys_setreuid())
	// So, we need to avoid sys_setreuid() calls that come from
	// sys_setreuid16().
	@__syscall_compat_gate(@const("__NR_setreuid"),
			       @const("__NR_ia32_setreuid32"))
    %:
	%( arch == "i386" %?
	    // On i386, there are 2 setreuid syscall numbers:
	    //   - __NR_setreuid which gets mapped to sys_setreuid16
	    //   - __NR_setreuid32 which gets mapped to sys_setreuid
	    // Since this gets called from a probe on sys_setreuid, we'll
	    // make sure this is really __NR_setreuid32.
	    @__syscall_nr_gate(@const("__NR_setreuid32"))
	%)
    %)
%)

@define _SYSCALL_SETREUID_REGARGS
%(
	ruid = __int32(uint_arg(1))
	euid = __int32(uint_arg(2))
%)

@define _SYSCALL_SETREUID16_REGARGS
%(
	ruid = __short(uint_arg(1))
	euid = __short(uint_arg(2))
%)

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

# dw_setreuid _____________________________________________________

probe dw_syscall.setreuid = kernel.function("sys_setreuid").call
{
	@_SYSCALL_GATE
	@_SYSCALL_SETREUID_NAME
	ruid = __int32($ruid)
	euid = __int32($euid)
	@_SYSCALL_SETREUID_ARGSTR
}
probe dw_syscall.setreuid.return = kernel.function("sys_setreuid").return
{
	@_SYSCALL_GATE
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR($return)
}

# nd_setreuid _____________________________________________________

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

probe nd1_syscall.setreuid = kprobe.function("sys_setreuid") ?
{
	@_SYSCALL_GATE
	@_SYSCALL_SETREUID_NAME
	asmlinkage()
	@_SYSCALL_SETREUID_REGARGS
	@_SYSCALL_SETREUID_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.setreuid = kprobe.function(@arch_syscall_prefix "sys_setreuid") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_SETREUID_NAME
	@_SYSCALL_SETREUID_REGARGS
	@_SYSCALL_SETREUID_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.setreuid = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_setreuid"), @const("__NR_compat_setreuid32"))
	@_SYSCALL_SETREUID_NAME
	@_SYSCALL_SETREUID_REGARGS
	@_SYSCALL_SETREUID_ARGSTR
}

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

probe nd1_syscall.setreuid.return = kprobe.function("sys_setreuid").return ?
{
	@_SYSCALL_GATE
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.setreuid.return = kprobe.function(@arch_syscall_prefix "sys_setreuid").return ?
{
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.setreuid.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_setreuid"), @const("__NR_compat_setreuid32"))
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR($ret)
}

# setreuid16 _________________________________________________
# long sys_setreuid16(old_uid_t ruid, old_uid_t euid)
#

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

# dw_setreuid16 _____________________________________________________

probe dw_syscall.setreuid16 = kernel.function("sys_setreuid16").call ?
{
	@_SYSCALL_SETREUID_NAME
	ruid = __short($ruid)
	euid = __short($euid)
	@_SYSCALL_SETREUID_ARGSTR
}
probe dw_syscall.setreuid16.return = kernel.function("sys_setreuid16").return ?
{
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR($return)
}

# nd_setreuid16 _____________________________________________________

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

probe nd1_syscall.setreuid16 = kprobe.function("sys_setreuid16") ?
{
	@_SYSCALL_SETREUID_NAME
	asmlinkage()
	@_SYSCALL_SETREUID16_REGARGS
	@_SYSCALL_SETREUID_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.setreuid16 = kprobe.function(@arch_syscall_prefix "sys_setreuid16") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_SETREUID_NAME
	@_SYSCALL_SETREUID16_REGARGS
	@_SYSCALL_SETREUID_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.setreuid16 = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__compat_syscall_gate(@const("__NR_compat_setreuid"))
	@_SYSCALL_SETREUID_NAME
	@_SYSCALL_SETREUID16_REGARGS
	@_SYSCALL_SETREUID_ARGSTR
}

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

probe nd1_syscall.setreuid16.return = kprobe.function("sys_setreuid16").return ?
{
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.setreuid16.return = kprobe.function(@arch_syscall_prefix "sys_setreuid16").return ?
{
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.setreuid16.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__compat_syscall_gate(@const("__NR_compat_setreuid"))
	@_SYSCALL_SETREUID_NAME
	@SYSC_RETVALSTR($ret)
}