LLVM optimized code loses ctx and confuses verifier
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
Source code is:
``` c
static int in_port(struct __sk_buff *skb) {
int in = skb->ifindex;
if (skb->cb[0])
in = skb->cb[0];
return in;
}
int foo(struct __sk_buff *skb) {
int in = in_port(skb);
return in;
}
```
```
0: (bf) r2 = r1
1: (07) r2 += 40
2: (61) r3 = *(u32 *)(r1 +48)
3: (b7) r4 = 0
4: (1d) if r3 == r4 goto pc+2
R1=ctx R2=inv R3=inv R4=imm0 R10=fp
5: (07) r1 += 48
6: (bf) r2 = r1
7: (61) r0 = *(u32 *)(r2 +0)
R2 invalid mem access 'inv'
```
The issue is clearly that LLVM introduced an optimization that incremented r1 conditionally rather than letting it stay as original r1 value and loading from r1 +40/48. I will investigate which compiler pass moved this value, meanwhile @yonghong-song agreed to look at the verifier side.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.