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 v4 1/3] bpf: add some comments to stack representation
Date: Thu, 7 Dec 2023 21:31:48 -0500 [thread overview]
Message-ID: <20231208023150.254207-2-andreimatei1@gmail.com> (raw)
In-Reply-To: <20231208023150.254207-1-andreimatei1@gmail.com>
Add comments to the datastructure tracking the stack state, as the
mapping between each stack slot and where its state is stored is not
entirely obvious.
Signed-off-by: Andrei Matei <andreimatei1@gmail.com>
---
include/linux/bpf_verifier.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index aa4d19d0bc94..6cf64338e978 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -316,7 +316,17 @@ struct bpf_func_state {
/* The following fields should be last. See copy_func_state() */
int acquired_refs;
struct bpf_reference_state *refs;
+ /* Size of the current stack, in bytes. The stack state is tracked below, in
+ * `stack`. allocated_stack is always a multiple of BPF_REG_SIZE.
+ */
int allocated_stack;
+ /* The state of the stack. Each element of the array describes BPF_REG_SIZE
+ * (i.e. 8) bytes worth of stack memory.
+ * stack[0] represents bytes [*(r10-8)..*(r10-1)]
+ * stack[1] represents bytes [*(r10-16)..*(r10-9)]
+ * ...
+ * stack[allocated_stack/8 - 1] represents [*(r10-allocated_stack)..*(r10-allocated_stack+7)]
+ */
struct bpf_stack_state *stack;
};
@@ -630,6 +640,10 @@ struct bpf_verifier_env {
int exception_callback_subprog;
bool explore_alu_limits;
bool allow_ptr_leaks;
+ /* Allow access to uninitialized stack memory. Writes with fixed offset are
+ * always allowed, so this refers to reads (with fixed or variable offset),
+ * to writes with variable offset and to indirect (helper) accesses.
+ */
bool allow_uninit_stack;
bool bpf_capable;
bool bypass_spec_v1;
--
2.40.1
next prev parent reply other threads:[~2023-12-08 2:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 2:31 [PATCH bpf v4 0/3] bpf: fix accesses to uninit stack slots Andrei Matei
2023-12-08 2:31 ` Andrei Matei [this message]
2023-12-08 2:31 ` [PATCH bpf v4 2/3] " Andrei Matei
2023-12-08 2:31 ` [PATCH bpf v4 3/3] bpf: minor cleanup around stack bounds Andrei Matei
2023-12-08 2:45 ` [PATCH bpf v4 0/3] bpf: fix accesses to uninit stack slots Andrei Matei
2023-12-08 2:50 ` Alexei Starovoitov
2023-12-08 3:01 ` Andrei Matei
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=20231208023150.254207-2-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