Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/30/2024 6:18 AM, Eduard Zingerman wrote:
On Mon, 2024-04-29 at 13:58 -0700, Andrii Nakryiko wrote:

[...]

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 8f0f2e21699e..b69c89bc5cfc 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -13478,6 +13478,28 @@ static void scalar32_min_max_and(struct bpf_reg_state *dst_reg,
                  return;
          }

+       /* Special case: dst_reg is in range [-1, 0] */
+       if (dst_reg->s32_min_value == -1 && dst_reg->s32_max_value == 0) {
+               var32_off = tnum_union(src_reg->var_off, tnum_const(0));
+               dst_reg->var_off = tnum_with_subreg(dst_reg->var_off, var32_off);
+               dst_reg->u32_min_value = var32_off.value;
+               dst_reg->u32_max_value = min(dst_reg->u32_max_value, umax_val);

can you explain the logic behing u32 min/max updates, especially that
we use completely different values for min/max and it's not clear why
u32_min <= u32_max invariant will always hold. Same below

I agree with Andrii here.
It appears that dst_reg.{min,max} fields should be set as
{min(src.min, 0), max(src.max, 0)} for both signed and unsigned cases.
Wdyt?


Agree, since 0 is the minimum unsigned number, the result range is
equal to [0, src.u32_max].


+               dst_reg->s32_min_value = min_t(s32, src_reg->s32_min_value, 0);
+               dst_reg->s32_max_value = max_t(s32, src_reg->s32_max_value, 0);
+               return;
+       }
+
+       /* Special case: src_reg is in range [-1, 0] */
+       if (src_reg->s32_min_value == -1 && src_reg->s32_max_value == 0) {
+               var32_off = tnum_union(dst_reg->var_off, tnum_const(0));
+               dst_reg->var_off = tnum_with_subreg(dst_reg->var_off, var32_off);
+               dst_reg->u32_min_value = var32_off.value;
+               dst_reg->u32_max_value = min(dst_reg->u32_max_value, umax_val);
+               dst_reg->s32_min_value = min_t(s32, dst_reg->s32_min_value, 0);
+               dst_reg->s32_max_value = max_t(s32, dst_reg->s32_max_value, 0);
+               return;
+       }
+
          /* We get our minimum from the var_off, since that's inherently
           * bitwise.  Our maximum is the minimum of the operands' maxima.
           */

[...]





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux