This is a note to let you know that I've just added the patch titled bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds() to the 4.19-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: bpf-verifer-adjust_scalar_min_max_vals-to-always-call-update_reg_bounds.patch and it can be found in the queue-4.19 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Sat Aug 13 03:11:42 PM CEST 2022 From: Ovidiu Panait <ovidiu.panait@xxxxxxxxxxxxx> Date: Tue, 9 Aug 2022 10:39:45 +0300 Subject: bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds() To: stable@xxxxxxxxxxxxxxx Cc: John Fastabend <john.fastabend@xxxxxxxxx>, Alexei Starovoitov <ast@xxxxxxxxxx>, Ovidiu Panait <ovidiu.panait@xxxxxxxxxxxxx> Message-ID: <20220809073947.33804-3-ovidiu.panait@xxxxxxxxxxxxx> From: Ovidiu Panait <ovidiu.panait@xxxxxxxxxxxxx> From: John Fastabend <john.fastabend@xxxxxxxxx> 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@xxxxxxxxx> Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> Link: https://lore.kernel.org/bpf/158507151689.15666.566796274289413203.stgit@john-Precision-5820-Tower Signed-off-by: Ovidiu Panait <ovidiu.panait@xxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -3496,6 +3496,7 @@ static int adjust_scalar_min_max_vals(st coerce_reg_to_size(dst_reg, 4); } + __update_reg_bounds(dst_reg); __reg_deduce_bounds(dst_reg); __reg_bound_offset(dst_reg); return 0; Patches currently in stable-queue which might be from ovidiu.panait@xxxxxxxxxxxxx are queue-4.19/bpf-verifer-adjust_scalar_min_max_vals-to-always-call-update_reg_bounds.patch queue-4.19/selftests-bpf-fix-dubious-pointer-arithmetic-test.patch queue-4.19/selftests-bpf-fix-test_align-verifier-log-patterns.patch