BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	alexei.starovoitov@gmail.com, martin.lau@kernel.org,
	eddyz87@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v1 3/5] selftests/bpf: Test referenced kptr arguments of struct_ops programs
Date: Fri, 14 Feb 2025 17:14:13 -0800	[thread overview]
Message-ID: <227f048e-402e-47c3-b989-27b8e88c83bc@linux.dev> (raw)
In-Reply-To: <20250214164520.1001211-4-ameryhung@gmail.com>

On 2/14/25 8:45 AM, Amery Hung wrote:
> diff --git a/tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__global_subprog.c b/tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__global_subprog.c
> new file mode 100644
> index 000000000000..ae074aa62852
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__global_subprog.c
> @@ -0,0 +1,39 @@
> +#include <vmlinux.h>
> +#include <bpf/bpf_tracing.h>
> +#include "../test_kmods/bpf_testmod.h"
> +#include "bpf_misc.h"
> +
> +char _license[] SEC("license") = "GPL";
> +
> +extern void bpf_task_release(struct task_struct *p) __ksym;
> +
> +__noinline int subprog_release(__u64 *ctx __arg_ctx)
> +{
> +	struct task_struct *task = (struct task_struct *)ctx[1];
> +	int dummy = (int)ctx[0];
> +
> +	bpf_task_release(task);
> +
> +	return dummy + 1;
> +}
> +
> +/* Test that the verifier rejects a program that contains a global
> + * subprogram with referenced kptr arguments
> + */
> +SEC("struct_ops/test_refcounted")
> +__failure __log_level(2)
> +__msg("Validating subprog_release() func#1...")
> +__msg("invalid bpf_context access off=8. Reference may already be released")
> +int refcounted_fail__global_subprog(unsigned long long *ctx)
> +{
> +	struct task_struct *task = (struct task_struct *)ctx[1];
> +
> +	bpf_task_release(task);
> +
> +	return subprog_release(ctx);

One question, swap the subprog_release and bpf_task_release order will still be 
the same failure, right?  Meaning:

	subprog_release(ctx);

	bpf_task_release(task);

	return 0;

which is fine based on the changes in the do_check_common() in patch 2. Just 
want to confirm my understanding.

Other than that,

Acked-by: Martin KaFai Lau <martin.lau@kernel.org>

  reply	other threads:[~2025-02-15  1:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 16:45 [PATCH bpf-next v1 0/5] Extend struct_ops support for operators Amery Hung
2025-02-14 16:45 ` [PATCH bpf-next v1 1/5] bpf: Make every prog keep a copy of ctx_arg_info Amery Hung
2025-02-15  0:20   ` Martin KaFai Lau
2025-02-15  2:41   ` Alexei Starovoitov
2025-02-15  4:39     ` Amery Hung
2025-02-14 16:45 ` [PATCH bpf-next v1 2/5] bpf: Support getting referenced kptr from struct_ops argument Amery Hung
2025-02-15  0:49   ` Martin KaFai Lau
2025-02-15  2:48   ` Alexei Starovoitov
2025-02-15  4:58     ` Amery Hung
2025-02-14 16:45 ` [PATCH bpf-next v1 3/5] selftests/bpf: Test referenced kptr arguments of struct_ops programs Amery Hung
2025-02-15  1:14   ` Martin KaFai Lau [this message]
2025-02-15  4:30     ` Amery Hung
2025-02-14 16:45 ` [PATCH bpf-next v1 4/5] bpf: Allow struct_ops prog to return referenced kptr Amery Hung
2025-02-15  1:42   ` Martin KaFai Lau
2025-02-14 16:45 ` [PATCH bpf-next v1 5/5] selftests/bpf: Test returning referenced kptr from struct_ops programs Amery Hung
2025-02-15  1:52   ` Martin KaFai Lau
2025-02-15  2:09 ` [PATCH bpf-next v1 0/5] Extend struct_ops support for operators Martin KaFai Lau
2025-02-18 22:20   ` Amery Hung

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=227f048e-402e-47c3-b989-27b8e88c83bc@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    /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