提交 32bf08a6 编写于 作者: A Alexei Starovoitov 提交者: David S. Miller

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.

Fixes: f1bca824 ("bpf: add search pruning optimization to verifier")
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
Acked-by: NHannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 78fd1d0a
...@@ -1409,7 +1409,8 @@ static bool states_equal(struct verifier_state *old, struct verifier_state *cur) ...@@ -1409,7 +1409,8 @@ static bool states_equal(struct verifier_state *old, struct verifier_state *cur)
if (memcmp(&old->regs[i], &cur->regs[i], if (memcmp(&old->regs[i], &cur->regs[i],
sizeof(old->regs[0])) != 0) { sizeof(old->regs[0])) != 0) {
if (old->regs[i].type == NOT_INIT || 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; continue;
return false; return false;
} }
......
...@@ -208,6 +208,17 @@ static struct bpf_test tests[] = { ...@@ -208,6 +208,17 @@ static struct bpf_test tests[] = {
.errstr = "R0 !read_ok", .errstr = "R0 !read_ok",
.result = REJECT, .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", "stack out of bounds",
.insns = { .insns = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册