diff options
| author | Anay Wadhera <awadhera@berkeley.edu> | 2021-05-20 21:48:46 -0700 |
|---|---|---|
| committer | Michael Bestas <mkbestas@lineageos.org> | 2022-04-19 00:49:38 +0300 |
| commit | a2b3af0ff2eb372f675f321130358e04f0fab1c3 (patch) | |
| tree | 6675126b37088a17ed26f3ea5b4c8a67c906dc22 | |
| parent | b5829ffaf76fe1841497591172b708fa521ad6b7 (diff) | |
Revert "bpf: Prevent memory disambiguation attack"
This reverts commit 1c74bd22e846b162ea6401e8d43172e0e7256ccf.
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
| -rw-r--r-- | kernel/bpf/verifier.c | 63 |
1 files changed, 4 insertions, 59 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index c43ca9857479..060cb8cba56b 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -191,7 +191,6 @@ struct bpf_insn_aux_data { enum bpf_reg_type ptr_type; /* pointer type for load/store insns */ struct bpf_map *map_ptr; /* pointer for call insn into lookup_elem */ }; - int sanitize_stack_off; /* stack slot to be cleared */ bool seen; /* this insn was processed by the verifier */ }; @@ -570,9 +569,8 @@ static bool is_spillable_regtype(enum bpf_reg_type type) /* check_stack_read/write functions track spill/fill of registers, * stack boundary and alignment are checked in check_mem_access() */ -static int check_stack_write(struct verifier_env *env, - struct verifier_state *state, int off, - int size, int value_regno, int insn_idx) +static int check_stack_write(struct verifier_state *state, int off, int size, + int value_regno) { int i, spi = (MAX_BPF_STACK + off) / BPF_REG_SIZE; /* caller checked that off % size == 0 and -MAX_BPF_STACK <= off < 0, @@ -591,32 +589,8 @@ static int check_stack_write(struct verifier_env *env, /* save register state */ state->spilled_regs[spi] = state->regs[value_regno]; - for (i = 0; i < BPF_REG_SIZE; i++) { - if (state->stack_slot_type[MAX_BPF_STACK + off + i] == STACK_MISC && - !env->allow_ptr_leaks) { - int *poff = &env->insn_aux_data[insn_idx].sanitize_stack_off; - int soff = (-spi - 1) * BPF_REG_SIZE; - - /* detected reuse of integer stack slot with a pointer - * which means either llvm is reusing stack slot or - * an attacker is trying to exploit CVE-2018-3639 - * (speculative store bypass) - * Have to sanitize that slot with preemptive - * store of zero. - */ - if (*poff && *poff != soff) { - /* disallow programs where single insn stores - * into two different stack slots, since verifier - * cannot sanitize them - */ - verbose("insn %d cannot access two stack slots fp%d and fp%d", - insn_idx, *poff, soff); - return -EINVAL; - } - *poff = soff; - } + for (i = 0; i < BPF_REG_SIZE; i++) state->stack_slot_type[MAX_BPF_STACK + off + i] = STACK_SPILL; - } } else { /* regular write of data into stack */ state->spilled_regs[spi] = (struct reg_state) {}; @@ -772,8 +746,7 @@ static int check_mem_access(struct verifier_env *env, int insn_idx, u32 regno, i verbose("attempt to corrupt spilled pointer on stack\n"); return -EACCES; } - err = check_stack_write(env, state, off, size, - value_regno, insn_idx); + err = check_stack_write(state, off, size, value_regno); } else { err = check_stack_read(state, off, size, value_regno); } @@ -2255,34 +2228,6 @@ static int convert_ctx_accesses(struct verifier_env *env) else continue; - if (type == BPF_WRITE && - env->insn_aux_data[i + delta].sanitize_stack_off) { - struct bpf_insn patch[] = { - /* Sanitize suspicious stack slot with zero. - * There are no memory dependencies for this store, - * since it's only using frame pointer and immediate - * constant of zero - */ - BPF_ST_MEM(BPF_DW, BPF_REG_FP, - env->insn_aux_data[i + delta].sanitize_stack_off, - 0), - /* the original STX instruction will immediately - * overwrite the same stack slot with appropriate value - */ - *insn, - }; - - cnt = ARRAY_SIZE(patch); - new_prog = bpf_patch_insn_data(env, i + delta, patch, cnt); - if (!new_prog) - return -ENOMEM; - - delta += cnt - 1; - env->prog = new_prog; - insn = new_prog->insnsi + i + delta; - continue; - } - if (env->insn_aux_data[i + delta].ptr_type != PTR_TO_CTX) continue; |
