mint0x33/kernel/bpf
John Fastabend a7cf53f9eb bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds()
commit 294f2fc6da27620a506e6c050241655459ccd6bd upstream.

Currently, for all op verification we call __red_deduce_bounds() and
__red_bound_offset() but we only call __update_reg_bounds() in bitwise
ops. However, we could benefit from calling __update_reg_bounds() in
BPF_ADD, BPF_SUB, and BPF_MUL cases as well.

For example, a register with state 'R1_w=invP0' when we subtract from
it,

 w1 -= 2

Before coerce we will now have an smin_value=S64_MIN, smax_value=U64_MAX
and unsigned bounds umin_value=0, umax_value=U64_MAX. These will then
be clamped to S32_MIN, U32_MAX values by coerce in the case of alu32 op
as done in above example. However tnum will be a constant because the
ALU op is done on a constant.

Without update_reg_bounds() we have a scenario where tnum is a const
but our unsigned bounds do not reflect this. By calling update_reg_bounds
after coerce to 32bit we further refine the umin_value to U64_MAX in the
alu64 case or U32_MAX in the alu32 case above.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/158507151689.15666.566796274289413203.stgit@john-Precision-5820-Tower
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-09-15 12:23:49 +02:00
..
arraymap.c
bpf_lru_list.c bpf_lru_list: Read double-checked variable once without lock 2021-03-03 18:22:39 +01:00
bpf_lru_list.h
cgroup.c
core.c bpf: Make sure mac_header was set before using it 2022-07-29 17:06:51 +02:00
devmap.c
hashtab.c bpf: Remove recursion prevention from rcu free callback 2020-10-01 13:12:35 +02:00
helpers.c
inode.c
lpm_trie.c
Makefile
map_in_map.c
map_in_map.h
percpu_freelist.c
percpu_freelist.h
sockmap.c
stackmap.c bpf: Fix integer overflow in prealloc_elems_and_freelist() 2021-10-17 10:08:32 +02:00
syscall.c bpf: Add kconfig knob for disabling unpriv bpf by default 2022-02-16 12:44:50 +01:00
tnum.c
verifier.c bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds() 2022-09-15 12:23:49 +02:00