bpf: Ensure precise is reset to false in __mark_reg_const_zero()
authorAndrii Nakryiko <andrii@kernel.org>
Mon, 18 Dec 2023 17:36:01 +0000 (09:36 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 18 Dec 2023 22:54:21 +0000 (23:54 +0100)
commit8e432e6197cef6250dfd6fdffd41c06613c874ca
tree441e472f39005b2d9a16b69dba9b6b40d726f322
parent6079ae6376181b49c9e4d65ef9fe954cca4974bd
bpf: Ensure precise is reset to false in __mark_reg_const_zero()

It is safe to always start with imprecise SCALAR_VALUE register.
Previously __mark_reg_const_zero() relied on caller to reset precise
mark, but it's very error prone and we already missed it in a few
places. So instead make __mark_reg_const_zero() reset precision always,
as it's a safe default for SCALAR_VALUE. Explanation is basically the
same as for why we are resetting (or rather not setting) precision in
current state. If necessary, precision propagation will set it to
precise correctly.

As such, also remove a big comment about forward precision propagation
in mark_reg_stack_read() and avoid unnecessarily setting precision to
true after reading from STACK_ZERO stack. Again, precision propagation
will correctly handle this, if that SCALAR_VALUE register will ever be
needed to be precise.

Reported-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Acked-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20231218173601.53047-1-andrii@kernel.org
kernel/bpf/verifier.c
tools/testing/selftests/bpf/progs/verifier_spill_fill.c