Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp22806imn; Thu, 28 Jul 2022 20:43:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tqPWJbkk9FYu1xlgBBFXhwX5+eVGd7Uv50W8xwLE0e0AX0x7PsQ60xZ6tdVrLL2SNIYgpW X-Received: by 2002:a17:906:7945:b0:72f:e584:10f2 with SMTP id l5-20020a170906794500b0072fe58410f2mr1371378ejo.534.1659066213118; Thu, 28 Jul 2022 20:43:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659066213; cv=none; d=google.com; s=arc-20160816; b=CP6depmHQWaUX4uaniXl4ZnZPuIL0CUgbcJawUtEete5NQkveTJ6ytY9yqb1m0HvXD PH2iRlHC3tt/iov8UThi36yr/A+O8UbNcJyMI72JrnvUK15ksllwnbiqxmgiWY6+nhbS aEHU79lig6P63pFeDNHasUBs+4InM9/GI24MCceDeX7SzsNVJ5M4o19qQzfoLSxX5ZWJ ujaMMy0Ugv4rMlE81R9/UgrQu1eCCoSzhUVnSOHpOrkOoSpQdIqVlw2N26vvxzK5Op8N /q0tJ1GwdNow3ByWZHUz+020A6kt5NLponsHsCZ8fsKFLq1zYy0BZ2OIWzcdPAhsIWbx 8dNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MxegPP+9eR+tqzB10w9UP7S+nttT/U9nMghcqqAW8Tc=; b=EyzIOL6lOI6i4+a+C+rK9v0Guo2aO+QnLGmK87MDGve2Df+IaIZdvqPntqFtteOo1V MDHngiJBdwK/enH8wz9GiapGJpS70q+qaS2Sp9VgMKyZAxoSXgjK8YnsJ5zk6VLlWbIC Lv542XsZ7RQJlI2qHTcajiJccpPfunlPCjTz7SN0fAD3Hy9pMiaFH9wg10L66C8atJ4n CktpuFoBxIzE7XMAxEwWCWMW4Uqu6r7joeenyGqbqqaBa9MVPiwTKeq9ZScqSfqHcwbf tuXnlRirtQmr5ai79/YAsdjfup5wDVCWyaGG02h2VBnAxhbztcyIeD+3MsKJ/yAZZn7x gpYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZuMiPGRj; 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 y20-20020a170906071400b007269f7adbadsi1962579ejb.670.2022.07.28.20.43.08; Thu, 28 Jul 2022 20:43:33 -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=ZuMiPGRj; 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 S233781AbiG2DbL (ORCPT + 99 others); Thu, 28 Jul 2022 23:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbiG2DbH (ORCPT ); Thu, 28 Jul 2022 23:31:07 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E091A068; Thu, 28 Jul 2022 20:31:06 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id 15-20020a17090a098f00b001f305b453feso7171590pjo.1; Thu, 28 Jul 2022 20:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MxegPP+9eR+tqzB10w9UP7S+nttT/U9nMghcqqAW8Tc=; b=ZuMiPGRjx2u0bWndPQFq3JctNqzjgqzlOstPsDNefFEgX6OnLCGcnYvMLQBvj8/C1v A1YSL7zuNfm3bo5s63cvTnQOW2vqXQ2QaMV2D43USVKnaLc7ORTIC8pbeECuH6nnpsex nk8635x9d7X9W2NgQWvEY5YGg9O1lBvEXHnoVcIq4+OTf44oSFE+N7REcC0F/v5OoiqD Q+D1e1GT0Li23yQevFmaRuQJN4BSQfMFGSJoDP8FSOC5Hf888FTaBHdXIs5lPrXaFeh6 mA3h10NXUMjxbDxPj3sycbndDrkWJLubedxSBDzh8YI0SvwH+2m/tMJ0vALy9LXrMPCW vrKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MxegPP+9eR+tqzB10w9UP7S+nttT/U9nMghcqqAW8Tc=; b=gOAyHKsEiVQXxXaPNdVCsbsVWZ9iQzNbi+RDWMvhOjvvPNvzfFCy9Gve4wWbOGwvWO 4fVQIpH1ljK3ga+iZqa0akKj45Ecttni8K+t1gr3I7uMnvmf2ToPnZt1RWh6mZZw91p5 E68MwThajdxmy0Hw0qb5mgHgILQ9bMPN1hh1io5ap71N3CMaljfmnG9yhjddilwiaqLM hJYDI1WqAd4xWnWcaB6vX8zVzV8Ews3AwLp3qmqpYoAVABbbQdkC0G151f2B4eLjvm6D PaVENRn023E6h/LI/Dqf7ExNgCF8QFNeKjEcv7pXitCs6Mmp7RUEtFBhw51xJ89EmonV 4xdg== X-Gm-Message-State: ACgBeo0t95UoGoGdcZ5VkCC0BWuN2admLNIqPpDsqRaqtZZgGXpQTS7n eOFidsprAx7xdrUAzn4rQZ0= X-Received: by 2002:a17:90b:1e4f:b0:1f2:b482:bab9 with SMTP id pi15-20020a17090b1e4f00b001f2b482bab9mr1909636pjb.9.1659065466045; Thu, 28 Jul 2022 20:31:06 -0700 (PDT) Received: from Kk1r0a.localdomain ([220.158.232.156]) by smtp.gmail.com with ESMTPSA id l1-20020a170902ec0100b0016d338160d6sm2145840pld.155.2022.07.28.20.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jul 2022 20:31:05 -0700 (PDT) From: Kuee K1r0a To: ast@kernel.org Cc: daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Kuee K1r0a Subject: [PATCH bpf] bpf: Do more tight ALU bounds tracking Date: Fri, 29 Jul 2022 11:30:33 +0800 Message-Id: <20220729033033.3022-1-liulin063@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 32bit bounds and 64bit bounds are updated separately in adjust_scalar_min_max_vals() currently, let them learn from each other to get more tight bounds tracking. Similar operation can be found in reg_set_min_max(). Before: func#0 @0 0: R1=ctx(off=0,imm=0) R10=fp0 0: (b7) r0 = 0 ; R0_w=0 1: (b7) r1 = 0 ; R1_w=0 2: (87) r1 = -r1 ; R1_w=scalar() 3: (87) r1 = -r1 ; R1_w=scalar() 4: (c7) r1 s>>= 63 ; R1_w=scalar(smin=-1,smax=0) 5: (07) r1 += 2 ; R1_w=scalar(umin=1,umax=2,var_off=(0x0; 0xffffffff)) <--- [*] 6: (95) exit It can be seen that even if the 64bit bounds is clear here, the 32bit bounds is still in the state of 'UNKNOWN'. After: func#0 @0 0: R1=ctx(off=0,imm=0) R10=fp0 0: (b7) r0 = 0 ; R0_w=0 1: (b7) r1 = 0 ; R1_w=0 2: (87) r1 = -r1 ; R1_w=scalar() 3: (87) r1 = -r1 ; R1_w=scalar() 4: (c7) r1 s>>= 63 ; R1_w=scalar(smin=-1,smax=0) 5: (07) r1 += 2 ; R1_w=scalar(umin=1,umax=2,var_off=(0x0; 0x3)) <--- [*] 6: (95) exit Fixes: 3f50f132d840 ("bpf: Verifier, do explicit ALU32 bounds tracking") Signed-off-by: Kuee K1r0a --- kernel/bpf/verifier.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 0efbac0fd126..888aa50fbdc0 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -8934,10 +8934,13 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, break; } - /* ALU32 ops are zero extended into 64bit register */ - if (alu32) + if (alu32) { + /* ALU32 ops are zero extended into 64bit register */ zext_32_to_64(dst_reg); - reg_bounds_sync(dst_reg); + __reg_combine_32_into_64(dst_reg); + } else { + __reg_combine_64_into_32(dst_reg); + } return 0; } -- 2.25.1