Debian Codegraph @

tapset/linux/sysc_chown.stp

raw
1 # chown ______________________________________________________
2 # long sys_chown(const char __user * filename, uid_t user, gid_t group)
3
4 @define _SYSCALL_CHOWN_NAME
5 %(
6 name = "chown"
7 %)
8
9 @define _SYSCALL_CHOWN_ARGSTR
10 %(
11 argstr = sprintf("%s, %d, %d", path, owner, group)
12 %)
13
14 @define _SYSCALL_CHOWN_REGARGS
15 %(
16 path = user_string_quoted(pointer_arg(1))
17 path_unquoted = user_string_nofault(pointer_arg(1))
18 owner = __int32(uint_arg(2))
19 group = __int32(uint_arg(3))
20 %)
21
22 @define _SYSCALL_CHOWN_REGARGS_STORE
23 %(
24 if (@probewrite(path_unquoted))
25 set_user_string_arg(pointer_arg(1), path_unquoted)
26
27 if (@probewrite(owner))
28 set_uint_arg(2, __int32(owner))
29
30 if (@probewrite(group))
31 set_uint_arg(3, __int32(group))
32 %)
33
34 probe syscall.chown = dw_syscall.chown !, nd_syscall.chown ? {}
35 probe syscall.chown.return = dw_syscall.chown.return !, nd_syscall.chown.return ? {}
36
37 # dw_chown _____________________________________________________
38
39 probe dw_syscall.chown = kernel.function("sys_chown").call
40 {
41 // Avoid chown16() calling chown().
42 %( arch == "x86_64" %?
43 @__syscall_compat_gate(@const("__NR_chown"), @const("__NR_ia32_chown32"))
44 %)
45 %( arch == "i386" %?
46 @__syscall_gate(@const("__NR_chown32"))
47 %)
48 @_SYSCALL_CHOWN_NAME
49 path = user_string_quoted($filename)
50 owner = __int32($user)
51 group = __int32($group)
52 @_SYSCALL_CHOWN_ARGSTR
53 }
54 probe dw_syscall.chown.return = kernel.function("sys_chown").return
55 {
56 %( arch == "x86_64" %?
57 @__syscall_compat_gate(@const("__NR_chown"), @const("__NR_ia32_chown32"))
58 %)
59 %( arch == "i386" %?
60 @__syscall_gate(@const("__NR_chown32"))
61 %)
62 @_SYSCALL_CHOWN_NAME
63 @SYSC_RETVALSTR($return)
64 }
65
66 # nd_chown _____________________________________________________
67
68 probe nd_syscall.chown = nd1_syscall.chown!, nd2_syscall.chown!, tp_syscall.chown
69 { }
70
71 probe nd1_syscall.chown = kprobe.function("sys_chown") ?
72 {
73 // Avoid chown16() calling chown().
74 %( arch == "x86_64" %?
75 @__syscall_compat_gate(@const("__NR_chown"), @const("__NR_ia32_chown32"))
76 %)
77 %( arch == "i386" %?
78 @__syscall_gate(@const("__NR_chown32"))
79 %)
80 @_SYSCALL_CHOWN_NAME
81 asmlinkage()
82 @_SYSCALL_CHOWN_REGARGS
83 @_SYSCALL_CHOWN_ARGSTR
84 }
85
86 /* kernel 4.17+ */
87 probe nd2_syscall.chown = kprobe.function(@arch_syscall_prefix "sys_chown") ?
88 {
89 __set_syscall_pt_regs(pointer_arg(1))
90 @_SYSCALL_CHOWN_NAME
91 @_SYSCALL_CHOWN_REGARGS
92 @_SYSCALL_CHOWN_ARGSTR
93 },
94 {
95 %( @_IS_SREG_KERNEL %? @_SYSCALL_CHOWN_REGARGS_STORE %)
96 }
97
98 /* kernel 3.5+, but undesirable because it affects all syscalls */
99 probe tp_syscall.chown = kernel.trace("sys_enter")
100 {
101 __set_syscall_pt_regs($regs)
102 %( CONFIG_64BIT == "y" %?
103 @__syscall_compat_gate(@const("__NR_chown"), @const("__NR_compat_chown32"))
104 %:
105 @__syscall_gate(@const("__NR_chown32"))
106 %)
107 @_SYSCALL_CHOWN_NAME
108 @_SYSCALL_CHOWN_REGARGS
109 @_SYSCALL_CHOWN_ARGSTR
110 },
111 {
112 %( @_IS_SREG_KERNEL %? @_SYSCALL_CHOWN_REGARGS_STORE %)
113 }
114
115 probe nd_syscall.chown.return = nd1_syscall.chown.return!, nd2_syscall.chown.return!, tp_syscall.chown.return
116 { }
117
118 probe nd1_syscall.chown.return = kprobe.function("sys_chown").return ?
119 {
120 %( arch == "x86_64" %?
121 @__syscall_compat_gate(@const("__NR_chown"), @const("__NR_ia32_chown32"))
122 %)
123 %( arch == "i386" %?
124 @__syscall_gate(@const("__NR_chown32"))
125 %)
126 @_SYSCALL_CHOWN_NAME
127 @SYSC_RETVALSTR(returnval())
128 }
129
130 /* kernel 4.17+ */
131 probe nd2_syscall.chown.return = kprobe.function(@arch_syscall_prefix "sys_chown").return ?
132 {
133 @_SYSCALL_CHOWN_NAME
134 @SYSC_RETVALSTR(returnval())
135 }
136
137 /* kernel 3.5+, but undesirable because it affects all syscalls */
138 probe tp_syscall.chown.return = kernel.trace("sys_exit")
139 {
140 __set_syscall_pt_regs($regs)
141 %( CONFIG_64BIT == "y" %?
142 @__syscall_compat_gate(@const("__NR_chown"), @const("__NR_compat_chown32"))
143 %:
144 @__syscall_gate(@const("__NR_chown32"))
145 %)
146 @_SYSCALL_CHOWN_NAME
147 @SYSC_RETVALSTR($ret)
148 }