From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Cong Wang <xiyou.wangcong@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: [PATCH bpf-next v4 01/12] bpf: factor out visit_func_call_insn() in check_cfg()
Date: Thu, 25 Feb 2021 21:13:05 -0800 [thread overview]
Message-ID: <20210226051305.3428292-1-yhs@fb.com> (raw)
In-Reply-To: <20210226051305.3428235-1-yhs@fb.com>
During verifier check_cfg(), all instructions are
visited to ensure verifier can handle program control flows.
This patch factored out function visit_func_call_insn()
so it can be reused in later patch to visit callback function
calls. There is no functionality change for this patch.
Signed-off-by: Yonghong Song <yhs@fb.com>
---
kernel/bpf/verifier.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1dda9d81f12c..9cb182e91162 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -8592,6 +8592,27 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env,
return DONE_EXPLORING;
}
+static int visit_func_call_insn(int t, int insn_cnt,
+ struct bpf_insn *insns,
+ struct bpf_verifier_env *env,
+ bool visit_callee)
+{
+ int ret;
+
+ ret = push_insn(t, t + 1, FALLTHROUGH, env, false);
+ if (ret)
+ return ret;
+
+ if (t + 1 < insn_cnt)
+ init_explored_state(env, t + 1);
+ if (visit_callee) {
+ init_explored_state(env, t);
+ ret = push_insn(t, t + insns[t].imm + 1, BRANCH,
+ env, false);
+ }
+ return ret;
+}
+
/* Visits the instruction at index t and returns one of the following:
* < 0 - an error occurred
* DONE_EXPLORING - the instruction was fully explored
@@ -8612,18 +8633,8 @@ static int visit_insn(int t, int insn_cnt, struct bpf_verifier_env *env)
return DONE_EXPLORING;
case BPF_CALL:
- ret = push_insn(t, t + 1, FALLTHROUGH, env, false);
- if (ret)
- return ret;
-
- if (t + 1 < insn_cnt)
- init_explored_state(env, t + 1);
- if (insns[t].src_reg == BPF_PSEUDO_CALL) {
- init_explored_state(env, t);
- ret = push_insn(t, t + insns[t].imm + 1, BRANCH,
- env, false);
- }
- return ret;
+ return visit_func_call_insn(t, insn_cnt, insns, env,
+ insns[t].src_reg == BPF_PSEUDO_CALL);
case BPF_JA:
if (BPF_SRC(insns[t].code) != BPF_K)
--
2.24.1
next prev parent reply other threads:[~2021-02-26 5:14 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-26 5:13 [PATCH bpf-next v4 00/12] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-26 5:13 ` Yonghong Song [this message]
2021-02-26 19:12 ` [PATCH bpf-next v4 01/12] bpf: factor out visit_func_call_insn() in check_cfg() Andrii Nakryiko
2021-02-26 5:13 ` [PATCH bpf-next v4 02/12] bpf: factor out verbose_invalid_scalar() Yonghong Song
2021-02-26 5:13 ` [PATCH bpf-next v4 03/12] bpf: refactor check_func_call() to allow callback function Yonghong Song
2021-02-26 19:13 ` Andrii Nakryiko
2021-02-26 5:13 ` [PATCH bpf-next v4 04/12] bpf: change return value of verifier function add_subprog() Yonghong Song
2021-02-26 19:14 ` Andrii Nakryiko
2021-02-26 5:13 ` [PATCH bpf-next v4 05/12] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-26 19:22 ` Andrii Nakryiko
2021-02-26 19:27 ` Alexei Starovoitov
2021-02-26 5:13 ` [PATCH bpf-next v4 06/12] bpf: add hashtab support for " Yonghong Song
2021-02-26 5:13 ` [PATCH bpf-next v4 07/12] bpf: add arraymap " Yonghong Song
2021-02-26 5:13 ` [PATCH bpf-next v4 08/12] libbpf: move function is_ldimm64() earlier in libbpf.c Yonghong Song
2021-02-26 5:13 ` [PATCH bpf-next v4 09/12] libbpf: support subprog address relocation Yonghong Song
2021-02-26 5:13 ` [PATCH bpf-next v4 10/12] bpftool: print subprog address properly Yonghong Song
2021-02-26 5:13 ` [PATCH bpf-next v4 11/12] selftests/bpf: add hashmap test for bpf_for_each_map_elem() helper Yonghong Song
2021-02-26 19:17 ` Andrii Nakryiko
2021-02-26 5:13 ` [PATCH bpf-next v4 12/12] selftests/bpf: add arraymap " Yonghong Song
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=20210226051305.3428292-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=xiyou.wangcong@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