Not sure if this belongs here or in the main aya repo, but I can move it over if needed.
I tried doing something similar to the simple example presented in the README, but the resulting BPF program fails the verifier checks for allegedly not terminating with an exit or jump instruction as follows on Linux 5.14:
Error: the BPF_PROG_LOAD syscall failed. Verifier output: func#0 @0
func#1 @217
func#2 @218
last insn is not an exit or jmp
verification time 3 usec
stack depth 0+0+0
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
Here's my minimal example:
#![no_std]
#![no_main]
use aya_bpf::{helpers::bpf_get_current_pid_tgid, macros::kprobe, programs::ProbeContext};
use aya_log_ebpf::info;
#[kprobe(name = "kprobe_test")]
pub fn kprobe_test(ctx: ProbeContext) -> u32 {
match unsafe { try_kprobe_test(ctx) } {
Ok(ret) => ret,
Err(ret) => ret,
}
}
unsafe fn try_kprobe_test(ctx: ProbeContext) -> Result<u32, u32> {
info!(&ctx, "Hello world");
Ok(0)
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unreachable!()
}
And my relevant configuration:
- Kernel 5.14
- bpf-linker 0.9.2
- rustc 1.56.0-nightly (492723897 2021-07-29)
- aya-log v0.1.1 (https://github.com/aya-rs/aya-log#5aa5eb5b)
- aya-bpf v0.1.0 (http://github.com/aya-rs/aya?branch=main#4152e8b1)
Here's a dump of the generated BPF bytecode with llvm-objdump -S
(seems odd to me since I do see an exit instruction at the end as expected):
0000000000000000 <kprobe_test>:
0: bf 16 00 00 00 00 00 00 r6 = r1
1: b7 09 00 00 00 00 00 00 r9 = 0
2: 63 9a 78 ff 00 00 00 00 *(u32 *)(r10 - 136) = r9
3: bf a2 00 00 00 00 00 00 r2 = r10
4: 07 02 00 00 78 ff ff ff r2 += -136
5: 18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll
7: 85 00 00 00 01 00 00 00 call 1
8: 7b 0a 60 ff 00 00 00 00 *(u64 *)(r10 - 160) = r0
9: 15 00 cd 00 00 00 00 00 if r0 == 0 goto +205 <LBB1_19>
10: 7b 6a 58 ff 00 00 00 00 *(u64 *)(r10 - 168) = r6
11: b7 01 00 00 03 00 00 00 r1 = 3
12: 7b 1a 68 ff 00 00 00 00 *(u64 *)(r10 - 152) = r1
13: b7 02 00 00 1b 00 00 00 r2 = 27
14: 63 2a 74 ff 00 00 00 00 *(u32 *)(r10 - 140) = r2
15: bf a2 00 00 00 00 00 00 r2 = r10
16: 07 02 00 00 74 ff ff ff r2 += -140
17: 7b 2a e0 ff 00 00 00 00 *(u64 *)(r10 - 32) = r2
18: b7 02 00 00 05 00 00 00 r2 = 5
19: 7b 2a f8 ff 00 00 00 00 *(u64 *)(r10 - 8) = r2
20: 7b 2a d8 ff 00 00 00 00 *(u64 *)(r10 - 40) = r2
21: b7 02 00 00 0b 00 00 00 r2 = 11
22: 7b 2a d0 ff 00 00 00 00 *(u64 *)(r10 - 48) = r2
23: 18 02 00 00 33 00 00 00 00 00 00 00 00 00 00 00 r2 = 51 ll
25: 7b 2a c8 ff 00 00 00 00 *(u64 *)(r10 - 56) = r2
26: b7 02 00 00 04 00 00 00 r2 = 4
27: 7b 2a e8 ff 00 00 00 00 *(u64 *)(r10 - 24) = r2
28: 7b 2a c0 ff 00 00 00 00 *(u64 *)(r10 - 64) = r2
29: 7b 1a a8 ff 00 00 00 00 *(u64 *)(r10 - 88) = r1
30: b7 01 00 00 08 00 00 00 r1 = 8
31: 7b 1a a0 ff 00 00 00 00 *(u64 *)(r10 - 96) = r1
32: bf a1 00 00 00 00 00 00 r1 = r10
33: 07 01 00 00 68 ff ff ff r1 += -152
34: 7b 1a 98 ff 00 00 00 00 *(u64 *)(r10 - 104) = r1
35: 18 02 00 00 3e 00 00 00 00 00 00 00 00 00 00 00 r2 = 62 ll
37: 7b 2a b0 ff 00 00 00 00 *(u64 *)(r10 - 80) = r2
38: 7b 2a 80 ff 00 00 00 00 *(u64 *)(r10 - 128) = r2
39: b7 03 00 00 0d 00 00 00 r3 = 13
40: 7b 3a b8 ff 00 00 00 00 *(u64 *)(r10 - 72) = r3
41: 7b 3a 88 ff 00 00 00 00 *(u64 *)(r10 - 120) = r3
42: b7 05 00 00 01 00 00 00 r5 = 1
43: 7b 5a 78 ff 00 00 00 00 *(u64 *)(r10 - 136) = r5
44: b7 06 00 00 02 00 00 00 r6 = 2
45: 7b 6a 90 ff 00 00 00 00 *(u64 *)(r10 - 112) = r6
46: bf a7 00 00 00 00 00 00 r7 = r10
47: 07 07 00 00 a0 ff ff ff r7 += -96
48: 05 00 15 00 00 00 00 00 goto +21 <LBB1_2>
0000000000000188 <LBB1_5>:
49: 07 01 00 00 10 00 00 00 r1 += 16
50: 85 10 00 00 ff ff ff ff call -1
51: 0f 98 00 00 00 00 00 00 r8 += r9
52: 15 06 57 00 06 00 00 00 if r6 == 6 goto +87 <LBB1_13>
53: 7b 6a f0 ff 00 00 00 00 *(u64 *)(r10 - 16) = r6
54: 79 75 f0 ff 00 00 00 00 r5 = *(u64 *)(r7 - 16)
55: 15 05 54 00 07 00 00 00 if r5 == 7 goto +84 <LBB1_13>
56: 07 06 00 00 01 00 00 00 r6 += 1
57: bf 71 00 00 00 00 00 00 r1 = r7
58: 07 01 00 00 18 00 00 00 r1 += 24
59: 79 72 f8 ff 00 00 00 00 r2 = *(u64 *)(r7 - 8)
60: 79 73 00 00 00 00 00 00 r3 = *(u64 *)(r7 + 0)
61: bf 17 00 00 00 00 00 00 r7 = r1
62: bf 89 00 00 00 00 00 00 r9 = r8
63: b7 01 00 00 01 04 00 00 r1 = 1025
64: 2d 81 05 00 00 00 00 00 if r1 > r8 goto +5 <LBB1_2>
65: bf 81 00 00 00 00 00 00 r1 = r8
66: b7 02 00 00 00 04 00 00 r2 = 1024
67: 18 03 00 00 48 00 00 00 00 00 00 00 00 00 00 00 r3 = 72 ll
69: 85 10 00 00 04 00 00 00 call 4
0000000000000230 <LBB1_2>:
70: b7 04 00 00 00 04 00 00 r4 = 1024
71: 1f 94 00 00 00 00 00 00 r4 -= r9
72: bf 38 00 00 00 00 00 00 r8 = r3
73: 07 08 00 00 10 00 00 00 r8 += 16
74: 2d 48 8c 00 00 00 00 00 if r8 > r4 goto +140 <LBB1_19>
75: 79 a1 60 ff 00 00 00 00 r1 = *(u64 *)(r10 - 160)
76: 0f 91 00 00 00 00 00 00 r1 += r9
77: bf 50 00 00 00 00 00 00 r0 = r5
78: 77 00 00 00 38 00 00 00 r0 >>= 56
79: 73 01 07 00 00 00 00 00 *(u8 *)(r1 + 7) = r0
80: bf 50 00 00 00 00 00 00 r0 = r5
81: 77 00 00 00 30 00 00 00 r0 >>= 48
82: 73 01 06 00 00 00 00 00 *(u8 *)(r1 + 6) = r0
83: bf 50 00 00 00 00 00 00 r0 = r5
84: 77 00 00 00 28 00 00 00 r0 >>= 40
85: 73 01 05 00 00 00 00 00 *(u8 *)(r1 + 5) = r0
86: bf 50 00 00 00 00 00 00 r0 = r5
87: 77 00 00 00 20 00 00 00 r0 >>= 32
88: 73 01 04 00 00 00 00 00 *(u8 *)(r1 + 4) = r0
89: bf 50 00 00 00 00 00 00 r0 = r5
90: 77 00 00 00 18 00 00 00 r0 >>= 24
91: 73 01 03 00 00 00 00 00 *(u8 *)(r1 + 3) = r0
92: bf 50 00 00 00 00 00 00 r0 = r5
93: 77 00 00 00 10 00 00 00 r0 >>= 16
94: 73 01 02 00 00 00 00 00 *(u8 *)(r1 + 2) = r0
95: 73 51 00 00 00 00 00 00 *(u8 *)(r1 + 0) = r5
96: 77 05 00 00 08 00 00 00 r5 >>= 8
97: 73 51 01 00 00 00 00 00 *(u8 *)(r1 + 1) = r5
98: b7 05 00 00 f9 03 00 00 r5 = 1017
99: 2d 95 05 00 00 00 00 00 if r5 > r9 goto +5 <LBB1_11>
100: b7 01 00 00 08 00 00 00 r1 = 8
101: bf 42 00 00 00 00 00 00 r2 = r4
102: 18 03 00 00 60 00 00 00 00 00 00 00 00 00 00 00 r3 = 96 ll
104: 85 10 00 00 04 00 00 00 call 4
0000000000000348 <LBB1_11>:
105: bf 34 00 00 00 00 00 00 r4 = r3
106: 77 04 00 00 38 00 00 00 r4 >>= 56
107: 73 41 0f 00 00 00 00 00 *(u8 *)(r1 + 15) = r4
108: bf 34 00 00 00 00 00 00 r4 = r3
109: 77 04 00 00 30 00 00 00 r4 >>= 48
110: 73 41 0e 00 00 00 00 00 *(u8 *)(r1 + 14) = r4
111: bf 34 00 00 00 00 00 00 r4 = r3
112: 77 04 00 00 28 00 00 00 r4 >>= 40
113: 73 41 0d 00 00 00 00 00 *(u8 *)(r1 + 13) = r4
114: bf 34 00 00 00 00 00 00 r4 = r3
115: 77 04 00 00 20 00 00 00 r4 >>= 32
116: 73 41 0c 00 00 00 00 00 *(u8 *)(r1 + 12) = r4
117: bf 34 00 00 00 00 00 00 r4 = r3
118: 77 04 00 00 18 00 00 00 r4 >>= 24
119: 73 41 0b 00 00 00 00 00 *(u8 *)(r1 + 11) = r4
120: bf 34 00 00 00 00 00 00 r4 = r3
121: 77 04 00 00 10 00 00 00 r4 >>= 16
122: 73 41 0a 00 00 00 00 00 *(u8 *)(r1 + 10) = r4
123: 73 31 08 00 00 00 00 00 *(u8 *)(r1 + 8) = r3
124: bf 34 00 00 00 00 00 00 r4 = r3
125: 77 04 00 00 08 00 00 00 r4 >>= 8
126: 73 41 09 00 00 00 00 00 *(u8 *)(r1 + 9) = r4
127: b7 04 00 00 f1 03 00 00 r4 = 1009
128: 2d 94 06 00 00 00 00 00 if r4 > r9 goto +6 <LBB1_3>
129: b7 02 00 00 f8 03 00 00 r2 = 1016
130: 1f 92 00 00 00 00 00 00 r2 -= r9
131: b7 01 00 00 08 00 00 00 r1 = 8
132: 18 03 00 00 78 00 00 00 00 00 00 00 00 00 00 00 r3 = 120 ll
134: 85 10 00 00 04 00 00 00 call 4
0000000000000438 <LBB1_3>:
135: b7 04 00 00 f0 03 00 00 r4 = 1008
136: 1f 94 00 00 00 00 00 00 r4 -= r9
137: 2d 34 a7 ff 00 00 00 00 if r4 > r3 goto -89 <LBB1_5>
138: bf 43 00 00 00 00 00 00 r3 = r4
139: 05 00 a5 ff 00 00 00 00 goto -91 <LBB1_5>
0000000000000460 <LBB1_13>:
140: b7 01 00 00 01 04 00 00 r1 = 1025
141: 2d 81 05 00 00 00 00 00 if r1 > r8 goto +5 <LBB1_15>
142: bf 81 00 00 00 00 00 00 r1 = r8
143: b7 02 00 00 00 04 00 00 r2 = 1024
144: 18 03 00 00 18 00 00 00 00 00 00 00 00 00 00 00 r3 = 24 ll
146: 85 10 00 00 04 00 00 00 call 4
0000000000000498 <LBB1_15>:
147: b7 03 00 00 f0 03 00 00 r3 = 1008
148: 1f 83 00 00 00 00 00 00 r3 -= r8
149: b7 02 00 00 0b 00 00 00 r2 = 11
150: 79 a1 58 ff 00 00 00 00 r1 = *(u64 *)(r10 - 168)
151: 2d 32 3f 00 00 00 00 00 if r2 > r3 goto +63 <LBB1_19>
152: b7 02 00 00 e6 03 00 00 r2 = 998
153: 2d 82 04 00 00 00 00 00 if r2 > r8 goto +4 <LBB1_18>
154: b7 02 00 00 00 04 00 00 r2 = 1024
155: 1f 82 00 00 00 00 00 00 r2 -= r8
156: b7 01 00 00 1b 00 00 00 r1 = 27
157: 85 10 00 00 ff ff ff ff call -1
00000000000004f0 <LBB1_18>:
158: 79 a4 60 ff 00 00 00 00 r4 = *(u64 *)(r10 - 160)
159: bf 45 00 00 00 00 00 00 r5 = r4
160: 0f 85 00 00 00 00 00 00 r5 += r8
161: bf 52 00 00 00 00 00 00 r2 = r5
162: 07 02 00 00 10 00 00 00 r2 += 16
163: 18 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r3 = 0 ll
165: 71 30 00 00 00 00 00 00 r0 = *(u8 *)(r3 + 0)
166: 73 02 00 00 00 00 00 00 *(u8 *)(r2 + 0) = r0
167: 71 30 01 00 00 00 00 00 r0 = *(u8 *)(r3 + 1)
168: 73 02 01 00 00 00 00 00 *(u8 *)(r2 + 1) = r0
169: 71 30 02 00 00 00 00 00 r0 = *(u8 *)(r3 + 2)
170: 73 02 02 00 00 00 00 00 *(u8 *)(r2 + 2) = r0
171: 71 30 03 00 00 00 00 00 r0 = *(u8 *)(r3 + 3)
172: 73 02 03 00 00 00 00 00 *(u8 *)(r2 + 3) = r0
173: 71 30 04 00 00 00 00 00 r0 = *(u8 *)(r3 + 4)
174: 73 02 04 00 00 00 00 00 *(u8 *)(r2 + 4) = r0
175: 71 30 05 00 00 00 00 00 r0 = *(u8 *)(r3 + 5)
176: 73 02 05 00 00 00 00 00 *(u8 *)(r2 + 5) = r0
177: 71 30 06 00 00 00 00 00 r0 = *(u8 *)(r3 + 6)
178: 73 02 06 00 00 00 00 00 *(u8 *)(r2 + 6) = r0
179: 71 30 07 00 00 00 00 00 r0 = *(u8 *)(r3 + 7)
180: 73 02 07 00 00 00 00 00 *(u8 *)(r2 + 7) = r0
181: 71 30 08 00 00 00 00 00 r0 = *(u8 *)(r3 + 8)
182: 73 02 08 00 00 00 00 00 *(u8 *)(r2 + 8) = r0
183: 71 30 09 00 00 00 00 00 r0 = *(u8 *)(r3 + 9)
184: 73 02 09 00 00 00 00 00 *(u8 *)(r2 + 9) = r0
185: 71 30 0a 00 00 00 00 00 r0 = *(u8 *)(r3 + 10)
186: 73 02 0a 00 00 00 00 00 *(u8 *)(r2 + 10) = r0
187: bf 42 00 00 00 00 00 00 r2 = r4
188: 0f 82 00 00 00 00 00 00 r2 += r8
189: b7 03 00 00 06 00 00 00 r3 = 6
190: 73 32 00 00 00 00 00 00 *(u8 *)(r2 + 0) = r3
191: b7 03 00 00 00 00 00 00 r3 = 0
192: 73 32 07 00 00 00 00 00 *(u8 *)(r2 + 7) = r3
193: 73 32 06 00 00 00 00 00 *(u8 *)(r2 + 6) = r3
194: 73 32 05 00 00 00 00 00 *(u8 *)(r2 + 5) = r3
195: 73 32 04 00 00 00 00 00 *(u8 *)(r2 + 4) = r3
196: 73 32 03 00 00 00 00 00 *(u8 *)(r2 + 3) = r3
197: 73 32 02 00 00 00 00 00 *(u8 *)(r2 + 2) = r3
198: 73 32 01 00 00 00 00 00 *(u8 *)(r2 + 1) = r3
199: b7 02 00 00 0b 00 00 00 r2 = 11
200: 73 25 08 00 00 00 00 00 *(u8 *)(r5 + 8) = r2
201: 73 35 0e 00 00 00 00 00 *(u8 *)(r5 + 14) = r3
202: 73 35 0f 00 00 00 00 00 *(u8 *)(r5 + 15) = r3
203: 73 35 0c 00 00 00 00 00 *(u8 *)(r5 + 12) = r3
204: 73 35 0d 00 00 00 00 00 *(u8 *)(r5 + 13) = r3
205: 73 35 0a 00 00 00 00 00 *(u8 *)(r5 + 10) = r3
206: 73 35 0b 00 00 00 00 00 *(u8 *)(r5 + 11) = r3
207: 73 35 09 00 00 00 00 00 *(u8 *)(r5 + 9) = r3
208: 07 08 00 00 1b 00 00 00 r8 += 27
209: 18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
211: 18 03 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 r3 = 4294967295 ll
213: bf 85 00 00 00 00 00 00 r5 = r8
214: 85 00 00 00 19 00 00 00 call 25
00000000000006b8 <LBB1_19>:
215: b7 00 00 00 00 00 00 00 r0 = 0
216: 95 00 00 00 00 00 00 00 exit