Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6783145rwn; Tue, 13 Sep 2022 08:59:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR4WB0yq3Menjp2TuhxDriVOUU/wOBxLj3YfgeQriJjVmWgW/je4rbze7SklZCuHwhI3OQWr X-Received: by 2002:a05:6402:34c2:b0:44f:322f:f0de with SMTP id w2-20020a05640234c200b0044f322ff0demr23867248edc.297.1663084748062; Tue, 13 Sep 2022 08:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663084748; cv=none; d=google.com; s=arc-20160816; b=MI38gt41pPQS3dbKqRhD7SWkWHhINBFQGZUTh9LiTsAerZXLrVOW1BjLfx0sp0Iqjq oPqq2tV6DL6sfCyAworGdgXMzDKjb9MxfnMS9Z3pLMoFP3lR/v8RXiE4uRLvvJgTehJ8 AFSPi6O/QKlOOyQmpkZoVYJIinims7NqgZJSAhfhn2nR34nZ/z4EjSsXqTJ+gUsjX0QJ DIsmVl8iOgj83nlwM3VMIlVa7Kv+dhCCBrkIlI+ey+081GU0mpzKGdx6+WyvY9L2hDOw TcJ4STBREim0Lxn0KlsbYhoiwnqf2ThADZpWvliMCImccwZxrd1CQU+GLIbnjklG2IcT sdCA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NGHa414ibNmnWDZtogwsW5Y7hTRewmXzrhujXT1Gz6Q=; b=L5Uu8yA6p6r5NoIzsQ2kSwI3QXWPzK5JF1ALfbDB9k6mzL67cJt+7Qn0w0KEf+55oA j7WyXLHQ0zZ99JAAB5yQ1hI+ist07n1/0zvHXsUPprSH1eSaAagjTlVVzYDAWNtJT24F 0hK52uzhI/4me5DcWSNdqLZvJXdLp+hKfzf+C/sK/wiPeLBb0CWRf7qnfK83bMI4j/f+ 7jr3yZnU0LOdTRy3vinhANJNVk6sf86APt0Iz1im6aw8Kc18+d4CzkzLbh3y78G4xHFM l9BtzAWz+cWcTrp8TqA7ms0oPcEiwmryy7PYoBG/gFETgCGp/6lJNMWOKUo3u582VrT+ 4EKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B2Lcm99P; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb10-20020a0564020d0a00b00448b72be304si10180399edb.64.2022.09.13.08.58.42; Tue, 13 Sep 2022 08:59:08 -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=@linuxfoundation.org header.s=korg header.b=B2Lcm99P; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235931AbiIMPlj (ORCPT + 99 others); Tue, 13 Sep 2022 11:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236724AbiIMPlF (ORCPT ); Tue, 13 Sep 2022 11:41:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39FD8287F; Tue, 13 Sep 2022 07:45:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3C547B80ECE; Tue, 13 Sep 2022 14:33:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A85FEC433D6; Tue, 13 Sep 2022 14:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079619; bh=PZSImN124wNr3us3+Y8nvBFBloECDt4+TqCOelhU4Wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B2Lcm99PvAZBFTWu4F7Zqk0G7iniiU4zeMu+aXJxi+5vFO4oT2gvzbpN7wZcbCfaX Dph7J3yOKu1ggRvyYrF/cuZE4R1P/9KydLrtuEHM8dm0yiQtXdYDd0lRmcMTJw0BXh Rnetd4dO6GxkE/YK6leRd6W9cfAY9Cmc6MLhNvuM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , John Fastabend , Alexei Starovoitov , Ovidiu Panait Subject: [PATCH 4.14 01/61] bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds() Date: Tue, 13 Sep 2022 16:07:03 +0200 Message-Id: <20220913140346.518913754@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140346.422813036@linuxfoundation.org> References: <20220913140346.422813036@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: John Fastabend commit 294f2fc6da27620a506e6c050241655459ccd6bd upstream. Currently, for all op verification we call __red_deduce_bounds() and __red_bound_offset() but we only call __update_reg_bounds() in bitwise ops. However, we could benefit from calling __update_reg_bounds() in BPF_ADD, BPF_SUB, and BPF_MUL cases as well. For example, a register with state 'R1_w=invP0' when we subtract from it, w1 -= 2 Before coerce we will now have an smin_value=S64_MIN, smax_value=U64_MAX and unsigned bounds umin_value=0, umax_value=U64_MAX. These will then be clamped to S32_MIN, U32_MAX values by coerce in the case of alu32 op as done in above example. However tnum will be a constant because the ALU op is done on a constant. Without update_reg_bounds() we have a scenario where tnum is a const but our unsigned bounds do not reflect this. By calling update_reg_bounds after coerce to 32bit we further refine the umin_value to U64_MAX in the alu64 case or U32_MAX in the alu32 case above. Signed-off-by: John Fastabend Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/158507151689.15666.566796274289413203.stgit@john-Precision-5820-Tower Signed-off-by: Ovidiu Panait Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2739,6 +2739,7 @@ static int adjust_scalar_min_max_vals(st coerce_reg_to_size(dst_reg, 4); } + __update_reg_bounds(dst_reg); __reg_deduce_bounds(dst_reg); __reg_bound_offset(dst_reg); return 0;