On Wed, Apr 24, 2024 at 3:41 PM Cupertino Miranda <cupertino.miranda@xxxxxxxxxx> wrote: > > MUL instruction required that src_reg would be a known value (i.e. > src_reg would be a const value). The condition in this case can be > relaxed, since the range computation algorithm used in current code > already supports a proper range computation for any valid range value on > its operands. > > Signed-off-by: Cupertino Miranda <cupertino.miranda@xxxxxxxxxx> > Cc: Yonghong Song <yonghong.song@xxxxxxxxx> > Cc: Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> > Cc: David Faust <david.faust@xxxxxxxxxx> > Cc: Jose Marchesi <jose.marchesi@xxxxxxxxxx> > Cc: Elena Zannoni <elena.zannoni@xxxxxxxxxx> > --- > kernel/bpf/verifier.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 6f956c0936d0..760193dac85e 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -13749,12 +13749,8 @@ static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, > case BPF_AND: > case BPF_XOR: > case BPF_OR: > - return true; > - > - /* Compute range for the following only if the src_reg is known. > - */ > case BPF_MUL: > - return src_known; > + return true; > scalar_min_max_mul() and scalar32_min_max_mul() could be implemented just a touch smarter without becoming non-obvious. E.g., we pessimistically limit both arguments to U16_MAX, but really we care about their multiplication not overflowing U32_MAX, which can be checked very easily (just multiply two max values and check they are still < U32_MAX; similar checks could be done for 64-bit case). All this is still trivially provable because we restrict arguments to be non-negative. So please consider some follow ups, if you are interested in improving these parts of verifier. But this change itself looks good to me: Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > /* Shift operators range is only computable if shift dimension operand > * is known. Also, shifts greater than 31 or 63 are undefined. This > -- > 2.39.2 > >