Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0082674

Browse files
shiloongmaqiao-mq
authored andcommitted
Revert "bpf: Fix pointer arithmetic mask tightening under state pruning"
ANBZ: torvalds#342 This reverts commit a4409d1. Signed-off-by: Qiao Ma <[email protected]> Acked-by: Mao Wenan <[email protected]> Acked-by: Tony Lu <[email protected]>
1 parent f3e93a7 commit 0082674

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

include/linux/bpf_verifier.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ struct bpf_verifier_env {
215215
struct bpf_map *used_maps[MAX_USED_MAPS]; /* array of map's used by eBPF program */
216216
u32 used_map_cnt; /* number of used maps */
217217
u32 id_gen; /* used to generate unique reg IDs */
218-
bool explore_alu_limits;
219218
bool allow_ptr_leaks;
220219
bool seen_direct_write;
221220
struct bpf_insn_aux_data *insn_aux_data; /* array of per-insn state */

kernel/bpf/verifier.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,12 +2848,6 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
28482848
alu_state |= off_is_imm ? BPF_ALU_IMMEDIATE : 0;
28492849
alu_state |= ptr_is_dst_reg ?
28502850
BPF_ALU_SANITIZE_SRC : BPF_ALU_SANITIZE_DST;
2851-
2852-
/* Limit pruning on unknown scalars to enable deep search for
2853-
* potential masking differences from other program paths.
2854-
*/
2855-
if (!off_is_imm)
2856-
env->explore_alu_limits = true;
28572851
}
28582852

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

47864780
/* Returns true if (rold safe implies rcur safe) */
4787-
static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
4788-
struct bpf_reg_state *rcur, struct bpf_id_pair *idmap)
4781+
static bool regsafe(struct bpf_reg_state *rold, struct bpf_reg_state *rcur,
4782+
struct bpf_id_pair *idmap)
47894783
{
47904784
bool equal;
47914785

@@ -4811,8 +4805,6 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
48114805
return false;
48124806
switch (rold->type) {
48134807
case SCALAR_VALUE:
4814-
if (env->explore_alu_limits)
4815-
return false;
48164808
if (rcur->type == SCALAR_VALUE) {
48174809
/* new val must satisfy old val knowledge */
48184810
return range_within(rold, rcur) &&
@@ -4889,8 +4881,9 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
48894881
return false;
48904882
}
48914883

4892-
static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,
4893-
struct bpf_func_state *cur, struct bpf_id_pair *idmap)
4884+
static bool stacksafe(struct bpf_func_state *old,
4885+
struct bpf_func_state *cur,
4886+
struct bpf_id_pair *idmap)
48944887
{
48954888
int i, spi;
48964889

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

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

4989-
if (!stacksafe(env, old, cur, env->idmap_scratch))
4982+
if (!stacksafe(old, cur, env->idmap_scratch))
49904983
return false;
49914984

49924985
return true;

0 commit comments

Comments
 (0)