bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Dave Marchevsky <davemarchevsky@fb.com>
Cc: "bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	Kernel Team <Kernel-team@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Yonghong Song <yhs@fb.com>
Subject: Re: [PATCH bpf-next 3/3] bpf/selftests: add bpf_get_task_stack retval bounds test_prog
Date: Fri, 16 Apr 2021 17:06:11 +0000	[thread overview]
Message-ID: <7E5C38DC-DCAA-4905-A289-1C339748E3DB@fb.com> (raw)
In-Reply-To: <20210416025537.2352753-4-davemarchevsky@fb.com>



> On Apr 15, 2021, at 7:55 PM, Dave Marchevsky <davemarchevsky@fb.com> wrote:
> 
> Add a libbpf test prog which feeds bpf_get_task_stack's return value
> into seq_write after confirming it's positive. No attempt to bound the
> value from above is made.
> 
> Load will fail if verifier does not refine retval range based on buf sz
> input to bpf_get_task_stack.
> 
> Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>

Acked-by: Song Liu <songliubraving@fb.com>

With one nit below. 


> ---
> .../selftests/bpf/prog_tests/bpf_iter.c       |  1 +
> .../selftests/bpf/progs/bpf_iter_task_stack.c | 22 +++++++++++++++++++
> 2 files changed, 23 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> index 74c45d557a2b..2d3590cfb5e1 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> @@ -147,6 +147,7 @@ static void test_task_stack(void)
> 		return;
> 
> 	do_dummy_read(skel->progs.dump_task_stack);
> +	do_dummy_read(skel->progs.get_task_user_stacks);
> 
> 	bpf_iter_task_stack__destroy(skel);
> }
> diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c b/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c
> index 50e59a2e142e..c60048ed226f 100644
> --- a/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c
> +++ b/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c
> @@ -35,3 +35,25 @@ int dump_task_stack(struct bpf_iter__task *ctx)
> 
> 	return 0;
> }
> +
> +SEC("iter/task")
> +int get_task_user_stacks(struct bpf_iter__task *ctx)
> +{
> +	struct seq_file *seq = ctx->meta->seq;
> +	struct task_struct *task = ctx->task;
> +	uint64_t buf_sz = 0;
> +	int64_t res;
> +
> +	if (task == (void *)0)
> +		return 0;
> +
> +	res = bpf_get_task_stack(task, entries,
> +			MAX_STACK_TRACE_DEPTH * SIZE_OF_ULONG, BPF_F_USER_STACK);
> +	if (res <= 0)
> +		return 0;
> +
> +	buf_sz += res;
> +
nit: When the test fails because of missing the verifier change, a comment here
would help the debug effort. 

> +	bpf_seq_write(seq, &entries, buf_sz);
> +	return 0;
> +}
> -- 
> 2.30.2
> 


      reply	other threads:[~2021-04-16 17:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16  2:55 [PATCH bpf-next 0/3] bpf: refine retval for bpf_get_task_stack helper Dave Marchevsky
2021-04-16  2:55 ` [PATCH bpf-next 1/3] " Dave Marchevsky
2021-04-16 16:53   ` Song Liu
2021-04-16  2:55 ` [PATCH bpf-next 2/3] bpf/selftests: add bpf_get_task_stack retval bounds verifier test Dave Marchevsky
2021-04-16 17:09   ` Song Liu
2021-04-16  2:55 ` [PATCH bpf-next 3/3] bpf/selftests: add bpf_get_task_stack retval bounds test_prog Dave Marchevsky
2021-04-16 17:06   ` Song Liu [this message]

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=7E5C38DC-DCAA-4905-A289-1C339748E3DB@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=yhs@fb.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).