Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5995168rdb; Thu, 14 Dec 2023 05:49:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPOe857Vv1SoPJ2OtSsKVyBNPMhNRI8Gq+G48DTNIHDXPV3QamT4SDE0DMZpPq+KT1Nsv6 X-Received: by 2002:a05:6a21:2782:b0:18f:e362:ccd3 with SMTP id rn2-20020a056a21278200b0018fe362ccd3mr3142498pzb.123.1702561789049; Thu, 14 Dec 2023 05:49:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702561789; cv=none; d=google.com; s=arc-20160816; b=s2v5R2dSY6YIxhN07Yed5wzf54stdGH1FLXIBfR9YgcuT5XK16LqfxR2IuG9rwYbfE c+PNzBTZEYvVr5tDsRCuEyiGD5XpWt8ZlZ7WqvP53ByWN3Wefn5QoSzECfdPqdXx7OEv 0s4SJXyCNJemOTh37heZkCuAf4lLGZuBceI/buBUBT/87xGL3xb899XK5WVxcOx78XCg JM+wiQ+isoSfggNoN+8s0VvTGiEXis/CqfMDRLbCXCaZp32gJL+OnvrGtzG2u5VF9jo6 RKwUcLXMXXlkfUOwo8Y+MY2q55kt4YGgXLkVWWA2UQPDUwd6mwn/q9YDwGrNDqr0Lt0A en/Q== 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=fz4v/GlOIwynmVpkuyg76jXkQ9B94i1i3JqKLEq9zcc=; fh=HM7zLZKdcTUOf1uvav7MJ0fdjJodau0oiFvqBG/+acY=; b=yhZ+dMjhNVGNUwM2s85FDzXBO7ClVNWoRPnxPGQXiFrh4+KsvR7gAl8i08cL+lYAbX 9A8Nj/Fs7+A4pYqAKxunYPqvhnCDyvBLvpkjl9W7Y1aMtufUfZWfT2XZOGAY3vskaud7 DJkVmuzGX80zN+5eEAp6+GSXzRmg/3c4v9/Wx6+/AmMIbNaFJ2UEamNJ4o0wl2DrjNLd eNhN5lwfuxxjwrujGWOgVoVnKIqgpgzihtdPObD/hdkok/5zzeKPGk1wPy+wFlVItFVN 0KSf5WNJnUzFX+U7zNbCWvd8fIFmDAQjKyHGGkQsgCUjINnF6U5xpaDu4e6IElegx1Ss WPPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gB8USD0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id fr7-20020a17090ae2c700b0028aec84d78dsi2351763pjb.67.2023.12.14.05.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:49:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gB8USD0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4A5A3806CF57; Thu, 14 Dec 2023 05:49:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573380AbjLNNth (ORCPT + 99 others); Thu, 14 Dec 2023 08:49:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573297AbjLNNte (ORCPT ); Thu, 14 Dec 2023 08:49:34 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AD34137; Thu, 14 Dec 2023 05:49:37 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-32f8441dfb5so7385829f8f.0; Thu, 14 Dec 2023 05:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702561776; x=1703166576; darn=vger.kernel.org; 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=fz4v/GlOIwynmVpkuyg76jXkQ9B94i1i3JqKLEq9zcc=; b=gB8USD0I+8E+cTNHyWkIQsK7WBA9zT7EX84JKpexDj7gQ8jklrmyrWVV3evoHJ0BwP 6b2kURYOE4wtYSDct8K5Mq88TBCaYG727mELQz5raVoLQtJc9n00hGgBjPmxzZLUSYYS QAK20MUtqKXeQO4+/uaL/SlvLaNaRdGBvkAIJJotpuAH6bI74cz7O1hHp3MrV8SAEvM6 kdJAD35T3hEmBMGp4r0voAPd0W3bUdcBUfup2QRJ4gBSVwSjMY4Qi4uQTl+FLBefFSRE mVcvRFIGqQ0NZzCBmtLR1zWQlSqkS9991fNHO+tf8tf6fpt9iyesXrrhrxse5JN+lpR2 8uSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702561776; x=1703166576; 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=fz4v/GlOIwynmVpkuyg76jXkQ9B94i1i3JqKLEq9zcc=; b=YZblfFNCFplLkG6Xkbt+zQQt5DE7rN+Fz/aPIwauDALKW4L44x9eswkADnqC8tl3pB ERfh8au76IoP64QZmHrPBu9Scd0VulnAEpPDm6xDCh8r4yIUiygtWtcVlIC2RVY0UJSb SMvf/+bJ7ED0y/ds4BfTm/Ru0ZbfRLQS/7RR5tRHCqXp6KhwrTm6AWU3BjNyazuGQVCu gCNBnys5zgTXlIWreXEYVlNB+K3v6ZffI2InUmKIodWQ9wW9Uah9GOrm/7+Ljem8SUy9 R1GQk80Dsr7i5o6w1wQJOvheWeLUwsTz+9qGVoF4U7TqcTnMj+ME6BqxnmD872+gbgCJ yscw== X-Gm-Message-State: AOJu0YyLDLkrD2RJ2ehiK5HuowZ7zVPPR46s5b7IqJH6b53ntUDxKC8i NZnRfeDL+3iAZ+x0Sa+4kSyswVRtH1IfuGhOarQeTJbGLQs= X-Received: by 2002:a5d:6208:0:b0:333:2fd2:6f54 with SMTP id y8-20020a5d6208000000b003332fd26f54mr4654191wru.94.1702561775638; Thu, 14 Dec 2023 05:49:35 -0800 (PST) MIME-Version: 1.0 References: <20231214062434.3565630-1-menglong8.dong@gmail.com> <20231214062434.3565630-2-menglong8.dong@gmail.com> In-Reply-To: <20231214062434.3565630-2-menglong8.dong@gmail.com> From: Alexei Starovoitov Date: Thu, 14 Dec 2023 05:49:24 -0800 Message-ID: Subject: Re: [PATCH bpf-next v3 1/2] bpf: make the verifier tracks the "not equal" for regs To: Menglong Dong Cc: Andrii Nakryiko , Eddy Z , Yonghong Song , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Martin KaFai Lau , Song Liu , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:49:47 -0800 (PST) On Wed, Dec 13, 2023 at 10:28=E2=80=AFPM Menglong Dong wrote: > > We can derive some new information for BPF_JNE in regs_refine_cond_op(). > Take following code for example: > > /* The type of "a" is u16 */ > if (a > 0 && a < 100) { > /* the range of the register for a is [0, 99], not [1, 99], > * and will cause the following error: > * > * invalid zero-sized read > * > * as a can be 0. > */ > bpf_skb_store_bytes(skb, xx, xx, a, 0); > } Please craft a selftest from above with inline asm (C might not work as compiler might optimize it) Also we call: /* fallthrough (FALSE) branch */ regs_refine_cond_op(false_reg1, false_reg2, rev_opcode(opcode), is_jmp32); /* jump (TRUE) branch */ regs_refine_cond_op(true_reg1, true_reg2, opcode, is_jmp32); so despite BPF_JNE is not handled explicitly it still should have caught above due to rev_opcode() ?