Commit 8ce36463 authored by Ben Hutchings's avatar Ben Hutchings Committed by Juerg Haefliger

bpf/verifier: Add spi variable to check_stack_write()

BugLink: https://bugs.launchpad.net/bugs/1811080

Extracted from commit dc503a8a "bpf/verifier: track liveness for
pruning".

Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent 0fb92f9c
...@@ -588,7 +588,7 @@ static bool is_spillable_regtype(enum bpf_reg_type type) ...@@ -588,7 +588,7 @@ static bool is_spillable_regtype(enum bpf_reg_type type)
static int check_stack_write(struct verifier_state *state, int off, int size, static int check_stack_write(struct verifier_state *state, int off, int size,
int value_regno) int value_regno)
{ {
int i; int i, spi = (MAX_BPF_STACK + off) / BPF_REG_SIZE;
/* caller checked that off % size == 0 and -MAX_BPF_STACK <= off < 0, /* caller checked that off % size == 0 and -MAX_BPF_STACK <= off < 0,
* so it's aligned access and [off, off + size) are within stack limits * so it's aligned access and [off, off + size) are within stack limits
*/ */
...@@ -603,15 +603,13 @@ static int check_stack_write(struct verifier_state *state, int off, int size, ...@@ -603,15 +603,13 @@ static int check_stack_write(struct verifier_state *state, int off, int size,
} }
/* save register state */ /* save register state */
state->spilled_regs[(MAX_BPF_STACK + off) / BPF_REG_SIZE] = state->spilled_regs[spi] = state->regs[value_regno];
state->regs[value_regno];
for (i = 0; i < BPF_REG_SIZE; i++) for (i = 0; i < BPF_REG_SIZE; i++)
state->stack_slot_type[MAX_BPF_STACK + off + i] = STACK_SPILL; state->stack_slot_type[MAX_BPF_STACK + off + i] = STACK_SPILL;
} else { } else {
/* regular write of data into stack */ /* regular write of data into stack */
state->spilled_regs[(MAX_BPF_STACK + off) / BPF_REG_SIZE] = state->spilled_regs[spi] = (struct reg_state) {};
(struct reg_state) {};
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
state->stack_slot_type[MAX_BPF_STACK + off + i] = STACK_MISC; state->stack_slot_type[MAX_BPF_STACK + off + i] = STACK_MISC;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment