Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp45067imn; Thu, 28 Jul 2022 21:54:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vmlFhRk7fzWeJgx1mcnvD8YKwuQ4E5NqEF03hoI3uT1+lvmo7K73DbE0VswLEUgndj/vEw X-Received: by 2002:a17:907:2723:b0:72b:5af3:5a11 with SMTP id d3-20020a170907272300b0072b5af35a11mr1558619ejl.584.1659070442610; Thu, 28 Jul 2022 21:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659070442; cv=none; d=google.com; s=arc-20160816; b=n+tkYuzylGPPwz2Og3XDJOVAyszxobxOWH3MtyxuZSO9qGSOcU8WGcwf+uZ5JH5sNF wx7QnniDw4LXGPeDaj0XUw5zxS9cFTy5zD0He3WfJ6d6cD2GFfDUaKEo8SUB6GDosP7L Fcya1x0JUOYzmdUn45fvGUplevKhBOw92Pecr3jj+0SKLde11Uxa+d+L5nxva/hji+0R a5obx1nkr/fQ/NRR6VDreTw3MtAV+KWYhrfy9ESbTa2PTocVrhWtdiYpgvbZp3ubbjG+ pNp3JIpQHUH/c6blOTXRbqOjjuVXEn9f4yDpkt5L1uZ0tJ7QI03K7jk2d26s51eV5sHK W2Rg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W307cKMsb6DPyWr0X6lTH1Vjbw0z3PqxnN4FmNS8G68=; b=m2HO2xSW2t8fFOZ8y5E6u0zbsiVC2d46YUOJo797v7o3MH+F8INSnk2pA2elBx+CMV Isd8LmVdD7WxwcG1+/jCqsbB2ze1oQzGMf8Gm7785bxApeZLrZFEilHNt12h2B2yqI+j H0ZrgyetbWu3fXja+K4byM08bInYjMe1MAuAvsqA5V8WazTB/YQX0NKLd7WfcdyOJEc6 4hRLqD+ErlXVbgoYsdg8syCy7m90xACZc/JkPv6zGdQrM4cTvjean2ohCrpw8nlxFjDc +U6KXcLTLKrpVc04VIyETtXey4r1WNUWTZq6mx6CBvo45XfWoUh5HFMK26k4CxfjMOuR 7ICw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Sh8XNz2L; 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 dz15-20020a0564021d4f00b0043aa8412572si2741945edb.257.2022.07.28.21.53.38; Thu, 28 Jul 2022 21:54:02 -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=Sh8XNz2L; 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 S233634AbiG2EoL (ORCPT + 99 others); Fri, 29 Jul 2022 00:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiG2EoJ (ORCPT ); Fri, 29 Jul 2022 00:44:09 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CDD77A500; Thu, 28 Jul 2022 21:44:08 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id l23so6497519ejr.5; Thu, 28 Jul 2022 21:44:07 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=W307cKMsb6DPyWr0X6lTH1Vjbw0z3PqxnN4FmNS8G68=; b=Sh8XNz2Lk+RX4ovQpXaF5Jp7OAv3RRcn9hQ8vhof0RJRkxz7z37FYOOC5rf+lcW9hM aEmvF3dWgms3/UWDca++4ZoG8PTqYwJ5ugz0niFjsamWHDIIDA4/RauyWdiq/cn/eiQ9 5vuThOHPEEF1BfEySlmGPOLbdLQquwstF1B5IRZIvB9AyHzx+diI/cF1YLcMk7hLVq6+ PtKYl/DFNCOveWIDHBesUBODJdyvVwlvx3Mcc8EdoYKHZCZu0wyJrXxJcF9VTjb3ddfn VP62n6Sw7TwrmQsa4X+D3iaHKJaMwqYuxLqaeuizd5qIPaFBoWPiZr51Qmdficnd2jVe +HsQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=W307cKMsb6DPyWr0X6lTH1Vjbw0z3PqxnN4FmNS8G68=; b=Yn3WM9seauhzz1lBbaBnK66oOoOrmWi6D25XUOKXPbNP718keJ7SKeCWkeKdZs1Wjx koP3S30R+l+SlnwGRfr/iLXIX/PVNAMOPl3PkUoKhTYnpbRFqlveTgrmpVbkT3U2GSL6 9iHNq1E3H8s498NV4FuTTehTrLETdNARuwyt2j+/TrZSWjsm6ze2VvNU+S4O+VLs5PMS N7AJv7tJaPkMk7LDVCpBW+TBHB3ITyjxE6i/pd2MYpF5EY+RZxwh1As6VdhVZPwYdhuG htn3iTbVwg5VgHawH1p3ztgRVWqvKywMWvX0Ip6NbqlxXKnybbXff8VZPWYj031Xp4Ag THIg== X-Gm-Message-State: AJIora+Pq/Sbg6+r2Q3fWtA3z7hJZ9QSdHflBOwMCDCCUX4EXCFAS+ik 9xKcCClrvMjxxeQVXtYQl7YgfGQTu7SpRTT2+txTPA== X-Received: by 2002:a17:906:9b86:b0:72f:56db:ccf3 with SMTP id dd6-20020a1709069b8600b0072f56dbccf3mr1574569ejc.422.1659069846655; Thu, 28 Jul 2022 21:44:06 -0700 (PDT) Received: from Kk1r0a.localdomain ([185.22.153.144]) by smtp.gmail.com with ESMTPSA id o21-20020a1709061d5500b007300d771a98sm1206928ejh.175.2022.07.28.21.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jul 2022 21:44:06 -0700 (PDT) From: Youlin Li 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, Youlin Li Subject: [PATCH bpf] bpf: Do more tight ALU bounds tracking Date: Fri, 29 Jul 2022 12:43:17 +0800 Message-Id: <20220729044317.31975-1-liulin063@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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: Youlin Li --- 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