From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [bug report] bpf/verifier: track liveness for pruning
Date: Thu, 17 Aug 2017 07:44:16 +0000 [thread overview]
Message-ID: <20170817074415.s24acvnsrask6ue2@mwanda> (raw)
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
next reply other threads:[~2017-08-17 7:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-17 7:44 Dan Carpenter [this message]
2017-08-17 12:00 ` [bug report] bpf/verifier: track liveness for pruning Daniel Borkmann
2017-08-17 12:53 ` Edward Cree
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170817074415.s24acvnsrask6ue2@mwanda \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox