OSDN Git Service

bpf: Check the other end of slot_type for STACK_SPILL
authorMartin KaFai Lau <kafai@fb.com>
Wed, 22 Sep 2021 00:49:34 +0000 (17:49 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 26 Sep 2021 20:07:27 +0000 (13:07 -0700)
commit27113c59b6d0a587b29ae72d4ff3f832f58b0651
tree8b6acdc79afdcd72ac7d406dc6313978f3f3f84b
parent091037fb770e1771a52246f9b68dc76082178a3c
bpf: Check the other end of slot_type for STACK_SPILL

Every 8 bytes of the stack is tracked by a bpf_stack_state.
Within each bpf_stack_state, there is a 'u8 slot_type[8]' to track
the type of each byte.  Verifier tests slot_type[0] == STACK_SPILL
to decide if the spilled reg state is saved.  Verifier currently only
saves the reg state if the whole 8 bytes are spilled to the stack,
so checking the slot_type[7] is the same as checking slot_type[0].

The later patch will allow verifier to save the bounded scalar
reg also for <8 bytes spill.  There is a llvm patch [1] to ensure
the <8 bytes spill will be 8-byte aligned,  so checking
slot_type[7] instead of slot_type[0] is required.

While at it, this patch refactors the slot_type[0] == STACK_SPILL
test into a new function is_spilled_reg() and change the
slot_type[0] check to slot_type[7] check in there also.

[1] https://reviews.llvm.org/D109073

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210922004934.624194-1-kafai@fb.com
kernel/bpf/verifier.c