Skip to content

Commit 914cb78

Browse files
4astborkmann
authored andcommitted
bpf: cleanup register_is_null()
don't pass large struct bpf_reg_state by value. Instead pass it by pointer. Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: John Fastabend <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 3bf1592 commit 914cb78

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

kernel/bpf/verifier.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,9 @@ static int check_xadd(struct bpf_verifier_env *env, int insn_idx, struct bpf_ins
12651265
}
12661266

12671267
/* Does this register contain a constant zero? */
1268-
static bool register_is_null(struct bpf_reg_state reg)
1268+
static bool register_is_null(struct bpf_reg_state *reg)
12691269
{
1270-
return reg.type == SCALAR_VALUE && tnum_equals_const(reg.var_off, 0);
1270+
return reg->type == SCALAR_VALUE && tnum_equals_const(reg->var_off, 0);
12711271
}
12721272

12731273
/* when register 'regno' is passed into function that will read 'access_size'
@@ -1280,31 +1280,31 @@ static int check_stack_boundary(struct bpf_verifier_env *env, int regno,
12801280
int access_size, bool zero_size_allowed,
12811281
struct bpf_call_arg_meta *meta)
12821282
{
1283+
struct bpf_reg_state *reg = cur_regs(env) + regno;
12831284
struct bpf_verifier_state *state = env->cur_state;
1284-
struct bpf_reg_state *regs = state->regs;
12851285
int off, i, slot, spi;
12861286

1287-
if (regs[regno].type != PTR_TO_STACK) {
1287+
if (reg->type != PTR_TO_STACK) {
12881288
/* Allow zero-byte read from NULL, regardless of pointer type */
12891289
if (zero_size_allowed && access_size == 0 &&
1290-
register_is_null(regs[regno]))
1290+
register_is_null(reg))
12911291
return 0;
12921292

12931293
verbose(env, "R%d type=%s expected=%s\n", regno,
1294-
reg_type_str[regs[regno].type],
1294+
reg_type_str[reg->type],
12951295
reg_type_str[PTR_TO_STACK]);
12961296
return -EACCES;
12971297
}
12981298

12991299
/* Only allow fixed-offset stack reads */
1300-
if (!tnum_is_const(regs[regno].var_off)) {
1300+
if (!tnum_is_const(reg->var_off)) {
13011301
char tn_buf[48];
13021302

1303-
tnum_strn(tn_buf, sizeof(tn_buf), regs[regno].var_off);
1303+
tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
13041304
verbose(env, "invalid variable stack read R%d var_off=%s\n",
13051305
regno, tn_buf);
13061306
}
1307-
off = regs[regno].off + regs[regno].var_off.value;
1307+
off = reg->off + reg->var_off.value;
13081308
if (off >= 0 || off < -MAX_BPF_STACK || off + access_size > 0 ||
13091309
access_size < 0 || (access_size == 0 && !zero_size_allowed)) {
13101310
verbose(env, "invalid stack type R%d off=%d access_size=%d\n",
@@ -1412,7 +1412,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
14121412
* passed in as argument, it's a SCALAR_VALUE type. Final test
14131413
* happens during stack boundary checking.
14141414
*/
1415-
if (register_is_null(*reg) &&
1415+
if (register_is_null(reg) &&
14161416
arg_type == ARG_PTR_TO_MEM_OR_NULL)
14171417
/* final test in check_stack_boundary() */;
14181418
else if (!type_is_pkt_pointer(type) &&

0 commit comments

Comments
 (0)