Skip to content

Commit

Permalink
Revert "bpf: Fix pointer arithmetic mask tightening under state pruning"
Browse files Browse the repository at this point in the history
ANBZ: torvalds#342

This reverts commit a4409d1.

Signed-off-by: Qiao Ma <mqaio@linux.alibaba.com>
Acked-by: Mao Wenan <wenan.mao@linux.alibaba.com>
Acked-by: Tony Lu <tonylu@linux.alibaba.com>
  • Loading branch information
shiloong authored and maqiao-mq committed Apr 20, 2022
1 parent f3e93a7 commit 0082674
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
1 change: 0 additions & 1 deletion include/linux/bpf_verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ struct bpf_verifier_env {
struct bpf_map *used_maps[MAX_USED_MAPS]; /* array of map's used by eBPF program */
u32 used_map_cnt; /* number of used maps */
u32 id_gen; /* used to generate unique reg IDs */
bool explore_alu_limits;
bool allow_ptr_leaks;
bool seen_direct_write;
struct bpf_insn_aux_data *insn_aux_data; /* array of per-insn state */
Expand Down
27 changes: 10 additions & 17 deletions kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -2848,12 +2848,6 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
alu_state |= off_is_imm ? BPF_ALU_IMMEDIATE : 0;
alu_state |= ptr_is_dst_reg ?
BPF_ALU_SANITIZE_SRC : BPF_ALU_SANITIZE_DST;

/* Limit pruning on unknown scalars to enable deep search for
* potential masking differences from other program paths.
*/
if (!off_is_imm)
env->explore_alu_limits = true;
}

err = update_alu_sanitation_state(aux, alu_state, alu_limit);
Expand Down Expand Up @@ -4784,8 +4778,8 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_id_pair *idmap)
}

/* Returns true if (rold safe implies rcur safe) */
static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
struct bpf_reg_state *rcur, struct bpf_id_pair *idmap)
static bool regsafe(struct bpf_reg_state *rold, struct bpf_reg_state *rcur,
struct bpf_id_pair *idmap)
{
bool equal;

Expand All @@ -4811,8 +4805,6 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
return false;
switch (rold->type) {
case SCALAR_VALUE:
if (env->explore_alu_limits)
return false;
if (rcur->type == SCALAR_VALUE) {
/* new val must satisfy old val knowledge */
return range_within(rold, rcur) &&
Expand Down Expand Up @@ -4889,8 +4881,9 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
return false;
}

static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,
struct bpf_func_state *cur, struct bpf_id_pair *idmap)
static bool stacksafe(struct bpf_func_state *old,
struct bpf_func_state *cur,
struct bpf_id_pair *idmap)
{
int i, spi;

Expand Down Expand Up @@ -4932,8 +4925,9 @@ static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,
continue;
if (old->stack[spi].slot_type[0] != STACK_SPILL)
continue;
if (!regsafe(env, &old->stack[spi].spilled_ptr,
&cur->stack[spi].spilled_ptr, idmap))
if (!regsafe(&old->stack[spi].spilled_ptr,
&cur->stack[spi].spilled_ptr,
idmap))
/* when explored and current stack slot are both storing
* spilled registers, check that stored pointers types
* are the same as well.
Expand Down Expand Up @@ -4982,11 +4976,10 @@ static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_stat

memset(env->idmap_scratch, 0, sizeof(env->idmap_scratch));
for (i = 0; i < MAX_BPF_REG; i++)
if (!regsafe(env, &old->regs[i], &cur->regs[i],
env->idmap_scratch))
if (!regsafe(&old->regs[i], &cur->regs[i], env->idmap_scratch))
return false;

if (!stacksafe(env, old, cur, env->idmap_scratch))
if (!stacksafe(old, cur, env->idmap_scratch))
return false;

return true;
Expand Down

0 comments on commit 0082674

Please sign in to comment.