@@ -5306,7 +5306,7 @@ enum bpf_access_src {
53065306static int check_stack_range_initialized(struct bpf_verifier_env *env,
53075307 int regno, int off, int access_size,
53085308 bool zero_size_allowed,
5309- enum bpf_access_src type,
5309+ enum bpf_access_type type,
53105310 struct bpf_call_arg_meta *meta);
53115311
53125312static struct bpf_reg_state *reg_state(struct bpf_verifier_env *env, int regno)
@@ -5339,7 +5339,7 @@ static int check_stack_read_var_off(struct bpf_verifier_env *env,
53395339 /* Note that we pass a NULL meta, so raw access will not be permitted.
53405340 */
53415341 err = check_stack_range_initialized(env, ptr_regno, off, size,
5342- false, ACCESS_DIRECT , NULL);
5342+ false, BPF_READ , NULL);
53435343 if (err)
53445344 return err;
53455345
@@ -7193,7 +7193,7 @@ static int check_stack_slot_within_bounds(struct bpf_verifier_env *env,
71937193static int check_stack_access_within_bounds(
71947194 struct bpf_verifier_env *env,
71957195 int regno, int off, int access_size,
7196- enum bpf_access_src src, enum bpf_access_type type)
7196+ enum bpf_access_type type)
71977197{
71987198 struct bpf_reg_state *regs = cur_regs(env);
71997199 struct bpf_reg_state *reg = regs + regno;
@@ -7202,10 +7202,7 @@ static int check_stack_access_within_bounds(
72027202 int err;
72037203 char *err_extra;
72047204
7205- if (src == ACCESS_HELPER)
7206- /* We don't know if helpers are reading or writing (or both). */
7207- err_extra = " indirect access to";
7208- else if (type == BPF_READ)
7205+ if (type == BPF_READ)
72097206 err_extra = " read from";
72107207 else
72117208 err_extra = " write to";
@@ -7423,7 +7420,7 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn
74237420
74247421 } else if (reg->type == PTR_TO_STACK) {
74257422 /* Basic bounds checks. */
7426- err = check_stack_access_within_bounds(env, regno, off, size, ACCESS_DIRECT, t);
7423+ err = check_stack_access_within_bounds(env, regno, off, size, t);
74277424 if (err)
74287425 return err;
74297426
@@ -7643,13 +7640,11 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_i
76437640static int check_stack_range_initialized(
76447641 struct bpf_verifier_env *env, int regno, int off,
76457642 int access_size, bool zero_size_allowed,
7646- enum bpf_access_src type, struct bpf_call_arg_meta *meta)
7643+ enum bpf_access_type type, struct bpf_call_arg_meta *meta)
76477644{
76487645 struct bpf_reg_state *reg = reg_state(env, regno);
76497646 struct bpf_func_state *state = func(env, reg);
76507647 int err, min_off, max_off, i, j, slot, spi;
7651- char *err_extra = type == ACCESS_HELPER ? " indirect" : "";
7652- enum bpf_access_type bounds_check_type;
76537648 /* Some accesses can write anything into the stack, others are
76547649 * read-only.
76557650 */
@@ -7660,18 +7655,10 @@ static int check_stack_range_initialized(
76607655 return -EACCES;
76617656 }
76627657
7663- if (type == ACCESS_HELPER) {
7664- /* The bounds checks for writes are more permissive than for
7665- * reads. However, if raw_mode is not set, we'll do extra
7666- * checks below.
7667- */
7668- bounds_check_type = BPF_WRITE;
7658+ if (type == BPF_WRITE)
76697659 clobber = true;
7670- } else {
7671- bounds_check_type = BPF_READ;
7672- }
7673- err = check_stack_access_within_bounds(env, regno, off, access_size,
7674- type, bounds_check_type);
7660+
7661+ err = check_stack_access_within_bounds(env, regno, off, access_size, type);
76757662 if (err)
76767663 return err;
76777664
@@ -7688,8 +7675,8 @@ static int check_stack_range_initialized(
76887675 char tn_buf[48];
76897676
76907677 tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
7691- verbose(env, "R%d%s variable offset stack access prohibited for !root, var_off=%s\n",
7692- regno, err_extra, tn_buf);
7678+ verbose(env, "R%d variable offset stack access prohibited for !root, var_off=%s\n",
7679+ regno, tn_buf);
76937680 return -EACCES;
76947681 }
76957682 /* Only initialized buffer on stack is allowed to be accessed
@@ -7770,14 +7757,14 @@ static int check_stack_range_initialized(
77707757 }
77717758
77727759 if (tnum_is_const(reg->var_off)) {
7773- verbose(env, "invalid%s read from stack R%d off %d+%d size %d\n",
7774- err_extra, regno, min_off, i - min_off, access_size);
7760+ verbose(env, "invalid read from stack R%d off %d+%d size %d\n",
7761+ regno, min_off, i - min_off, access_size);
77757762 } else {
77767763 char tn_buf[48];
77777764
77787765 tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
7779- verbose(env, "invalid%s read from stack R%d var_off %s+%d size %d\n",
7780- err_extra, regno, tn_buf, i - min_off, access_size);
7766+ verbose(env, "invalid read from stack R%d var_off %s+%d size %d\n",
7767+ regno, tn_buf, i - min_off, access_size);
77817768 }
77827769 return -EACCES;
77837770mark:
@@ -7852,7 +7839,7 @@ static int check_helper_mem_access(struct bpf_verifier_env *env, int regno,
78527839 return check_stack_range_initialized(
78537840 env,
78547841 regno, reg->off, access_size,
7855- zero_size_allowed, ACCESS_HELPER , meta);
7842+ zero_size_allowed, access_type , meta);
78567843 case PTR_TO_BTF_ID:
78577844 return check_ptr_to_btf_access(env, regs, regno, reg->off,
78587845 access_size, BPF_READ, -1);
0 commit comments