Commit 81335f90 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

bpf: unconditionally reset backtrack_state masks on global func exit

In mark_chain_precision() logic, when we reach the entry to a global
func, it is expected that R1-R5 might be still requested to be marked
precise. This would correspond to some integer input arguments being
tracked as precise. This is all expected and handled as a special case.

What's not expected is that we'll leave backtrack_state structure with
some register bits set. This is because for subsequent precision
propagations backtrack_state is reused without clearing masks, as all
code paths are carefully written in a way to leave empty backtrack_state
with zeroed out masks, for speed.

The fix is trivial, we always clear register bit in the register mask, and
then, optionally, set reg->precise if register is SCALAR_VALUE type.
Reported-by: default avatarChris Mason <clm@meta.com>
Fixes: be2ef816 ("bpf: allow precision tracking for programs with subprogs")
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230918210110.2241458-1-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent b724a641
...@@ -4047,10 +4047,8 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno) ...@@ -4047,10 +4047,8 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno)
bitmap_from_u64(mask, bt_reg_mask(bt)); bitmap_from_u64(mask, bt_reg_mask(bt));
for_each_set_bit(i, mask, 32) { for_each_set_bit(i, mask, 32) {
reg = &st->frame[0]->regs[i]; reg = &st->frame[0]->regs[i];
if (reg->type != SCALAR_VALUE) {
bt_clear_reg(bt, i); bt_clear_reg(bt, i);
continue; if (reg->type == SCALAR_VALUE)
}
reg->precise = true; reg->precise = true;
} }
return 0; return 0;
......
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