return 0;
}
-static void free_verifier_state(struct bpf_verifier_state *state)
+static void free_verifier_state(struct bpf_verifier_state *state,
+ bool free_self)
{
kfree(state->stack);
- kfree(state);
+ if (free_self)
+ kfree(state);
}
/* copy verifier state from src to dst growing dst stack space
if (prev_insn_idx)
*prev_insn_idx = head->prev_insn_idx;
elem = head->next;
+ free_verifier_state(&head->st, false);
kfree(head);
env->head = elem;
env->stack_size--;
if (!elem)
goto err;
- err = copy_verifier_state(&elem->st, cur);
- if (err)
- return NULL;
elem->insn_idx = insn_idx;
elem->prev_insn_idx = prev_insn_idx;
elem->next = env->head;
env->head = elem;
env->stack_size++;
+ err = copy_verifier_state(&elem->st, cur);
+ if (err)
+ goto err;
if (env->stack_size > BPF_COMPLEXITY_LIMIT_STACK) {
verbose("BPF program is too complex\n");
goto err;
struct bpf_verifier_state_list *new_sl;
struct bpf_verifier_state_list *sl;
struct bpf_verifier_state *cur = env->cur_state;
- int i;
+ int i, err;
sl = env->explored_states[insn_idx];
if (!sl)
return -ENOMEM;
/* add new state to the head of linked list */
- copy_verifier_state(&new_sl->state, cur);
+ err = copy_verifier_state(&new_sl->state, cur);
+ if (err) {
+ free_verifier_state(&new_sl->state, false);
+ kfree(new_sl);
+ return err;
+ }
new_sl->next = env->explored_states[insn_idx];
env->explored_states[insn_idx] = new_sl;
/* connect new state to parentage chain */
if (sl)
while (sl != STATE_LIST_MARK) {
sln = sl->next;
+ free_verifier_state(&sl->state, false);
kfree(sl);
sl = sln;
}
env->allow_ptr_leaks = capable(CAP_SYS_ADMIN);
ret = do_check(env);
- free_verifier_state(env->cur_state);
+ free_verifier_state(env->cur_state, true);
env->cur_state = NULL;
skip_full_check:
env->allow_ptr_leaks = capable(CAP_SYS_ADMIN);
ret = do_check(env);
- free_verifier_state(env->cur_state);
+ free_verifier_state(env->cur_state, true);
env->cur_state = NULL;
skip_full_check: