File: sysc_setfsuid.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 (157 lines) | stat: -rw-r--r-- 4,584 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
# setfsuid ___________________________________________________
# long sys_setfsuid(uid_t uid)
# long sys_setfsuid16(old_uid_t uid)
#

@define _SYSCALL_SETFSUID_NAME
%(
	name = "setfsuid"
%)

@define _SYSCALL_SETFSUID_ARGSTR
%(
	argstr = sprint(fsuid)
%)

@define _SYSCALL_GATE
%(
    %( arch == "x86_64" %?
	// There are actually 3 x86_64 setfsuid syscalls numbers (which
	// get mapped to 2 syscall functions:
	//   - __NR_setfsuid which gets mapped to sys_setfsuid()
	//   - __NR_ia32_setfsuid32 which also gets mapped to
	//     sys_setfsuid() 
	//   - __NR_ia32_setfsuid which gets mapped to sys_setfsuid16()
	//     (which is a wrapper around sys_setfsuid())
	// So, we need to avoid sys_setfsuid() calls that come from
	// sys_setfsuid16().
	@__syscall_compat_gate(@const("__NR_setfsuid"),
			       @const("__NR_ia32_setfsuid32"))
    %:
	%( arch == "i386" %?
	    // On i386, there are 2 setfsuid syscall numbers:
	    //   - __NR_setfsuid which gets mapped to sys_setfsuid16
	    //   - __NR_setfsuid32 which gets mapped to sys_setfsuid
	    // Since this gets called from a probe on sys_setfsuid, we'll
	    // make sure this is really __NR_setfsuid32.
	    @__syscall_nr_gate(@const("__NR_setfsuid32"))
	%)
    %)
%)

@define _SYSCALL_SETFSUID_REGARGS
%(
	fsuid = int_arg(1)
%)

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

# dw_setfsuid _____________________________________________________

probe dw_syscall.setfsuid = kernel.function("sys_setfsuid16").call ?,
			    __syscall.setfsuid ?
{
	@_SYSCALL_SETFSUID_NAME
	fsuid = __int32($uid)
	@_SYSCALL_SETFSUID_ARGSTR
}
probe __syscall.setfsuid = kernel.function("sys_setfsuid").call ?
{
	@_SYSCALL_GATE
}
probe dw_syscall.setfsuid.return = kernel.function("sys_setfsuid16").return ?,
				   __syscall.setfsuid.return ?
{
	@_SYSCALL_SETFSUID_NAME
	@SYSC_RETVALSTR($return)
}
probe __syscall.setfsuid.return = kernel.function("sys_setfsuid").return ?
{
	@_SYSCALL_GATE
}

# nd_setfsuid _____________________________________________________

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

probe nd1_syscall.setfsuid = kprobe.function("sys_setfsuid16") ?,
                             __nd1_syscall.setfsuid ?
{
	@_SYSCALL_SETFSUID_NAME
	asmlinkage()
	@_SYSCALL_SETFSUID_REGARGS
	@_SYSCALL_SETFSUID_ARGSTR
}
probe __nd1_syscall.setfsuid = kprobe.function("sys_setfsuid") ?
{
	@_SYSCALL_GATE
}

/* kernel 4.17+ */
probe nd2_syscall.setfsuid = kprobe.function(@arch_syscall_prefix "sys_setfsuid") ?,
                             kprobe.function(@arch_syscall_prefix "sys_setfsuid16") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_SETFSUID_NAME
	@_SYSCALL_SETFSUID_REGARGS
	@_SYSCALL_SETFSUID_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.setfsuid = __tp_syscall.setfsuid, __tp_syscall.setfsuid16
{
	__set_syscall_pt_regs($regs)
	@_SYSCALL_SETFSUID_NAME
	@_SYSCALL_SETFSUID_REGARGS
	@_SYSCALL_SETFSUID_ARGSTR
}
probe __tp_syscall.setfsuid = kernel.trace("sys_enter")
{
	@__syscall_compat_gate(@const("__NR_setfsuid"), @const("__NR_compat_setfsuid32"))
}
probe __tp_syscall.setfsuid16 = kernel.trace("sys_enter")
{
	@__compat_syscall_gate(@const("__NR_compat_setfsuid"))
}

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

probe nd1_syscall.setfsuid.return = kprobe.function("sys_setfsuid16").return ?,
                                    __nd1_syscall.setfsuid.return ?
{
	@_SYSCALL_SETFSUID_NAME
	@SYSC_RETVALSTR(returnval())
}
probe __nd1_syscall.setfsuid.return = kprobe.function("sys_setfsuid").return ?
{
	@_SYSCALL_GATE
}

/* kernel 4.17+ */
probe nd2_syscall.setfsuid.return =
	kprobe.function(@arch_syscall_prefix "sys_setfsuid").return ?,
	kprobe.function(@arch_syscall_prefix "sys_setfsuid16").return ?
{
	@_SYSCALL_SETFSUID_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.setfsuid.return = __tp_syscall.setfsuid.return, __tp_syscall.setfsuid16.return
{
	__set_syscall_pt_regs($regs)
	@_SYSCALL_SETFSUID_NAME
	@SYSC_RETVALSTR($ret)
}
probe __tp_syscall.setfsuid.return = kernel.trace("sys_exit")
{
	@__syscall_compat_gate(@const("__NR_setfsuid"), @const("__NR_compat_setfsuid32"))
}
probe __tp_syscall.setfsuid16.return = kernel.trace("sys_exit")
{
	@__compat_syscall_gate(@const("__NR_compat_setfsuid"))
}