From nobody Wed Feb 11 12:31:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A32DCC77B61 for ; Mon, 10 Apr 2023 08:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbjDJI7d (ORCPT ); Mon, 10 Apr 2023 04:59:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjDJI7b (ORCPT ); Mon, 10 Apr 2023 04:59:31 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB50C30D1 for ; Mon, 10 Apr 2023 01:59:29 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id q2so9030545pll.7 for ; Mon, 10 Apr 2023 01:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681117169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ueHlf63HU9JRFKSuWrERCIbxEHTEvzXB14p8A02eQpo=; b=CbC7kM3gDgrsz/8uuOl3IsHCOrSEg1QePC6wsHtePGDcEdppy/6fDvhBkRWD7aQrkh CMFzel33HYF9q1bIlal4ejP5H1RyYVC9Xu0BKNsfvPU2sD+GBAOmEBDE4fZVIUY3tNqH NIqNcSjZdloqdwwU2sVwX+ECL34OQPaO3MAlUJh5j5gY7dcz+t6DMxHgX8neu25sDUgh Ij8G8mRN050YaUJ4v3SPVOUvp2KPOV2c1enYRJhrl+B2txm/l/XJQRxvkXdRhlBQGc/9 Trzi+X+9jKajfI61tHtWXNNXFvFKoW2a94Yz6ATFO5vXeBsHloPIYg8lD+Bct6LTkHKn XCxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681117169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ueHlf63HU9JRFKSuWrERCIbxEHTEvzXB14p8A02eQpo=; b=O9ONARxFeyLf/dSU0IQYAjdLtXLFm3CKtf7f53m63EOunhvi+KfM/Jk9Kyxv8hAed7 m6xRnocSLvfrB1i0gcSlePqKd7S0BSBgH4S08UNC1Hrkh+4cCXzucUH2ajNdfXGGWRpR nCEmdGUNKIFT+RlzgoqU+EEZfiYxGbBuKcdndx+PVjmTZhfn8CYycUiLXZQgfRvEUBiw fCyhD7GoIrmDhRzW+LDXZ59SCWu6U+CSQDO/fwcpFKuYYG1Wl+IplH+KbG5xdPNQBjYO Ml/cMgs3KZdvTm0SGrP/xQmAwm81h5tZ5hNOvL91kIRaKBQRCRQ5tXGAHKeM/95Owo8o 5l/A== X-Gm-Message-State: AAQBX9cyuodyZZ929uq1X6Ng6QhPrHcGOBJrW0SwmQ9vzFgxP1EVvODV qU8h1Zxw5GHtOkY73rDvlb+DXw== X-Google-Smtp-Source: AKy350Yo1QN1keYMBG5X4wrxjlA7RdV5x6e9ubtteeY2QslDbmfBLvvkwOiZQJX6rEtxB2KABWGVvw== X-Received: by 2002:a05:6a20:6707:b0:dd:f44a:2717 with SMTP id q7-20020a056a20670700b000ddf44a2717mr10980029pzh.8.1681117169277; Mon, 10 Apr 2023 01:59:29 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id s21-20020aa78295000000b0058bacd6c4e8sm7279526pfm.207.2023.04.10.01.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 01:59:28 -0700 (PDT) From: Feng zhou To: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, yangzhenze@bytedance.com, wangdongdong.6@bytedance.com, zhouchengming@bytedance.com, zhoufeng.zf@bytedance.com Subject: [PATCH v3 1/2] bpf/btf: Fix is_int_ptr() Date: Mon, 10 Apr 2023 16:59:07 +0800 Message-Id: <20230410085908.98493-2-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230410085908.98493-1-zhoufeng.zf@bytedance.com> References: <20230410085908.98493-1-zhoufeng.zf@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Feng Zhou When tracing a kernel function with arg type is u32*, btf_ctx_access() would report error: arg2 type INT is not a struct. The commit bb6728d75611 ("bpf: Allow access to int pointer arguments in tracing programs") added support for int pointer, but don't skip modifiers before checking it's type. This patch fixes it. Fixes: bb6728d75611 ("bpf: Allow access to int pointer arguments in tracing= programs") Co-developed-by: Chengming Zhou Signed-off-by: Chengming Zhou Signed-off-by: Feng Zhou Acked-by: Jiri Olsa --- kernel/bpf/btf.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 593c45a294d0..5abd8dfa6b70 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -5910,12 +5910,8 @@ struct btf *bpf_prog_get_target_btf(const struct bpf= _prog *prog) =20 static bool is_int_ptr(struct btf *btf, const struct btf_type *t) { - /* t comes in already as a pointer */ - t =3D btf_type_by_id(btf, t->type); - - /* allow const */ - if (BTF_INFO_KIND(t->info) =3D=3D BTF_KIND_CONST) - t =3D btf_type_by_id(btf, t->type); + /* skip modifiers */ + t =3D btf_type_skip_modifiers(btf, t->type, NULL); =20 return btf_type_is_int(t); } --=20 2.20.1 From nobody Wed Feb 11 12:31:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13D90C76196 for ; Mon, 10 Apr 2023 09:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjDJJAR (ORCPT ); Mon, 10 Apr 2023 05:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbjDJJAE (ORCPT ); Mon, 10 Apr 2023 05:00:04 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5CB749E9 for ; Mon, 10 Apr 2023 01:59:37 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-633a6bf6af9so396734b3a.0 for ; Mon, 10 Apr 2023 01:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681117177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vmjzgy6aRksKW2xHyWe1W6xO2vj0DerqrAUjE2I1iOw=; b=fzN+MiU6321vicJhqAots7mAuz8s2SwEdyneHO35BP9aG2bAglabCDR54Dg9qrEr83 jQ15bR6CYr5dUAFx3btvWSu4q0wh2xdC9AI5zFXRUD7ZY/+jLqDhTZ7ebRhX2fQ7Xbji oyim6f/nljWILB+xe3P0Y+xAHly9T71+sHq2/tU2W1qwgxSGru2YjnIcvZZxj70KUuxd ITED0LiGDwFlG3l1DXPvL+kufdE0cDlvLTH3uXjnSkSlZSouF+3YlSz/TwW7QTvXz+hM dtPJYVyO2pIwj7GoWgLaK7VN+mpiMeMMzhoh3EOzaEtfOdptBSbMKE4coq9IuZpcqLDZ fF7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681117177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vmjzgy6aRksKW2xHyWe1W6xO2vj0DerqrAUjE2I1iOw=; b=AwL+eO5suzV8dUBlPJnYlFIVBP8zmjxrDZzmN0wzAccRAnpDODhC8hP/JaleU7brgW 4O0k/mbHdpU5SP16XQojlpX6nBqjJRzOnqSstFcs9ZXvzWNZerKh0vu2G9V5+9yinsIe /jYinkeiuH5ECM0ThzdoJEKF/kEw17xicUNRXD84Inq4iWUgiBsyyYn+CJzvw+DQPPdR AyC0rQ3CbLazi+avGVGOy6dWNTqcpUhfiHYNpv2p+BaOySKpYkzEpuWQhB3abM/7Ptr/ smOx35fVRy9xowkW6xJ8k0axpabqYP/lhBXVSjOduX5jsBTMHXQXwq/lf9s67ocmY11/ Ximg== X-Gm-Message-State: AAQBX9fdguPkQYubMVwOIlm4Y45cZxhKDcxZgVL9PCoUNoDV1+JXKyp9 Il3BCJius799pj9bvN0OJJQcEw== X-Google-Smtp-Source: AKy350Z6VMnUO4zv6ubuAdli2LF9uiWGuFD6pJjud0oMYpPji4pcHarTnTjnf6UpzXThS/n+Pt6Ydg== X-Received: by 2002:aa7:9464:0:b0:636:4850:7b9d with SMTP id t4-20020aa79464000000b0063648507b9dmr3859415pfq.0.1681117177404; Mon, 10 Apr 2023 01:59:37 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id s21-20020aa78295000000b0058bacd6c4e8sm7279526pfm.207.2023.04.10.01.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 01:59:37 -0700 (PDT) From: Feng zhou To: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, yangzhenze@bytedance.com, wangdongdong.6@bytedance.com, zhouchengming@bytedance.com, zhoufeng.zf@bytedance.com Subject: [PATCH v3 2/2] selftests/bpf: Add test to access u32 ptr argument in tracing program Date: Mon, 10 Apr 2023 16:59:08 +0800 Message-Id: <20230410085908.98493-3-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230410085908.98493-1-zhoufeng.zf@bytedance.com> References: <20230410085908.98493-1-zhoufeng.zf@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Feng Zhou Adding verifier test for accessing u32 pointer argument in tracing programs. The test program loads 1nd argument of bpf_fentry_test9 function which is u32 pointer and checks that verifier allows that. Co-developed-by: Chengming Zhou Signed-off-by: Chengming Zhou Signed-off-by: Feng Zhou Acked-by: Jiri Olsa --- net/bpf/test_run.c | 8 +++++++- .../testing/selftests/bpf/verifier/btf_ctx_access.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index f1652f5fbd2e..68bdfc041a7b 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -541,6 +541,11 @@ int noinline bpf_fentry_test8(struct bpf_fentry_test_t= *arg) return (long)arg->a; } =20 +__bpf_kfunc u32 bpf_fentry_test9(u32 *a) +{ + return *a; +} + __bpf_kfunc int bpf_modify_return_test(int a, int *b) { *b +=3D 1; @@ -855,7 +860,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog, bpf_fentry_test5(11, (void *)12, 13, 14, 15) !=3D 65 || bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) !=3D 111 || bpf_fentry_test7((struct bpf_fentry_test_t *)0) !=3D 0 || - bpf_fentry_test8(&arg) !=3D 0) + bpf_fentry_test8(&arg) !=3D 0 || + bpf_fentry_test9(&retval) !=3D 0) goto out; break; case BPF_MODIFY_RETURN: diff --git a/tools/testing/selftests/bpf/verifier/btf_ctx_access.c b/tools/= testing/selftests/bpf/verifier/btf_ctx_access.c index 6340db6b46dc..0484d3de040d 100644 --- a/tools/testing/selftests/bpf/verifier/btf_ctx_access.c +++ b/tools/testing/selftests/bpf/verifier/btf_ctx_access.c @@ -10,3 +10,16 @@ .expected_attach_type =3D BPF_TRACE_FENTRY, .kfunc =3D "bpf_modify_return_test", }, + +{ + "btf_ctx_access u32 pointer accept", + .insns =3D { + BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 0), /* load 1nd argument value (= u32 pointer) */ + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_EXIT_INSN(), + }, + .result =3D ACCEPT, + .prog_type =3D BPF_PROG_TYPE_TRACING, + .expected_attach_type =3D BPF_TRACE_FENTRY, + .kfunc =3D "bpf_fentry_test9", +}, --=20 2.20.1