From: Song Liu <song@kernel.org>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
pablo@netfilter.org, fw@strlen.de,
netfilter-devel@vger.kernel.org, lorenzo.bianconi@redhat.com,
"Jesper Dangaard Brouer" <brouer@redhat.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Subject: Re: [PATCH v2 bpf-next 2/4] selftests/bpf: Extend KF_TRUSTED_ARGS test for __ref annotation
Date: Tue, 6 Sep 2022 14:30:09 -0700 [thread overview]
Message-ID: <CAPhsuW49ZU+ak=uned=AfBbGNVboLguKVXjfsOy7hZLbUSkyag@mail.gmail.com> (raw)
In-Reply-To: <1bea1050068d7ad50baa2f6b6c09c9eb1ae5b4dd.1662383493.git.lorenzo@kernel.org>
On Mon, Sep 5, 2022 at 6:15 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>
> Extend the existing test for KF_TRUSTED_ARGS by also checking whether
> the same happens when a __ref suffix is present in argument name of a
> kfunc.
>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Acked-by: Song Liu <song@kernel.org>
> ---
> tools/testing/selftests/bpf/verifier/calls.c | 38 +++++++++++++++-----
> 1 file changed, 30 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c
> index 3fb4f69b1962..891fcda50d9d 100644
> --- a/tools/testing/selftests/bpf/verifier/calls.c
> +++ b/tools/testing/selftests/bpf/verifier/calls.c
> @@ -219,7 +219,7 @@
> .errstr = "variable ptr_ access var_off=(0x0; 0x7) disallowed",
> },
> {
> - "calls: invalid kfunc call: referenced arg needs refcounted PTR_TO_BTF_ID",
> + "calls: invalid kfunc call: referenced arg needs refcounted PTR_TO_BTF_ID (KF_TRUSTED_ARGS)",
> .insns = {
> BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
> BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
> @@ -227,10 +227,30 @@
> BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
> BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
> BPF_EXIT_INSN(),
> - BPF_MOV64_REG(BPF_REG_6, BPF_REG_0),
> - BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
> + BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, 16),
> BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
> - BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_6, 16),
> + BPF_MOV64_IMM(BPF_REG_0, 0),
> + BPF_EXIT_INSN(),
> + },
> + .prog_type = BPF_PROG_TYPE_SCHED_CLS,
> + .fixup_kfunc_btf_id = {
> + { "bpf_kfunc_call_test_acquire", 3 },
> + { "bpf_kfunc_call_test_trusted", 7 },
> + },
> + .result_unpriv = REJECT,
> + .result = REJECT,
> + .errstr = "R1 must be referenced",
> +},
> +{
> + "calls: invalid kfunc call: referenced arg needs refcounted PTR_TO_BTF_ID (__ref)",
> + .insns = {
> + BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
> + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
> + BPF_ST_MEM(BPF_DW, BPF_REG_1, 0, 0),
> + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
> + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
> + BPF_EXIT_INSN(),
> + BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, 16),
> BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
> BPF_MOV64_IMM(BPF_REG_0, 0),
> BPF_EXIT_INSN(),
> @@ -238,8 +258,7 @@
> .prog_type = BPF_PROG_TYPE_SCHED_CLS,
> .fixup_kfunc_btf_id = {
> { "bpf_kfunc_call_test_acquire", 3 },
> - { "bpf_kfunc_call_test_ref", 8 },
> - { "bpf_kfunc_call_test_ref", 10 },
> + { "bpf_kfunc_call_test_ref", 7 },
> },
> .result_unpriv = REJECT,
> .result = REJECT,
> @@ -259,14 +278,17 @@
> BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
> BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
> BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
> + BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
> + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
> BPF_MOV64_IMM(BPF_REG_0, 0),
> BPF_EXIT_INSN(),
> },
> .prog_type = BPF_PROG_TYPE_SCHED_CLS,
> .fixup_kfunc_btf_id = {
> { "bpf_kfunc_call_test_acquire", 3 },
> - { "bpf_kfunc_call_test_ref", 8 },
> - { "bpf_kfunc_call_test_release", 10 },
> + { "bpf_kfunc_call_test_trusted", 8 },
> + { "bpf_kfunc_call_test_ref", 10 },
> + { "bpf_kfunc_call_test_release", 12 },
> },
> .result_unpriv = REJECT,
> .result = ACCEPT,
> --
> 2.37.3
>
next prev parent reply other threads:[~2022-09-06 21:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-05 13:14 [PATCH v2 bpf-next 0/4] Introduce bpf_ct_set_nat_info kfunc helper Lorenzo Bianconi
2022-09-05 13:14 ` [PATCH v2 bpf-next 1/4] bpf: Add support for per-parameter trusted args Lorenzo Bianconi
2022-09-06 21:27 ` Song Liu
2022-09-05 13:14 ` [PATCH v2 bpf-next 2/4] selftests/bpf: Extend KF_TRUSTED_ARGS test for __ref annotation Lorenzo Bianconi
2022-09-06 21:30 ` Song Liu [this message]
2022-09-05 13:14 ` [PATCH v2 bpf-next 3/4] net: netfilter: add bpf_ct_set_nat_info kfunc helper Lorenzo Bianconi
2022-09-06 21:36 ` Song Liu
2022-09-07 9:01 ` Lorenzo Bianconi
2022-09-07 4:27 ` Alexei Starovoitov
2022-09-07 4:39 ` Kumar Kartikeya Dwivedi
2022-09-07 5:15 ` Alexei Starovoitov
2022-09-07 5:51 ` Kumar Kartikeya Dwivedi
2022-09-07 17:33 ` Alexei Starovoitov
2022-09-07 18:12 ` Kumar Kartikeya Dwivedi
2022-09-05 13:14 ` [PATCH v2 bpf-next 4/4] selftests/bpf: add tests for bpf_ct_set_nat_info kfunc Lorenzo Bianconi
2022-09-06 21:54 ` Song Liu
2022-09-07 10:47 ` Lorenzo Bianconi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPhsuW49ZU+ak=uned=AfBbGNVboLguKVXjfsOy7hZLbUSkyag@mail.gmail.com' \
--to=song@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=kuba@kernel.org \
--cc=lorenzo.bianconi@redhat.com \
--cc=lorenzo@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=toke@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).