All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: David Vernet <void@manifault.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	 andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
	yhs@fb.com,  john.fastabend@gmail.com, kpsingh@kernel.org,
	haoluo@google.com,  jolsa@kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add test for non-NULLable PTR_TO_BTF_IDs
Date: Fri, 2 Jun 2023 18:26:53 -0700	[thread overview]
Message-ID: <ZHqW3d2naDAZsmAs@google.com> (raw)
In-Reply-To: <20230602150112.1494194-2-void@manifault.com>

On 06/02, David Vernet wrote:
> In a recent patch, we taught the verifier that trusted PTR_TO_BTF_ID can
> never be NULL. This prevents the verifier from incorrectly failing to
> load certain programs where it gets confused and thinks a reference
> isn't dropped because it incorrectly assumes that a branch exists in
> which a NULL PTR_TO_BTF_ID pointer is never released.
> 
> This patch adds a testcase that verifies this cannot happen.
> 
> Signed-off-by: David Vernet <void@manifault.com>

Acked-by: Stanislav Fomichev <sdf@google.com>

I hope someone else can look at the actual change. It looks good to
me conceptually, but not sure what other parts it might affect.

> ---
>  .../selftests/bpf/prog_tests/cpumask.c        |  1 +
>  .../selftests/bpf/progs/cpumask_success.c     | 24 +++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/cpumask.c b/tools/testing/selftests/bpf/prog_tests/cpumask.c
> index cdf4acc18e4c..d89191440fb1 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cpumask.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cpumask.c
> @@ -70,5 +70,6 @@ void test_cpumask(void)
>  		verify_success(cpumask_success_testcases[i]);
>  	}
>  
> +	RUN_TESTS(cpumask_success);
>  	RUN_TESTS(cpumask_failure);
>  }
> diff --git a/tools/testing/selftests/bpf/progs/cpumask_success.c b/tools/testing/selftests/bpf/progs/cpumask_success.c
> index 2fcdd7f68ac7..602a88b03dbc 100644
> --- a/tools/testing/selftests/bpf/progs/cpumask_success.c
> +++ b/tools/testing/selftests/bpf/progs/cpumask_success.c
> @@ -5,6 +5,7 @@
>  #include <bpf/bpf_tracing.h>
>  #include <bpf/bpf_helpers.h>
>  
> +#include "bpf_misc.h"
>  #include "cpumask_common.h"
>  
>  char _license[] SEC("license") = "GPL";
> @@ -426,3 +427,26 @@ int BPF_PROG(test_global_mask_rcu, struct task_struct *task, u64 clone_flags)
>  
>  	return 0;
>  }
> +
> +SEC("tp_btf/task_newtask")
> +__success
> +int BPF_PROG(test_refcount_null_tracking, struct task_struct *task, u64 clone_flags)
> +{
> +	struct bpf_cpumask *mask1, *mask2;
> +
> +	mask1 = bpf_cpumask_create();
> +	mask2 = bpf_cpumask_create();
> +
> +	if (!mask1 || !mask2)
> +		goto free_masks_return;
> +
> +	bpf_cpumask_test_cpu(0, (const struct cpumask *)mask1);
> +	bpf_cpumask_test_cpu(0, (const struct cpumask *)mask2);
> +
> +free_masks_return:
> +	if (mask1)
> +		bpf_cpumask_release(mask1);
> +	if (mask2)
> +		bpf_cpumask_release(mask2);
> +	return 0;
> +}
> -- 
> 2.40.1
> 

  reply	other threads:[~2023-06-03  1:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02 15:01 [PATCH bpf-next 1/2] bpf: Teach verifier that trusted PTR_TO_BTF_ID pointers are non-NULL David Vernet
2023-06-02 15:01 ` [PATCH bpf-next 2/2] selftests/bpf: Add test for non-NULLable PTR_TO_BTF_IDs David Vernet
2023-06-03  1:26   ` Stanislav Fomichev [this message]
2023-06-05 21:40 ` [PATCH bpf-next 1/2] bpf: Teach verifier that trusted PTR_TO_BTF_ID pointers are non-NULL 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=ZHqW3d2naDAZsmAs@google.com \
    --to=sdf@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=song@kernel.org \
    --cc=void@manifault.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.