Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7930823rwl; Thu, 23 Mar 2023 10:20:49 -0700 (PDT) X-Google-Smtp-Source: AK7set/b34eP31/WG8n2GQNDHNgo9iPszwa5n2NTRa7ap37Ua2uq7CJGBMBFSfJ8Mlro+3VH7DGL X-Received: by 2002:a17:906:6981:b0:8ee:babc:d40b with SMTP id i1-20020a170906698100b008eebabcd40bmr12194475ejr.58.1679592048809; Thu, 23 Mar 2023 10:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679592048; cv=none; d=google.com; s=arc-20160816; b=U9DyPATcyIvBGnb8w19px78LY2T92tqF5IM9FEnykDP/nhZIWsM5zD75/h9q3iFj62 Ohfa2GsHhCla7jW5jMt6pMan39OvOS079QSfXp7Woy0mL9/+5y+u6TeCwee8MV3YP8uC jFsw3mGu6xzc0iFszqzjkedBvpv4d1oHsMm0obz71TZhueT1Gyu9wM9CF7s+Yo/+Wi3J 3iox/sFBeuxznJsWhOPYFcX0sSvoGlrtRf7xDjg9RnX74SjDTBVg6Yr8UwfncWXA7ILI TefTFSxMFbUzrZgk42382W05mQqUPqL2T3WM/LSVfLKxSl1wC4FSQqwCuV/qraN3yI+C qfuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UyfF97kg0OssMdjFthc2Xy3Web7QH9KpQCMnZmHyDZk=; b=oD4eO4gk12FJh/PH6ujrX6VD8Rtv0o+FaI7tEDnuWg56Q0Vkg8husE+dlGGk4xrzK7 ms1Be9GeFE55ZO2Bg5N9K3A0v5ZarXF3p9Xbgs+SciBjY5YilslE7Qk5EadY343YOieZ 3A34kTidmhUbWrVuKInCz3c6S/lpl0QXcZ+7WzIWr2E+wIGuPlSCwysKYiYBJyDFMsjN adpDJ3GMi9dCjzQYQHsO9J0wPBwc9iV7aS1JiX/GP9HuJ/8GOhDZXo2tMQr3O8u0qryD Fo7m0euLp/LDK3SfvppcyRfqbonIp6KDIWg82keUDXDnD4wOgel99sUNpczKD/KaVLY/ Dd9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=S1lCXnis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs33-20020a1709073ea100b0093c2280aafbsi3400355ejc.943.2023.03.23.10.20.25; Thu, 23 Mar 2023 10:20:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=S1lCXnis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231334AbjCWRQd (ORCPT + 99 others); Thu, 23 Mar 2023 13:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjCWRQa (ORCPT ); Thu, 23 Mar 2023 13:16:30 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEC4626866; Thu, 23 Mar 2023 10:16:29 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id eg48so89793487edb.13; Thu, 23 Mar 2023 10:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679591788; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UyfF97kg0OssMdjFthc2Xy3Web7QH9KpQCMnZmHyDZk=; b=S1lCXnisFdgkrdmHgl445bKHxAT6H/kvGykTpRQPIo/DybGALPmoPHFCMhfvqOynYp rzD6GIf2zaPtL+TULCx3Dwi1MchAMAzmf7ZkwzWxCw09gMLPqDpQwtm5caU48hbfW5TN kB3pUQvBupZQpK5kgTQo7JCo7koODxfOvDzmUiUKFPYCt+Y5Z0Tpxh+aRgJ0r9w0EVMG rNwCKNsDx4hzQzpq0Co/U0DagdmUiNAzCHCvjSzfFxZswwg0HRaJK7AZNa651M9tHzfj kNaeKuPBBzXK66cSq7opPWUNzXYUS55LwVFWHorz3kY8lHYVWpnGasRIHoFrXzapHoqW 0sGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679591788; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UyfF97kg0OssMdjFthc2Xy3Web7QH9KpQCMnZmHyDZk=; b=0mWddD8ayk4PEIsn+tfrbaXsx4Rq74VUg93g25nhVXT9Xvxw35dK9LRcUkd0Qr6rHX mwLPhZ3qoqyBdSe3PVZsFTcbFypiPGR9PCbYSo6Jf1GXHOLT45T2VYejt/fRWWWKri/T RaAXQaCpYMWO36hygoGd1WUgqZ9d0Yo78uTRcuuGhEnyGQSUhxa1Qdw2IGyqqduhYgaV sLrkXKy0KpViUr/dkzxzO3aOmrHW3YGWWcqD7rT/1n76r4R1NhfczbLHZz/T20jI1RVh JDH+jNRKA4RuRwrNv/xiHoDWwpby9lSYpeir2NfcfsGQ9gceQcT/rJBK+6xysa12U5e7 V+Vg== X-Gm-Message-State: AAQBX9dxXJULrKtejaVkWux76dLMu99m9wh86REjz7wMJNI42SNgyOuK eH/i2UF+uUv1IOH48kODDr1VHiFrytSTcRaG5Js= X-Received: by 2002:a50:f69e:0:b0:4fc:8749:cd77 with SMTP id d30-20020a50f69e000000b004fc8749cd77mr87589edn.3.1679591788153; Thu, 23 Mar 2023 10:16:28 -0700 (PDT) MIME-Version: 1.0 References: <20230324045842.729719-1-xukuohai@huaweicloud.com> <20230324045842.729719-2-xukuohai@huaweicloud.com> In-Reply-To: <20230324045842.729719-2-xukuohai@huaweicloud.com> From: Alexei Starovoitov Date: Thu, 23 Mar 2023 10:16:17 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2 1/2] bpf: add bound tracking for BPF_MOD To: Xu Kuohai Cc: bpf , "open list:KERNEL SELFTEST FRAMEWORK" , LKML , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 23, 2023 at 8:59=E2=80=AFAM Xu Kuohai wrote: > > From: Xu Kuohai > > dst_reg is marked as unknown when BPF_MOD instruction is verified, causin= g > the following bpf prog to be incorrectly rejected. > > 0: r0 =3D 0 > 1: r0 %=3D 1 // r0 is marked as unknown > 2: r1 =3D 0 > 3: r1 +=3D 1 > 4: if r1 < r0 goto pc-2 // verifier treats the loop as unbounded > 5: exit > > To teach verifier to accept the above prog, this patch adds bound trackin= g > for BPF_MOD. > > The approach is based on the following rules: > > 1. BPF_MOD is unsigned; > > 2. For an unsigned constant divisor x: > > a. when x !=3D 0, the resulted dst_reg bits are in the range [0, x - 1], > and if no wrapping occurs, the result can be further narrowed down > to [umin mod x, umax mod x]; > > b. when x =3D=3D 0, dst_reg is truncated to 32 bits by mod32 or remains > unchanged by mod64. > > Signed-off-by: Xu Kuohai Same Nack as before. You haven't answered _why_ anyone needs it.