From patchwork Tue Dec 12 13:10:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 17913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7713774vqy; Tue, 12 Dec 2023 05:15:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEa5Vt97B3SdpUgD5BV7gGczV0iT2ZP6YhwAvvcq42R0MKwFoawa1tYBHOc4O5Mb8wdC9g/ X-Received: by 2002:a17:903:120c:b0:1d2:ec9b:930 with SMTP id l12-20020a170903120c00b001d2ec9b0930mr3274404plh.111.1702386954197; Tue, 12 Dec 2023 05:15:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702386954; cv=none; d=google.com; s=arc-20160816; b=xGAE2eHi4lmKoHYRzQkDHF2ldoJplNrjUgzBPtq+9J8QlCaMJBcTiaGBUDc/FhLoNw 9Y3MealINYWHbcsbpICehM6cgHn19hkQg+q6ptOVOI0Itx8lhgP5NDtEk6NafPZkUKy4 1pZuhSNP4bE7KECaOzpMLigU82afIz08bWMHEScYBsBOlIokkCkPHV4mfJA1q5aAccfI JaPvQBI+nFi8dt6uOdhrOu5XSFik3/PmLy8PiEXI90V+IF/PZWnYS1/p0mPhXaQ9pYMa u1q/iNPV+c/6n3mwnbO9d4PSA5xBmHrzfuNnX5THlDITW2Ty7D/zIusjQ5ZTaut0cqzZ FAYA== 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=2Tlr6Isxfo0VAkoIC5C/TmG4WBg0mKgqYVQoYoM3bP8=; fh=SGifBTVjLZ95Bpo5OYjxcS+0FNZ4Hm4Cdfz1m3M7p+s=; b=kQtSf9YTrncMIFWuGo7Ed1xSybwjUxYns+vgxkM+gKg13+0mZarxVb6xXR02Dx6+mH JjqaCRJbo30Dz+r/Y97wlOQB++bZgmyhC+0g4SWpG8OC3+wGXTgXaGa4KlXpAZ8by4ml /j+zJwBfEzqOjGxkFGA+x+Wbu8oToAyJQmjtiMy57eSGH3jC1k6bgn9wyqVbFO2i9WjN rniRKNcGOtQhWMYVmZGoRfo+bDL3OL4NiZZdpVdd+ZF7vlGUGgLOzCBAOxiuX2N5+d7q k5Yet9+lJD45ynnquWexYTURcL564s3p9sNRdSzXTnN58NZSpw+99fk81Tp3DsJxxh+7 0M5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ApIsWLvV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id t8-20020a1709028c8800b001cf97206e86si7672764plo.75.2023.12.12.05.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:15:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ApIsWLvV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id D17F6809B9C8; Tue, 12 Dec 2023 05:15:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376544AbjLLNP1 (ORCPT + 99 others); Tue, 12 Dec 2023 08:15:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232626AbjLLNPZ (ORCPT ); Tue, 12 Dec 2023 08:15:25 -0500 Received: from mail-oo1-xc44.google.com (mail-oo1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09419A8; Tue, 12 Dec 2023 05:15:32 -0800 (PST) Received: by mail-oo1-xc44.google.com with SMTP id 006d021491bc7-590a2a963baso2155443eaf.2; Tue, 12 Dec 2023 05:15:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702386931; x=1702991731; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2Tlr6Isxfo0VAkoIC5C/TmG4WBg0mKgqYVQoYoM3bP8=; b=ApIsWLvVgaWZXoBBEEg1N/ai8y8vkK8J8oqkJ1jAGXK5u2WanGfPXzlXLwigzpCjHi oa+5kSIAmbUxxcRRYxwJL/fsr3QblKePeAjBqjEa5zJkZc0CUMikElz6ZV3e1s9AyCPK XfX9EExW8awH9G/UA9LMCfEu9XnUydzK0TVzw2daixHJNZN2ty2rmWJvW190mG9nZse9 7wYgi69uYhZuTYX7CtoledSdcYz8czlYPq1/EwR2DAcTll7MlwRc5nrekeSz27TXQI5F lAfg50ZOmlctnS1KyqRkaUHiYLB5CE0/g0r7FdAEXtHOIBwEsSO1WgAKp079lhAC5k4v 2uXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702386931; x=1702991731; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2Tlr6Isxfo0VAkoIC5C/TmG4WBg0mKgqYVQoYoM3bP8=; b=vq0vfu2JYOWDB1Iq/FGA0YU9Ew6HEtsywxrJ+SEGVtPVMsssF1B6mM6Gz6geIR6HQ+ 6y+rrQxFK4mC2+ShjAgHSq25+3gFLuQASCf4SppGrfEGjt6Jbbqp0Prwe4aBMzVqJ4T3 PzLy/IxMxUDfqevNpKCBhbmPOItlOFagpmre0bx+5khjekbaj9Dn2Rf6uNO9stdXUycO kH30j7Ox10cyrl91pCHb2u9WuAWs97j7itDPpECSZ82KFOZ8RURT4wwaoSQh5wDKEjlj Uo71wPf9os/Ga13K7bn1NM6PJyKBWIOfbCS2OPH+ldiIVv1DFs6sdt0L4p3bFjOE3hbt FtXw== X-Gm-Message-State: AOJu0YxFAcMU+L/acQ3U1vgN8NrpDQl9DXHkYP9ONiTx3FKdfFYUhf1A qfxJiSy00Q+mZqPwjtlPXO0= X-Received: by 2002:a05:6358:7e03:b0:170:ef25:aa5c with SMTP id o3-20020a0563587e0300b00170ef25aa5cmr670918rwm.17.1702386931118; Tue, 12 Dec 2023 05:15:31 -0800 (PST) Received: from localhost.localdomain ([43.129.244.20]) by smtp.gmail.com with ESMTPSA id x20-20020aa793b4000000b006c4d2479bf8sm8095026pff.51.2023.12.12.05.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:15:30 -0800 (PST) From: Menglong Dong To: andrii@kernel.org, yonghong.song@linux.dev Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong Subject: [PATCH net-next v2 0/2] bpf: support to trace BPF_JNE Date: Tue, 12 Dec 2023 21:10:29 +0800 Message-Id: <20231212131031.3088661-1-menglong8.dong@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 05:15:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785082102542573783 X-GMAIL-MSGID: 1785082102542573783 For now, the reg bounds is not handled for BPF_JNE case, which can cause the failure of following case: /* 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); } In the code above, "a > 0" will be compiled to "jmp xxx if a == 0". In the TRUE branch, the dst_reg will be marked as known to 0. However, in the fallthrough(FALSE) branch, the dst_reg will not be handled, which makes the [min, max] for a is [0, 99], not [1, 99]. In the 1st patch, we reduce the range of the dst reg if the src reg is a const and is exactly the edge of the dst reg For BPF_JNE. In the 2nd patch, we just activate the test case for this logic in range_cond(), which is committed by Andrii in the commit 8863238993e2 ("selftests/bpf: BPF register range bounds tester"). Changes since v1: - simplify the code in the 1st patch - introduce the 2nd patch for the testing Menglong Dong (2): bpf: make the verifier trace the "not qeual" for regs selftests/bpf: activate the OP_NE login in range_cond() kernel/bpf/verifier.c | 29 ++++++++++++++++++- .../selftests/bpf/prog_tests/reg_bounds.c | 7 +---- 2 files changed, 29 insertions(+), 7 deletions(-)