summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorEduard Zingerman <eddyz87@gmail.com>2023-10-24 03:09:12 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-01-31 16:18:58 -0800
commitb8615d7ff2b3d4c3ecd1ed3cd5fd11ba32933501 (patch)
tree4e8d544faebe81749d8936af76e548e5df17caa7 /kernel
parent4c6352f35eb2ef5e01c40cf9fb424948ef49d4e4 (diff)
downloadlinux-stable-b8615d7ff2b3d4c3ecd1ed3cd5fd11ba32933501.tar.gz
linux-stable-b8615d7ff2b3d4c3ecd1ed3cd5fd11ba32933501.tar.bz2
linux-stable-b8615d7ff2b3d4c3ecd1ed3cd5fd11ba32933501.zip
bpf: extract same_callsites() as utility function
commit 4c97259abc9bc8df7712f76f58ce385581876857 upstream. Extract same_callsites() from clean_live_states() as a utility function. This function would be used by the next patch in the set. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/r/20231024000917.12153-3-eddyz87@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/verifier.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 696097877cbf..c1195e7439f5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1799,6 +1799,20 @@ static struct bpf_verifier_state_list **explored_state(struct bpf_verifier_env *
return &env->explored_states[(idx ^ state->callsite) % state_htab_size(env)];
}
+static bool same_callsites(struct bpf_verifier_state *a, struct bpf_verifier_state *b)
+{
+ int fr;
+
+ if (a->curframe != b->curframe)
+ return false;
+
+ for (fr = a->curframe; fr >= 0; fr--)
+ if (a->frame[fr]->callsite != b->frame[fr]->callsite)
+ return false;
+
+ return true;
+}
+
static void update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
{
while (st) {
@@ -15521,18 +15535,14 @@ static void clean_live_states(struct bpf_verifier_env *env, int insn,
struct bpf_verifier_state *cur)
{
struct bpf_verifier_state_list *sl;
- int i;
sl = *explored_state(env, insn);
while (sl) {
if (sl->state.branches)
goto next;
if (sl->state.insn_idx != insn ||
- sl->state.curframe != cur->curframe)
+ !same_callsites(&sl->state, cur))
goto next;
- for (i = 0; i <= cur->curframe; i++)
- if (sl->state.frame[i]->callsite != cur->frame[i]->callsite)
- goto next;
clean_verifier_state(env, &sl->state);
next:
sl = sl->next;