Debian Codegraph @

tapset/linux/sysc_setfsuid.stp

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