Skip to content

Commit c04c0d2

Browse files
Alexei Starovoitovborkmann
Alexei Starovoitov
authored andcommitted
bpf: increase complexity limit and maximum program size
Large verifier speed improvements allow to increase verifier complexity limit. Now regardless of the program composition and its size it takes little time for the verifier to hit insn_processed limit. On typical x86 machine non-debug kernel processes 1M instructions in 1/10 of a second. (before these speed improvements specially crafted programs could be hitting multi-second verification times) Full kasan kernel with debug takes ~1 second for the same 1M insns. Hence bump the BPF_COMPLEXITY_LIMIT_INSNS limit to 1M. Also increase the number of instructions per program from 4k to internal BPF_COMPLEXITY_LIMIT_INSNS limit. 4k limit was confusing to users, since small programs with hundreds of insns could be hitting BPF_COMPLEXITY_LIMIT_INSNS limit. Sometimes adding more insns and bpf_trace_printk debug statements would make the verifier accept the program while removing code would make the verifier reject it. Some user space application started to add #define MAX_FOO to their programs and do: MAX_FOO=100; again: compile with MAX_FOO; try to load; if (fails_to_load) { reduce MAX_FOO; goto again; } to be able to fit maximum amount of processing into single program. Other users artificially split their single program into a set of programs and use all 32 iterations of tail_calls to increase compute limits. And the most advanced folks used unlimited tc-bpf filter list to execute many bpf programs. Essentially the users managed to workaround 4k insn limit. This patch removes the limit for root programs from uapi. BPF_COMPLEXITY_LIMIT_INSNS is the kernel internal limit and success to load the program no longer depends on program size, but on 'smartness' of the verifier only. The verifier will continue to get smarter with every kernel release. Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 4f73379 commit c04c0d2

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

include/linux/bpf.h

+1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ struct bpf_array {
421421
};
422422
};
423423

424+
#define BPF_COMPLEXITY_LIMIT_INSNS 1000000 /* yes. 1M insns */
424425
#define MAX_TAIL_CALL_CNT 32
425426

426427
struct bpf_event_entry {

kernel/bpf/syscall.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,8 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr)
15571557
/* eBPF programs must be GPL compatible to use GPL-ed functions */
15581558
is_gpl = license_is_gpl_compatible(license);
15591559

1560-
if (attr->insn_cnt == 0 || attr->insn_cnt > BPF_MAXINSNS)
1560+
if (attr->insn_cnt == 0 ||
1561+
attr->insn_cnt > (capable(CAP_SYS_ADMIN) ? BPF_COMPLEXITY_LIMIT_INSNS : BPF_MAXINSNS))
15611562
return -E2BIG;
15621563
if (type != BPF_PROG_TYPE_SOCKET_FILTER &&
15631564
type != BPF_PROG_TYPE_CGROUP_SKB &&

kernel/bpf/verifier.c

-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ struct bpf_verifier_stack_elem {
176176
struct bpf_verifier_stack_elem *next;
177177
};
178178

179-
#define BPF_COMPLEXITY_LIMIT_INSNS 131072
180179
#define BPF_COMPLEXITY_LIMIT_STACK 1024
181180
#define BPF_COMPLEXITY_LIMIT_STATES 64
182181

0 commit comments

Comments
 (0)