bpf/verifier: track liveness for pruning
Subsystems (3)
Hello Edward Cree,
The patch dc503a8ad984: "bpf/verifier: track liveness for pruning" from Aug 15, 2017, leads to the following static checker warning:
kernel/bpf/verifier.c:3463 do_propagate_liveness() error: buffer overflow 'parent->regs' 11 <= 63
kernel/bpf/verifier.c
3435 static bool do_propagate_liveness(const struct bpf_verifier_state *state,
3436 struct bpf_verifier_state *parent)
3437 {
3438 bool touched = false; /* any changes made? */
3439 int i;
3440
3441 if (!parent)
3442 return touched;
3443 /* Propagate read liveness of registers... */
3444 BUILD_BUG_ON(BPF_REG_FP + 1 != MAX_BPF_REG);
3445 /* We don't need to worry about FP liveness because it's read-only */
3446 for (i = 0; i < BPF_REG_FP; i++) {This loop goes from 0-ARRAY_SIZE(state->regs)
3447 if (parent->regs[i].live & REG_LIVE_READ)
3448 continue;
3449 if (state->regs[i].live = REG_LIVE_READ) {
3450 parent->regs[i].live |= REG_LIVE_READ;So it's a more natural place to set parent->regs[i].live.
3451 touched = true;
3452 }
3453 }
3454 /* ... and stack slots */
3455 for (i = 0; i < MAX_BPF_STACK / BPF_REG_SIZE; i++) {This loop is longer.
3456 if (parent->stack_slot_type[i * BPF_REG_SIZE] != STACK_SPILL)
3457 continue;
3458 if (state->stack_slot_type[i * BPF_REG_SIZE] != STACK_SPILL)
3459 continue;
3460 if (parent->spilled_regs[i].live & REG_LIVE_READ)
3461 continue;
3462 if (state->spilled_regs[i].live = REG_LIVE_READ) {
3463 parent->regs[i].live |= REG_LIVE_READ;
^^^^^^^^^^^^^^^^^^^^And causes a static checker warning. Smatch doesn't track arrays well, and I also find it tricky to know if this is a real bug or we always hit a continue or whatever so I'm not sure if this a real bug or not.
3464 touched = true; 3465 } 3466 } 3467 return touched; 3468 }
regards,
dan carpenter
Daniel Borkmann
maintainerQuoted 7 lines · Dan Carpenter
Hello Edward Cree,
The patch
dc503a8ad984: "bpf/verifier: track liveness for pruning" from Aug 15, 2017, leads to the following static checker warning:kernel/bpf/verifier.c:3463 do_propagate_liveness() error: buffer overflow 'parent->regs' 11 <= 63
This should be the below. Will submit a proper one after some tests.
Thanks for spotting!
From 385a1a9f16bf70e0139b38a68252380d6380e003 Mon Sep 17 00:00:00 2001
Message-Id: <385a1a9f16bf70e0139b38a68252380d6380e003.1502971079.git.daniel@iogearbox.net>
From: Daniel Borkmann <[email protected]>
Date: Thu, 17 Aug 2017 13:57:38 +0200
Subject: [PATCH net-next] bpf: fix liveness propagation to parent in stack slots
--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -3460,7 +3460,7 @@ static bool do_propagate_liveness(const struct bpf_verifier_state *state,if (parent->spilled_regs[i].live ®_LIVE_READ )continue ;if (state->spilled_regs[i].live =REG_LIVE_READ ) { - parent->regs[i].live |=REG_LIVE_READ ; + parent->spilled_regs[i].live |=REG_LIVE_READ ; touched = true; } }
Signature · 1 line
1.9.3
Edward Cree
Acked-byQuoted 13 lines · Daniel Borkmann
Quoted 7 lines · Dan Carpenter
Hello Edward Cree,
The patch
dc503a8ad984: "bpf/verifier: track liveness for pruning" from Aug 15, 2017, leads to the following static checker warning:kernel/bpf/verifier.c:3463 do_propagate_liveness() error: buffer overflow 'parent->regs' 11 <= 63This should be the below. Will submit a proper one after some tests.
Thanks for spotting!
Quoted 8 lines
From
385a1a9f16bf70e0139b38a68252380d6380e003Mon Sep 17 00:00:00 2001
Message-Id: <385a1a9f16bf70e0139b38a68252380d6380e003.1502971079.git.daniel@iogearbox.net>
From: Daniel Borkmann <[email protected]>
Date: Thu, 17 Aug 2017 13:57:38 +0200
Subject: [PATCH net-next] bpf: fix liveness propagation to parent in stack slotsReported-by Dan Carpenter <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Quoted 9 lines
--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/verifier.c +0
-0
kernel/bpf/verifier.c static bool do_propagate_liveness(const struct bpf_verifier_state *state, · line 3466
Quoted 8 lines
kernel/bpf/verifier.c +1
-1@@ -3460,7 +3460,7 @@ static bool do_propagate_liveness(const struct bpf_verifier_state *state,if (parent->spilled_regs[i].live ®_LIVE_READ )continue ;if (state->spilled_regs[i].live =REG_LIVE_READ ) { - parent->regs[i].live |=REG_LIVE_READ ; + parent->spilled_regs[i].live |=REG_LIVE_READ ; touched = true; } }
The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.