From: Eduard Zingerman <eddyz87@gmail.com>
To: Amery Hung <ameryhung@gmail.com>, netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
alexei.starovoitov@gmail.com, martin.lau@kernel.org,
sinquersw@gmail.com, toke@redhat.com, jhs@mojatatu.com,
jiri@resnulli.us, stfomichev@gmail.com,
ekarani.silvestre@ccc.ufcg.edu.br, yangpeihao@sjtu.edu.cn,
xiyou.wangcong@gmail.com, yepeilin.cs@gmail.com,
amery.hung@bytedance.com
Subject: Re: [PATCH bpf-next v2 04/14] selftests/bpf: Test returning referenced kptr from struct_ops programs
Date: Thu, 23 Jan 2025 01:58:09 -0800 [thread overview]
Message-ID: <63ef4167a39a33cdc72fa8e920d39a1a66e158f6.camel@gmail.com> (raw)
In-Reply-To: <20241220195619.2022866-5-amery.hung@gmail.com>
On Fri, 2024-12-20 at 11:55 -0800, Amery Hung wrote:
[...]
> diff --git a/tools/testing/selftests/bpf/progs/struct_ops_kptr_return_fail__local_kptr.c b/tools/testing/selftests/bpf/progs/struct_ops_kptr_return_fail__local_kptr.c
> new file mode 100644
> index 000000000000..b8b4f05c3d7f
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/struct_ops_kptr_return_fail__local_kptr.c
> @@ -0,0 +1,34 @@
> +#include <vmlinux.h>
> +#include <bpf/bpf_tracing.h>
> +#include "../test_kmods/bpf_testmod.h"
> +#include "bpf_experimental.h"
> +#include "bpf_misc.h"
> +
> +char _license[] SEC("license") = "GPL";
> +
> +struct cgroup *bpf_cgroup_acquire(struct cgroup *p) __ksym;
> +void bpf_task_release(struct task_struct *p) __ksym;
> +
> +/* This test struct_ops BPF programs returning referenced kptr. The verifier should
> + * reject programs returning a local kptr.
> + */
> +SEC("struct_ops/test_return_ref_kptr")
> +__failure __msg("At program exit the register R0 is not a known value (ptr_or_null_)")
> +struct task_struct *BPF_PROG(kptr_return_fail__local_kptr, int dummy,
> + struct task_struct *task, struct cgroup *cgrp)
> +{
> + struct task_struct *t;
> +
> + bpf_task_release(task);
> +
> + t = bpf_obj_new(typeof(*task));
The return type (and btf id) of the bpf_obj_new is 'void *',
but here a function with return type (and btf id) of
'struct task_struct *' is necessary.
For example:
- t = bpf_obj_new(typeof(*task));
+ t = bpf_task_from_pid(32);
However, if this replacement is done the test does
not signal verification error because of insufficient
checks in the verifier.c:check_return_code().
> + if (!t)
> + return NULL;
> +
> + return t;
> +}
> +
> +SEC(".struct_ops.link")
> +struct bpf_testmod_ops testmod_kptr_return = {
> + .test_return_ref_kptr = (void *)kptr_return_fail__local_kptr,
> +};
[...]
next prev parent reply other threads:[~2025-01-23 9:58 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 19:55 [PATCH bpf-next v2 00/14] bpf qdisc Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 01/14] bpf: Support getting referenced kptr from struct_ops argument Amery Hung
2025-01-23 9:57 ` Eduard Zingerman
2025-01-23 19:41 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 02/14] selftests/bpf: Test referenced kptr arguments of struct_ops programs Amery Hung
2025-01-23 9:57 ` Eduard Zingerman
2025-01-24 0:04 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 03/14] bpf: Allow struct_ops prog to return referenced kptr Amery Hung
2025-01-15 15:25 ` Ming Lei
2025-01-23 9:57 ` Eduard Zingerman
2025-01-23 18:19 ` Eduard Zingerman
2024-12-20 19:55 ` [PATCH bpf-next v2 04/14] selftests/bpf: Test returning referenced kptr from struct_ops programs Amery Hung
2025-01-23 9:58 ` Eduard Zingerman [this message]
2024-12-20 19:55 ` [PATCH bpf-next v2 05/14] bpf: net_sched: Support implementation of Qdisc_ops in bpf Amery Hung
2025-01-09 15:00 ` Amery Hung
2025-01-10 0:28 ` Martin KaFai Lau
2025-01-10 1:20 ` Jakub Kicinski
2024-12-20 19:55 ` [PATCH bpf-next v2 06/14] bpf: net_sched: Add basic bpf qdisc kfuncs Amery Hung
2025-01-10 0:24 ` Martin KaFai Lau
2025-01-10 18:00 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 07/14] bpf: Search and add kfuncs in struct_ops prologue and epilogue Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 08/14] bpf: net_sched: Add a qdisc watchdog timer Amery Hung
2025-01-09 0:20 ` Martin KaFai Lau
2025-01-09 15:00 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 09/14] bpf: net_sched: Support updating bstats Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 10/14] bpf: net_sched: Support updating qstats Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 11/14] bpf: net_sched: Allow writing to more Qdisc members Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 12/14] libbpf: Support creating and destroying qdisc Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 13/14] selftests: Add a basic fifo qdisc test Amery Hung
2025-01-10 0:05 ` Martin KaFai Lau
2024-12-20 19:55 ` [PATCH bpf-next v2 14/14] selftests: Add a bpf fq qdisc to selftest Amery Hung
2025-01-09 23:36 ` Martin KaFai Lau
2025-01-02 17:29 ` [PATCH bpf-next v2 00/14] bpf qdisc Toke Høiland-Jørgensen
2025-01-10 1:43 ` Martin KaFai Lau
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=63ef4167a39a33cdc72fa8e920d39a1a66e158f6.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=amery.hung@bytedance.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=ekarani.silvestre@ccc.ufcg.edu.br \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sinquersw@gmail.com \
--cc=stfomichev@gmail.com \
--cc=toke@redhat.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yangpeihao@sjtu.edu.cn \
--cc=yepeilin.cs@gmail.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