bpf: fix bug in eBPF verifier
Subsystems (4)
PATCH 1/1 bpf: fix bug in eBPF verifier
while comparing for verifier state equivalency the comparison was missing a check for uninitialized register. Make sure it does so and add a testcase.
---
while we were staring at the verifier code with Hannes during LPC something felt odd in this spot. Yes. It was a bug. Fix it.
kernel/bpf/verifier.c | 3 ++- samples/bpf/test_verifier.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +2 -1
@@ -1409,7 +1409,8 @@ static bool states_equal(struct verifier_state *old, struct verifier_state *cur)if (memcmp (&old->regs[i], &cur->regs[i],sizeof (old->regs[0 ])) !=0 ) {if (old->regs[i].type ==NOT_INIT || - old->regs[i].type ==UNKNOWN_VALUE ) + (old->regs[i].type ==UNKNOWN_VALUE && + cur->regs[i].type !=NOT_INIT ))continue ;return false; }
samples/bpf/test_verifier.c +11 -0
@@ -209,6 +209,17 @@ static struct bpf_test tests[] = { .result = REJECT, }, { + "program doesn't init R0 before exit in all branches", + .insns = { +BPF_JMP_IMM (BPF_JGE ,BPF_REG_1 ,0 ,2 ), +BPF_MOV64_IMM (BPF_REG_0 ,1 ), +BPF_ALU64_IMM (BPF_ADD ,BPF_REG_0 ,2 ), + BPF_EXIT_INSN(), + }, + .errstr ="R0 !read_ok" , + .result = REJECT, + }, + {"stack out of bounds" , .insns = { BPF_ST_MEM(BPF_DW, BPF_REG_10, 8, 0),
Signature · 1 line
1.7.9.5
Quoted 21 lines · Alexei Starovoitov
while comparing for verifier state equivalency the comparison was missing a check for uninitialized register. Make sure it does so and add a testcase.
Fixes f1bca824dabb ("bpf: add search pruning optimization to verifier")Cc Hannes Frederic Sowa <[email protected]>Signed-off-by Alexei Starovoitov <[email protected]>---
while we were staring at the verifier code with Hannes during LPC something felt odd in this spot. Yes. It was a bug. Fix it.
kernel/bpf/verifier.c | 3 ++- samples/bpf/test_verifier.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)kernel/bpf/verifier.c +0
-0
kernel/bpf/verifier.c static bool states_equal(struct verifier_state *old, struct verifier_state *cur) · line 1416
Quoted 9 lines
kernel/bpf/verifier.c +2
-1@@ -1409,7 +1409,8 @@ static bool states_equal(struct verifier_state *old, struct verifier_state *cur)if (memcmp (&old->regs[i], &cur->regs[i],sizeof (old->regs[0 ])) !=0 ) {if (old->regs[i].type ==NOT_INIT || - old->regs[i].type ==UNKNOWN_VALUE ) + (old->regs[i].type ==UNKNOWN_VALUE && + cur->regs[i].type !=NOT_INIT ))continue ;return false; }
That makes sense.
Thanks,
Hannes
From: Alexei Starovoitov <[email protected]>
Date: Mon, 20 Oct 2014 14:54:57 -0700
Quoted 7 lines
while comparing for verifier state equivalency the comparison was missing a check for uninitialized register. Make sure it does so and add a testcase.
Fixes f1bca824dabb ("bpf: add search pruning optimization to verifier")Cc Hannes Frederic Sowa <[email protected]>Signed-off-by Alexei Starovoitov <[email protected]>
Applied, thanks.