OpenCloudOS-Kernel/kernel/bpf
John Fastabend fb114b1a5f bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds()
commit 294f2fc6da 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>
Signed-off-by: Haisu Wang <haisuwang@tencent.com>
Reviewed-by: Alex Shi <alexsshi@tencent.com>
2024-06-11 20:41:09 +08:00
..
Makefile ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
arraymap.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
bpf_inode_storage.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
bpf_iter.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
bpf_local_storage.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
bpf_lru_list.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
bpf_lru_list.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 206 2019-05-30 11:29:53 -07:00
bpf_lsm.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
bpf_struct_ops.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
bpf_struct_ops_types.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
btf.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
cgroup.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
core.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
cpumap.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
devmap.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
disasm.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
disasm.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 295 2019-06-05 17:36:38 +02:00
dispatcher.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
hashtab.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
helpers.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
inode.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
local_storage.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
lpm_trie.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
map_in_map.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
map_in_map.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 206 2019-05-30 11:29:53 -07:00
map_iter.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
net_namespace.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
offload.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
percpu_freelist.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 206 2019-05-30 11:29:53 -07:00
percpu_freelist.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 206 2019-05-30 11:29:53 -07:00
prog_iter.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
queue_stack_maps.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
reuseport_array.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ringbuf.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
stackmap.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
syscall.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
sysfs_btf.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
task_iter.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
tnum.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
trampoline.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
verifier.c bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds() 2024-06-11 20:41:09 +08:00
xskmap.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00