From: Andrei Matei <andreimatei1@gmail.com>
To: bpf@vger.kernel.org
Cc: sunhao.th@gmail.com, andrii.nakryiko@gmail.com,
eddyz87@gmail.com, Andrei Matei <andreimatei1@gmail.com>
Subject: [PATCH bpf-next v5 3/3] bpf: minor cleanup around stack bounds
Date: Thu, 7 Dec 2023 22:25:19 -0500 [thread overview]
Message-ID: <20231208032519.260451-4-andreimatei1@gmail.com> (raw)
In-Reply-To: <20231208032519.260451-1-andreimatei1@gmail.com>
Push the rounding up of stack offsets into the function responsible for
growing the stack, rather than relying on all the callers to do it.
Uncertainty about whether the callers did it or not tripped up people in
a previous review.
Signed-off-by: Andrei Matei <andreimatei1@gmail.com>
---
kernel/bpf/verifier.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index de1e29fa467e..fb690539d5f6 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1264,7 +1264,11 @@ static int resize_reference_state(struct bpf_func_state *state, size_t n)
*/
static int grow_stack_state(struct bpf_verifier_env *env, struct bpf_func_state *state, int size)
{
- size_t old_n = state->allocated_stack / BPF_REG_SIZE, n = size / BPF_REG_SIZE;
+ size_t old_n = state->allocated_stack / BPF_REG_SIZE, n;
+
+ /* The stack size is always a multiple of BPF_REG_SIZE. */
+ size = round_up(size, BPF_REG_SIZE);
+ n = size / BPF_REG_SIZE;
if (old_n >= n)
return 0;
@@ -6638,7 +6642,10 @@ static int check_stack_access_within_bounds(
return err;
}
- return grow_stack_state(env, state, round_up(-min_off, BPF_REG_SIZE));
+ /* Note that there is no stack access with offset zero, so the needed stack
+ * size is -min_off, not -min_off+1.
+ */
+ return grow_stack_state(env, state, -min_off /* size */);
}
/* check whether memory at (regno + off) is accessible for t = (read | write)
--
2.40.1
next prev parent reply other threads:[~2023-12-08 3:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 3:25 [PATCH bpf v5 0/3] bpf: fix accesses to uninit stack slots Andrei Matei
2023-12-08 3:25 ` [PATCH bpf-next v5 1/3] bpf: add some comments to stack representation Andrei Matei
2023-12-08 21:06 ` Eduard Zingerman
2023-12-08 3:25 ` [PATCH bpf-next v5 2/3] bpf: fix accesses to uninit stack slots Andrei Matei
2023-12-08 3:25 ` Andrei Matei [this message]
2023-12-08 21:10 ` [PATCH bpf-next v5 3/3] bpf: minor cleanup around stack bounds Eduard Zingerman
2023-12-08 23:10 ` [PATCH bpf v5 0/3] bpf: fix accesses to uninit stack slots patchwork-bot+netdevbpf
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=20231208032519.260451-4-andreimatei1@gmail.com \
--to=andreimatei1@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=sunhao.th@gmail.com \
/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