Debian Codegraph @

tapset/linux/sysc_bpf.stp

raw
1 # bpf ________________________________________________________
2 # SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr,
3 # unsigned int, size)
4
5 @define _SYSCALL_BPF_NAME
6 %(
7 name = "bpf"
8 %)
9
10 @define _SYSCALL_BPF_ARGSTR
11 %(
12 argstr = sprintf("%s, %p, %u", cmd_str, attr_uaddr, size)
13 %)
14
15 @define _SYSCALL_BPF_REGARGS
16 %(
17 cmd = int_arg(1)
18 cmd_str = _bpf_cmd_str(cmd)
19 attr_uaddr = pointer_arg(2)
20 size = uint_arg(3)
21 %)
22
23 @define _SYSCALL_BPF_REGARGS_STORE
24 %(
25 if (@probewrite(cmd))
26 set_int_arg(1, cmd)
27
28 if (@probewrite(attr_uaddr))
29 set_pointer_arg(2, attr_uaddr)
30
31 if (@probewrite(size))
32 set_uint_arg(3, size)
33 %)
34
35 probe syscall.bpf = dw_syscall.bpf !, nd_syscall.bpf ? {}
36 probe syscall.bpf.return = dw_syscall.bpf.return !, nd_syscall.bpf.return ? {}
37
38 # dw_bpf _____________________________________________________
39
40 probe dw_syscall.bpf = kernel.function("sys_bpf") ?
41 {
42 @_SYSCALL_BPF_NAME
43 cmd = __int32($cmd)
44 cmd_str = _bpf_cmd_str(cmd)
45 attr_uaddr = $uattr
46 size = __uint32($size)
47 @_SYSCALL_BPF_ARGSTR
48 }
49 probe dw_syscall.bpf.return = kernel.function("sys_bpf").return ?
50 {
51 @_SYSCALL_BPF_NAME
52 @SYSC_RETVALSTR($return)
53 }
54
55 # nd_bpf _____________________________________________________
56
57 probe nd_syscall.bpf = nd1_syscall.bpf!, nd2_syscall.bpf!, tp_syscall.bpf
58 { }
59
60 probe nd1_syscall.bpf = kprobe.function("sys_bpf") ?
61 {
62 @_SYSCALL_BPF_NAME
63 asmlinkage()
64 @_SYSCALL_BPF_REGARGS
65 @_SYSCALL_BPF_ARGSTR
66 }
67
68 /* kernel 4.17+ */
69 probe nd2_syscall.bpf = kprobe.function(@arch_syscall_prefix "sys_bpf") ?
70 {
71 __set_syscall_pt_regs(pointer_arg(1))
72 @_SYSCALL_BPF_NAME
73 @_SYSCALL_BPF_REGARGS
74 @_SYSCALL_BPF_ARGSTR
75 },
76 {
77 %( @_IS_SREG_KERNEL %? @_SYSCALL_BPF_REGARGS_STORE %)
78 }
79
80 /* kernel 3.5+, but undesirable because it affects all syscalls */
81 probe tp_syscall.bpf = kernel.trace("sys_enter")
82 {
83 __set_syscall_pt_regs($regs)
84 @__syscall_compat_gate(@const("__NR_bpf"), @const("__NR_compat_bpf"))
85 @_SYSCALL_BPF_NAME
86 @_SYSCALL_BPF_REGARGS
87 @_SYSCALL_BPF_ARGSTR
88 },
89 {
90 %( @_IS_SREG_KERNEL %? @_SYSCALL_BPF_REGARGS_STORE %)
91 }
92
93 probe nd_syscall.bpf.return = nd1_syscall.bpf.return!, nd2_syscall.bpf.return!, tp_syscall.bpf.return
94 { }
95
96 probe nd1_syscall.bpf.return = kprobe.function("sys_bpf").return ?
97 {
98 @_SYSCALL_BPF_NAME
99 @SYSC_RETVALSTR(returnval())
100 }
101
102 /* kernel 4.17+ */
103 probe nd2_syscall.bpf.return = kprobe.function(@arch_syscall_prefix "sys_bpf").return ?
104 {
105 @_SYSCALL_BPF_NAME
106 @SYSC_RETVALSTR(returnval())
107 }
108
109 /* kernel 3.5+, but undesirable because it affects all syscalls */
110 probe tp_syscall.bpf.return = kernel.trace("sys_exit")
111 {
112 __set_syscall_pt_regs($regs)
113 @__syscall_compat_gate(@const("__NR_bpf"), @const("__NR_compat_bpf"))
114 @_SYSCALL_BPF_NAME
115 @SYSC_RETVALSTR($ret)
116 }