Skip to content

Commit 4e2c7b2

Browse files
borkmanngregkh
authored andcommitted
bpf: Wrap aux data inside bpf_sanitize_info container
commit 3d0220f upstream. Add a container structure struct bpf_sanitize_info which holds the current aux info, and update call-sites to sanitize_ptr_alu() to pass it in. This is needed for passing in additional state later on. Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Piotr Krysiuk <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4068786 commit 4e2c7b2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

kernel/bpf/verifier.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5743,15 +5743,19 @@ static bool sanitize_needed(u8 opcode)
57435743
return opcode == BPF_ADD || opcode == BPF_SUB;
57445744
}
57455745

5746+
struct bpf_sanitize_info {
5747+
struct bpf_insn_aux_data aux;
5748+
};
5749+
57465750
static int sanitize_ptr_alu(struct bpf_verifier_env *env,
57475751
struct bpf_insn *insn,
57485752
const struct bpf_reg_state *ptr_reg,
57495753
const struct bpf_reg_state *off_reg,
57505754
struct bpf_reg_state *dst_reg,
5751-
struct bpf_insn_aux_data *tmp_aux,
5755+
struct bpf_sanitize_info *info,
57525756
const bool commit_window)
57535757
{
5754-
struct bpf_insn_aux_data *aux = commit_window ? cur_aux(env) : tmp_aux;
5758+
struct bpf_insn_aux_data *aux = commit_window ? cur_aux(env) : &info->aux;
57555759
struct bpf_verifier_state *vstate = env->cur_state;
57565760
bool off_is_imm = tnum_is_const(off_reg->var_off);
57575761
bool off_is_neg = off_reg->smin_value < 0;
@@ -5780,8 +5784,8 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
57805784
/* In commit phase we narrow the masking window based on
57815785
* the observed pointer move after the simulated operation.
57825786
*/
5783-
alu_state = tmp_aux->alu_state;
5784-
alu_limit = abs(tmp_aux->alu_limit - alu_limit);
5787+
alu_state = info->aux.alu_state;
5788+
alu_limit = abs(info->aux.alu_limit - alu_limit);
57855789
} else {
57865790
alu_state = off_is_neg ? BPF_ALU_NEG_VALUE : 0;
57875791
alu_state |= off_is_imm ? BPF_ALU_IMMEDIATE : 0;
@@ -5942,7 +5946,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
59425946
smin_ptr = ptr_reg->smin_value, smax_ptr = ptr_reg->smax_value;
59435947
u64 umin_val = off_reg->umin_value, umax_val = off_reg->umax_value,
59445948
umin_ptr = ptr_reg->umin_value, umax_ptr = ptr_reg->umax_value;
5945-
struct bpf_insn_aux_data tmp_aux = {};
5949+
struct bpf_sanitize_info info = {};
59465950
u8 opcode = BPF_OP(insn->code);
59475951
u32 dst = insn->dst_reg;
59485952
int ret;
@@ -6011,7 +6015,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
60116015

60126016
if (sanitize_needed(opcode)) {
60136017
ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg,
6014-
&tmp_aux, false);
6018+
&info, false);
60156019
if (ret < 0)
60166020
return sanitize_err(env, insn, ret, off_reg, dst_reg);
60176021
}
@@ -6152,7 +6156,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
61526156
return -EACCES;
61536157
if (sanitize_needed(opcode)) {
61546158
ret = sanitize_ptr_alu(env, insn, dst_reg, off_reg, dst_reg,
6155-
&tmp_aux, true);
6159+
&info, true);
61566160
if (ret < 0)
61576161
return sanitize_err(env, insn, ret, off_reg, dst_reg);
61586162
}

0 commit comments

Comments
 (0)