From patchwork Fri Apr 7 08:46:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Zhou X-Patchwork-Id: 13204595 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 E869CC6FD1D for ; Fri, 7 Apr 2023 08:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232108AbjDGIq7 (ORCPT ); Fri, 7 Apr 2023 04:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239799AbjDGIq6 (ORCPT ); Fri, 7 Apr 2023 04:46:58 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5E0D8A79 for ; Fri, 7 Apr 2023 01:46:53 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id d22-20020a17090a111600b0023d1b009f52so864466pja.2 for ; Fri, 07 Apr 2023 01:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680857213; 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=FVi0AWiu1zAkxzg8zSlzsBAWbtMyPsv5tFRVM1WnV2A=; b=YjtReY6YH5PgBWUNe8+Zz4g/S7AxXP6Ok/jQUc4jyUj8R+tDpnsYdLbh8/iMw2v+Jv P23WAr2SOl8H6ECcKcyL7BfAoR+jwoW5qbOL9VtenUVOu/XpVntsOtakSPjqNpj9SBfI 2btr4MW/LNfAmx4og6Fbif4/zshs0ZWo3bs8VJT4aeAh9+Z/rTf6LQ/Ewh8uNxiIyqh8 /NvMpNeaBAFmvi635Gy7rT3iNd7KLX9AbDcfGQkw/CyU8p55KmHTE/GF27WcJebT51A3 xWjGoGrkccsgK0wUmabcpFmK6SbB7An3As2nt521xR37SML4gDfm6L2iCFCySbEIU8HK KQTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680857213; 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=FVi0AWiu1zAkxzg8zSlzsBAWbtMyPsv5tFRVM1WnV2A=; b=Awz/4mOi6LSOgmpbKP6yMphyfjgmk1uXyx/CefYzaExAnwdEm+xtPUbyq9SrzRrwXy aQsDqWoiboTZ/VjggYzQ6fZgnJs5HzkjSFnPqKij6btGsYuy0nUVjjDTAe9kbI269NBJ 9+uk9qm24UVXxpjnOq+RmPwBdKpHOxxO2Opb/TLwwqcaUg/Y/D2PZsE11LU1aaMKAopA y3g7TibgSlw2BuTGVedd5nDQtMgD1xiX7NRI9OX7yuHN6LvcwoIxsveDmtYhyQSm7lSC ICxKdLJn1JSe+LSp3tCbm9AzBm2vbHhUitsDgCQ+njIzF58hutgetBg/+s/uzL3UYRCH IgdQ== X-Gm-Message-State: AAQBX9e3Bwlk9WoVjyFn8aAX1Xp+o+pL9kIrFbVMX1haZ1R/aadbcdrF PQ6q6slD/bZaa9Tj6FIzIS5PQQ== X-Google-Smtp-Source: AKy350bzeTj5bfaWlrevCPwRsEkQ42Pd5eqaKyCwfP9XiQJ2/nx1laJP+4SSVAhR8jdFnKHsZw+QhA== X-Received: by 2002:a17:90b:4a0a:b0:23b:3d6e:1ed with SMTP id kk10-20020a17090b4a0a00b0023b3d6e01edmr1732441pjb.13.1680857213186; Fri, 07 Apr 2023 01:46:53 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id s13-20020a17090a5d0d00b0023b3d80c76csm2333676pji.4.2023.04.07.01.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 01:46:52 -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 v2 1/2] bpf/btf: Fix is_int_ptr() Date: Fri, 7 Apr 2023 16:46:07 +0800 Message-Id: <20230407084608.62296-2-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230407084608.62296-1-zhoufeng.zf@bytedance.com> References: <20230407084608.62296-1-zhoufeng.zf@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 --- kernel/bpf/btf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 593c45a294d0..17c65de1e48b 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -5913,9 +5913,8 @@ static bool is_int_ptr(struct btf *btf, const struct btf_type *t) /* t comes in already as a pointer */ t = btf_type_by_id(btf, t->type); - /* allow const */ - if (BTF_INFO_KIND(t->info) == BTF_KIND_CONST) - t = btf_type_by_id(btf, t->type); + /* skip modifiers */ + t = btf_type_skip_modifiers(btf, t->type, NULL); return btf_type_is_int(t); } From patchwork Fri Apr 7 08:46:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Zhou X-Patchwork-Id: 13204597 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 456B2C76196 for ; Fri, 7 Apr 2023 08:47:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238521AbjDGIrf (ORCPT ); Fri, 7 Apr 2023 04:47:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240322AbjDGIr0 (ORCPT ); Fri, 7 Apr 2023 04:47:26 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 397FCA24F for ; Fri, 7 Apr 2023 01:47:02 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 60-20020a17090a09c200b0023fcc8ce113so817871pjo.4 for ; Fri, 07 Apr 2023 01:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680857221; 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=R19VL0csBPbWvcgvmXecbzxFCkoToYH65diKdOlEF9KJ/fEYiWe37kKhzwJoq70D/C Oo+Wfsg7HRJ4da903PbxzU++qNf8IHdRLW3w0tJvetNpXiN4ZlLhtK1GnlWwQ4Ws0bCh o0ryF+AcZPFBXUve+oRoD6FFsQUF8t+FVSRFJcF22Y/f52ElJGYZb0U0mrpr2rZ0rKOO viD5AXfUBZ5gyoOGuxMxwOTXcbG/HJEaOBflD7lF5qC+YY9ESVQ/0S3W21LDzN6MfmE+ OydadRLL5SvuJ/oglzCl73BXA4sIFWY5w9+LHsbi0Bn7Z5gKnJCROgaIQiFs/cMwN3FP rJoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680857221; 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=3zLsll28Vtqlt5nDW23e2S13x/+qPfvTh040TxKqjkUBx8L70lOoWXfPNXFPROlb2/ Q5nt8MADogZoXsCGA1/ujLd4KZjyeHoGLoirZs2AQ/OsmzdT/2IK1+wJDWTdRqKPm7qg 96/eRpULni6ubrgS3d4SG9mrMXSUJLBiAxyHkyczQb+Co+yKlQOD9lGe4arkKrBpDZ4d nFUUNsfLGbWUvt1vaIcDWYhLwEBB+Dc+vfOTzBrxFxDy6am+ICFp1vcKtxGjKzIA+bqA 9KZEYi5WzgocWvePfoQ4P/IjNwSURn5SFtacvNYLi/6ypOmLsdmFHIu9k75mg0rQWUvJ P6Ww== X-Gm-Message-State: AAQBX9eSSSIHE+a7TjoCJmcnwSpFqHsHrYRDWHFXc2yxswmukwosEGRf 21KMzY4eFmyLn+JoGsdx9uLhwQ== X-Google-Smtp-Source: AKy350ak8Z2sVLnknesb8rdNJcheWrbfZoigZ/kr+Zq60kGlUKezCUKJy/ma6QUMi7cvv7oDlZUXOg== X-Received: by 2002:a17:90b:1bd1:b0:23c:fef0:d441 with SMTP id oa17-20020a17090b1bd100b0023cfef0d441mr1578447pjb.33.1680857221702; Fri, 07 Apr 2023 01:47:01 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id s13-20020a17090a5d0d00b0023b3d80c76csm2333676pji.4.2023.04.07.01.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 01:47:01 -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 v2 2/2] selftests/bpf: Add test to access u32 ptr argument in tracing program Date: Fri, 7 Apr 2023 16:46:08 +0800 Message-Id: <20230407084608.62296-3-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230407084608.62296-1-zhoufeng.zf@bytedance.com> References: <20230407084608.62296-1-zhoufeng.zf@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 --- 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; } +__bpf_kfunc u32 bpf_fentry_test9(u32 *a) +{ + return *a; +} + __bpf_kfunc int bpf_modify_return_test(int a, int *b) { *b += 1; @@ -855,7 +860,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog, bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 || bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 || bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 || - bpf_fentry_test8(&arg) != 0) + bpf_fentry_test8(&arg) != 0 || + bpf_fentry_test9(&retval) != 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 = BPF_TRACE_FENTRY, .kfunc = "bpf_modify_return_test", }, + +{ + "btf_ctx_access u32 pointer accept", + .insns = { + 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 = ACCEPT, + .prog_type = BPF_PROG_TYPE_TRACING, + .expected_attach_type = BPF_TRACE_FENTRY, + .kfunc = "bpf_fentry_test9", +},