netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Vernet <void@manifault.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: davem@davemloft.net, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@kernel.org, davemarchevsky@meta.com, tj@kernel.org,
	memxor@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org,
	kernel-team@fb.com
Subject: Re: [PATCH bpf-next 3/3] selftests/bpf: Add various tests to check helper access into ptr_to_btf_id.
Date: Mon, 13 Mar 2023 19:15:12 -0500	[thread overview]
Message-ID: <20230314001512.GC202344@maniforge> (raw)
In-Reply-To: <20230313235845.61029-4-alexei.starovoitov@gmail.com>

On Mon, Mar 13, 2023 at 04:58:45PM -0700, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Add various tests to check helper access into ptr_to_btf_id.
> 
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Thanks a lot for the quick turnaround on this.

LGTM, just left one small nit below.

Acked-by: David Vernet <void@manifault.com>

> ---
>  .../selftests/bpf/progs/task_kfunc_failure.c  | 36 +++++++++++++++++++
>  .../selftests/bpf/progs/task_kfunc_success.c  |  4 +++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
> index 002c7f69e47f..27994d6b2914 100644
> --- a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
> +++ b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
> @@ -301,3 +301,39 @@ int BPF_PROG(task_kfunc_from_lsm_task_free, struct task_struct *task)
>  	bpf_task_release(acquired);
>  	return 0;
>  }
> +
> +SEC("tp_btf/task_newtask")
> +__failure __msg("access beyond the end of member comm")
> +int BPF_PROG(task_access_comm1, struct task_struct *task, u64 clone_flags)
> +{
> +	bpf_strncmp(task->comm, 17, "foo");

Instead of 17, can you do either TASK_COMM_LEN + 1, or
sizeof(task->comm) + 1, to make the test a bit less brittle? Applies to
the other testcases as well.

> +	return 0;
> +}
> +
> +SEC("tp_btf/task_newtask")
> +__failure __msg("access beyond the end of member comm")
> +int BPF_PROG(task_access_comm2, struct task_struct *task, u64 clone_flags)
> +{
> +	bpf_strncmp(task->comm + 1, 16, "foo");
> +	return 0;
> +}
> +
> +SEC("tp_btf/task_newtask")
> +__failure __msg("write into memory")
> +int BPF_PROG(task_access_comm3, struct task_struct *task, u64 clone_flags)
> +{
> +	bpf_probe_read_kernel(task->comm, 16, task->comm);
> +	return 0;
> +}
> +
> +SEC("fentry/__set_task_comm")
> +__failure __msg("R1 type=ptr_ expected")
> +int BPF_PROG(task_access_comm4, struct task_struct *task, const char *buf, bool exec)
> +{
> +	/*
> +	 * task->comm is a legacy ptr_to_btf_id. The verifier cannot guarantee
> +	 * its safety. Hence it cannot be accessed with normal load insns.
> +	 */
> +	bpf_strncmp(task->comm, 16, "foo");
> +	return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_success.c b/tools/testing/selftests/bpf/progs/task_kfunc_success.c
> index aebc4bb14e7d..4f61596b0242 100644
> --- a/tools/testing/selftests/bpf/progs/task_kfunc_success.c
> +++ b/tools/testing/selftests/bpf/progs/task_kfunc_success.c
> @@ -207,6 +207,10 @@ int BPF_PROG(test_task_from_pid_invalid, struct task_struct *task, u64 clone_fla
>  	if (!is_test_kfunc_task())
>  		return 0;
>  
> +	bpf_strncmp(task->comm, 12, "foo");
> +	bpf_strncmp(task->comm, 16, "foo");
> +	bpf_strncmp(&task->comm[8], 4, "foo");
> +
>  	if (is_pid_lookup_valid(-1)) {
>  		err = 1;
>  		return 0;
> -- 
> 2.34.1
> 

  reply	other threads:[~2023-03-14  0:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13 23:58 [PATCH bpf-next 0/3] bpf: Allow helpers access ptr_to_btf_id Alexei Starovoitov
2023-03-13 23:58 ` [PATCH bpf-next 1/3] bpf: Fix bpf_strncmp proto Alexei Starovoitov
2023-03-14  0:02   ` David Vernet
2023-03-13 23:58 ` [PATCH bpf-next 2/3] bpf: Allow helpers access trusted PTR_TO_BTF_ID Alexei Starovoitov
2023-03-14  0:07   ` David Vernet
2023-03-13 23:58 ` [PATCH bpf-next 3/3] selftests/bpf: Add various tests to check helper access into ptr_to_btf_id Alexei Starovoitov
2023-03-14  0:15   ` David Vernet [this message]
2023-03-14  0:19     ` Alexei Starovoitov
2023-03-14  5:33 ` [PATCH bpf-next 0/3] bpf: Allow helpers access ptr_to_btf_id John Fastabend
2023-03-14  6:40 ` patchwork-bot+netdevbpf

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=20230314001512.GC202344@maniforge \
    --to=void@manifault.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=davemarchevsky@meta.com \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=tj@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;
as well as URLs for NNTP newsgroup(s).