BPF Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH bpf-next] selftests/bpf: don't destroy failed link
@ 2020-07-29  4:50 Andrii Nakryiko
  2020-07-29  5:30 ` YiFei Zhu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2020-07-29  4:50 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel
  Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko, YiFei Zhu

Check that link is NULL or proper pointer before invoking bpf_link__destroy().
Not doing this causes crash in test_progs, when cg_storage_multi selftest
fails.

Cc: YiFei Zhu <zhuyifei@google.com>
Fixes: 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 .../bpf/prog_tests/cg_storage_multi.c         | 42 ++++++++++++-------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c b/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c
index c67d8c076a34..643dfa35419c 100644
--- a/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c
@@ -147,8 +147,10 @@ static void test_egress_only(int parent_cgroup_fd, int child_cgroup_fd)
 		goto close_bpf_object;
 
 close_bpf_object:
-	bpf_link__destroy(parent_link);
-	bpf_link__destroy(child_link);
+	if (!IS_ERR(parent_link))
+		bpf_link__destroy(parent_link);
+	if (!IS_ERR(child_link))
+		bpf_link__destroy(child_link);
 
 	cg_storage_multi_egress_only__destroy(obj);
 }
@@ -262,12 +264,18 @@ static void test_isolated(int parent_cgroup_fd, int child_cgroup_fd)
 		goto close_bpf_object;
 
 close_bpf_object:
-	bpf_link__destroy(parent_egress1_link);
-	bpf_link__destroy(parent_egress2_link);
-	bpf_link__destroy(parent_ingress_link);
-	bpf_link__destroy(child_egress1_link);
-	bpf_link__destroy(child_egress2_link);
-	bpf_link__destroy(child_ingress_link);
+	if (!IS_ERR(parent_egress1_link))
+		bpf_link__destroy(parent_egress1_link);
+	if (!IS_ERR(parent_egress2_link))
+		bpf_link__destroy(parent_egress2_link);
+	if (!IS_ERR(parent_ingress_link))
+		bpf_link__destroy(parent_ingress_link);
+	if (!IS_ERR(child_egress1_link))
+		bpf_link__destroy(child_egress1_link);
+	if (!IS_ERR(child_egress2_link))
+		bpf_link__destroy(child_egress2_link);
+	if (!IS_ERR(child_ingress_link))
+		bpf_link__destroy(child_ingress_link);
 
 	cg_storage_multi_isolated__destroy(obj);
 }
@@ -367,12 +375,18 @@ static void test_shared(int parent_cgroup_fd, int child_cgroup_fd)
 		goto close_bpf_object;
 
 close_bpf_object:
-	bpf_link__destroy(parent_egress1_link);
-	bpf_link__destroy(parent_egress2_link);
-	bpf_link__destroy(parent_ingress_link);
-	bpf_link__destroy(child_egress1_link);
-	bpf_link__destroy(child_egress2_link);
-	bpf_link__destroy(child_ingress_link);
+	if (!IS_ERR(parent_egress1_link))
+		bpf_link__destroy(parent_egress1_link);
+	if (!IS_ERR(parent_egress2_link))
+		bpf_link__destroy(parent_egress2_link);
+	if (!IS_ERR(parent_ingress_link))
+		bpf_link__destroy(parent_ingress_link);
+	if (!IS_ERR(child_egress1_link))
+		bpf_link__destroy(child_egress1_link);
+	if (!IS_ERR(child_egress2_link))
+		bpf_link__destroy(child_egress2_link);
+	if (!IS_ERR(child_ingress_link))
+		bpf_link__destroy(child_ingress_link);
 
 	cg_storage_multi_shared__destroy(obj);
 }
-- 
2.24.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: don't destroy failed link
  2020-07-29  4:50 [PATCH bpf-next] selftests/bpf: don't destroy failed link Andrii Nakryiko
@ 2020-07-29  5:30 ` YiFei Zhu
  2020-07-29  5:47 ` Song Liu
  2020-07-29 23:12 ` Daniel Borkmann
  2 siblings, 0 replies; 5+ messages in thread
From: YiFei Zhu @ 2020-07-29  5:30 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, netdev, ast, Daniel Borkmann, Andrii Nakryiko, kernel-team

On Tue, Jul 28, 2020 at 11:51 PM Andrii Nakryiko <andriin@fb.com> wrote:
>
> Check that link is NULL or proper pointer before invoking bpf_link__destroy().
> Not doing this causes crash in test_progs, when cg_storage_multi selftest
> fails.
>
> Cc: YiFei Zhu <zhuyifei@google.com>
> Fixes: 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>  .../bpf/prog_tests/cg_storage_multi.c         | 42 ++++++++++++-------
>  1 file changed, 28 insertions(+), 14 deletions(-)
>

Awesome! Thanks for the fix. I did not realize the return was a -errno
rather than NULL like open_and_load.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: don't destroy failed link
  2020-07-29  4:50 [PATCH bpf-next] selftests/bpf: don't destroy failed link Andrii Nakryiko
  2020-07-29  5:30 ` YiFei Zhu
@ 2020-07-29  5:47 ` Song Liu
  2020-07-29  6:16   ` Andrii Nakryiko
  2020-07-29 23:12 ` Daniel Borkmann
  2 siblings, 1 reply; 5+ messages in thread
From: Song Liu @ 2020-07-29  5:47 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, Networking, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Kernel Team, YiFei Zhu

On Tue, Jul 28, 2020 at 9:54 PM Andrii Nakryiko <andriin@fb.com> wrote:
>
> Check that link is NULL or proper pointer before invoking bpf_link__destroy().
> Not doing this causes crash in test_progs, when cg_storage_multi selftest
> fails.
>
> Cc: YiFei Zhu <zhuyifei@google.com>
> Fixes: 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

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

btw: maybe we can move the IS_ERR() check to bpf_link__destroy()?

> ---
>  .../bpf/prog_tests/cg_storage_multi.c         | 42 ++++++++++++-------
>  1 file changed, 28 insertions(+), 14 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c b/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c
> index c67d8c076a34..643dfa35419c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c
> @@ -147,8 +147,10 @@ static void test_egress_only(int parent_cgroup_fd, int child_cgroup_fd)
>                 goto close_bpf_object;
>
>  close_bpf_object:
> -       bpf_link__destroy(parent_link);
> -       bpf_link__destroy(child_link);
> +       if (!IS_ERR(parent_link))
> +               bpf_link__destroy(parent_link);
> +       if (!IS_ERR(child_link))
> +               bpf_link__destroy(child_link);
>
>         cg_storage_multi_egress_only__destroy(obj);
>  }
> @@ -262,12 +264,18 @@ static void test_isolated(int parent_cgroup_fd, int child_cgroup_fd)
>                 goto close_bpf_object;
>
>  close_bpf_object:
> -       bpf_link__destroy(parent_egress1_link);
> -       bpf_link__destroy(parent_egress2_link);
> -       bpf_link__destroy(parent_ingress_link);
> -       bpf_link__destroy(child_egress1_link);
> -       bpf_link__destroy(child_egress2_link);
> -       bpf_link__destroy(child_ingress_link);
> +       if (!IS_ERR(parent_egress1_link))
> +               bpf_link__destroy(parent_egress1_link);
> +       if (!IS_ERR(parent_egress2_link))
> +               bpf_link__destroy(parent_egress2_link);
> +       if (!IS_ERR(parent_ingress_link))
> +               bpf_link__destroy(parent_ingress_link);
> +       if (!IS_ERR(child_egress1_link))
> +               bpf_link__destroy(child_egress1_link);
> +       if (!IS_ERR(child_egress2_link))
> +               bpf_link__destroy(child_egress2_link);
> +       if (!IS_ERR(child_ingress_link))
> +               bpf_link__destroy(child_ingress_link);
>
>         cg_storage_multi_isolated__destroy(obj);
>  }
> @@ -367,12 +375,18 @@ static void test_shared(int parent_cgroup_fd, int child_cgroup_fd)
>                 goto close_bpf_object;
>
>  close_bpf_object:
> -       bpf_link__destroy(parent_egress1_link);
> -       bpf_link__destroy(parent_egress2_link);
> -       bpf_link__destroy(parent_ingress_link);
> -       bpf_link__destroy(child_egress1_link);
> -       bpf_link__destroy(child_egress2_link);
> -       bpf_link__destroy(child_ingress_link);
> +       if (!IS_ERR(parent_egress1_link))
> +               bpf_link__destroy(parent_egress1_link);
> +       if (!IS_ERR(parent_egress2_link))
> +               bpf_link__destroy(parent_egress2_link);
> +       if (!IS_ERR(parent_ingress_link))
> +               bpf_link__destroy(parent_ingress_link);
> +       if (!IS_ERR(child_egress1_link))
> +               bpf_link__destroy(child_egress1_link);
> +       if (!IS_ERR(child_egress2_link))
> +               bpf_link__destroy(child_egress2_link);
> +       if (!IS_ERR(child_ingress_link))
> +               bpf_link__destroy(child_ingress_link);
>
>         cg_storage_multi_shared__destroy(obj);
>  }
> --
> 2.24.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: don't destroy failed link
  2020-07-29  5:47 ` Song Liu
@ 2020-07-29  6:16   ` Andrii Nakryiko
  0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2020-07-29  6:16 UTC (permalink / raw)
  To: Song Liu
  Cc: Andrii Nakryiko, bpf, Networking, Alexei Starovoitov,
	Daniel Borkmann, Kernel Team, YiFei Zhu

On Tue, Jul 28, 2020 at 10:47 PM Song Liu <song@kernel.org> wrote:
>
> On Tue, Jul 28, 2020 at 9:54 PM Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > Check that link is NULL or proper pointer before invoking bpf_link__destroy().
> > Not doing this causes crash in test_progs, when cg_storage_multi selftest
> > fails.
> >
> > Cc: YiFei Zhu <zhuyifei@google.com>
> > Fixes: 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Acked-by: Song Liu <songliubraving@fb.com>
>
> btw: maybe we can move the IS_ERR() check to bpf_link__destroy()?

Yeah, given how common this mistake seems to be, that wouldn't be a bad idea.

>
> > ---
> >  .../bpf/prog_tests/cg_storage_multi.c         | 42 ++++++++++++-------
> >  1 file changed, 28 insertions(+), 14 deletions(-)
> >

[...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: don't destroy failed link
  2020-07-29  4:50 [PATCH bpf-next] selftests/bpf: don't destroy failed link Andrii Nakryiko
  2020-07-29  5:30 ` YiFei Zhu
  2020-07-29  5:47 ` Song Liu
@ 2020-07-29 23:12 ` Daniel Borkmann
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2020-07-29 23:12 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, netdev, ast; +Cc: andrii.nakryiko, kernel-team, YiFei Zhu

On 7/29/20 6:50 AM, Andrii Nakryiko wrote:
> Check that link is NULL or proper pointer before invoking bpf_link__destroy().
> Not doing this causes crash in test_progs, when cg_storage_multi selftest
> fails.
> 
> Cc: YiFei Zhu <zhuyifei@google.com>
> Fixes: 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29  4:50 [PATCH bpf-next] selftests/bpf: don't destroy failed link Andrii Nakryiko
2020-07-29  5:30 ` YiFei Zhu
2020-07-29  5:47 ` Song Liu
2020-07-29  6:16   ` Andrii Nakryiko
2020-07-29 23:12 ` Daniel Borkmann

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git