Debian Codegraph @

tapset/linux/sysc_ioctl.stp

raw
1 # ioctl ______________________________________________________
2 # long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
3 # long compat_sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
4 #
5
6 @define _SYSCALL_IOCTL_NAME
7 %(
8 name = "ioctl"
9 %)
10
11 @define _SYSCALL_IOCTL_ARGSTR
12 %(
13 argstr = sprintf("%d, %d, %p", fd, request, argp)
14 %)
15
16 @define _SYSCALL_IOCTL_REGARGS
17 %(
18 fd = int_arg(1)
19 request = int_arg(2)
20 argp = ulong_arg(3)
21 %)
22
23 @define _SYSCALL_IOCTL_REGARGS_STORE
24 %(
25 if (@probewrite(fd))
26 set_int_arg(1, fd)
27
28 if (@probewrite(request))
29 set_int_arg(2, request)
30
31 if (@probewrite(argp))
32 set_ulong_arg(3, argp)
33 %)
34
35 probe syscall.ioctl = dw_syscall.ioctl !, nd_syscall.ioctl ? {}
36 probe syscall.ioctl.return = dw_syscall.ioctl.return !, nd_syscall.ioctl.return ? {}
37
38 # dw_ioctl _____________________________________________________
39
40 probe dw_syscall.ioctl = __syscall.ioctl ?,
41 kernel.function("compat_sys_ioctl").call ?
42 {
43 @_SYSCALL_IOCTL_NAME
44 fd = __int32($fd)
45 request = __int32($cmd)
46 argp = @__compat_ulong(@choose_defined($arg, $arg32))
47 @_SYSCALL_IOCTL_ARGSTR
48 }
49 probe __syscall.ioctl = kernel.function("sys_ioctl").call
50 {
51 @__syscall_gate(@const("__NR_ioctl"))
52 }
53 probe dw_syscall.ioctl.return =
54 __syscall.ioctl.return ?,
55 kernel.function("compat_sys_ioctl").return ?
56 {
57 @_SYSCALL_IOCTL_NAME
58 @SYSC_RETVALSTR($return)
59 }
60 probe __syscall.ioctl.return = kernel.function("sys_ioctl").return
61 {
62 @__syscall_gate(@const("__NR_ioctl"))
63 }
64
65 # nd_ioctl _____________________________________________________
66
67 probe nd_syscall.ioctl = nd1_syscall.ioctl!, nd2_syscall.ioctl!, tp_syscall.ioctl
68 { }
69
70 probe nd1_syscall.ioctl = __nd1_syscall.ioctl,
71 kprobe.function("compat_sys_ioctl") ?
72 {
73 asmlinkage()
74 @_SYSCALL_IOCTL_NAME
75 @_SYSCALL_IOCTL_REGARGS
76 @_SYSCALL_IOCTL_ARGSTR
77 }
78 probe __nd1_syscall.ioctl = kprobe.function("sys_ioctl")
79 {
80 @__syscall_gate(@const("__NR_ioctl"))
81 }
82
83 /* kernel 4.17+ */
84 probe nd2_syscall.ioctl = kprobe.function(@arch_syscall_prefix "sys_ioctl") ?,
85 kprobe.function(@arch_syscall_prefix "compat_sys_ioctl") ?
86 {
87 __set_syscall_pt_regs(pointer_arg(1))
88 @_SYSCALL_IOCTL_NAME
89 @_SYSCALL_IOCTL_REGARGS
90 @_SYSCALL_IOCTL_ARGSTR
91 },
92 {
93 %( @_IS_SREG_KERNEL %? @_SYSCALL_IOCTL_REGARGS_STORE %)
94 }
95
96 /* kernel 3.5+, but undesirable because it affects all syscalls */
97 probe tp_syscall.ioctl = kernel.trace("sys_enter")
98 {
99 __set_syscall_pt_regs($regs)
100 @__syscall_compat_gate(@const("__NR_ioctl"), @const("__NR_compat_ioctl"))
101 @_SYSCALL_IOCTL_NAME
102 @_SYSCALL_IOCTL_REGARGS
103 @_SYSCALL_IOCTL_ARGSTR
104 },
105 {
106 %( @_IS_SREG_KERNEL %? @_SYSCALL_IOCTL_REGARGS_STORE %)
107 }
108
109 probe nd_syscall.ioctl.return = nd1_syscall.ioctl.return!, nd2_syscall.ioctl.return!, tp_syscall.ioctl.return
110 { }
111
112 probe nd1_syscall.ioctl.return =
113 __nd1_syscall.ioctl.return,
114 kprobe.function("compat_sys_ioctl").return ?
115 {
116 @_SYSCALL_IOCTL_NAME
117 @SYSC_RETVALSTR(returnval())
118 }
119 probe __nd1_syscall.ioctl.return = kprobe.function("sys_ioctl").return
120 {
121 @__syscall_gate(@const("__NR_ioctl"))
122 }
123
124 /* kernel 4.17+ */
125 probe nd2_syscall.ioctl.return = kprobe.function(@arch_syscall_prefix "sys_ioctl").return ?,
126 kprobe.function(@arch_syscall_prefix "compat_sys_ioctl").return ?
127 {
128 @_SYSCALL_IOCTL_NAME
129 @SYSC_RETVALSTR(returnval())
130 }
131
132 /* kernel 3.5+, but undesirable because it affects all syscalls */
133 probe tp_syscall.ioctl.return = kernel.trace("sys_exit")
134 {
135 __set_syscall_pt_regs($regs)
136 @__syscall_compat_gate(@const("__NR_ioctl"), @const("__NR_compat_ioctl"))
137 @_SYSCALL_IOCTL_NAME
138 @SYSC_RETVALSTR($ret)
139 }