bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <song@kernel.org>
To: Andrii Nakryiko <andriin@fb.com>
Cc: bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Kernel Team <kernel-team@fb.com>, YiFei Zhu <zhuyifei@google.com>
Subject: Re: [PATCH bpf-next] selftests/bpf: don't destroy failed link
Date: Tue, 28 Jul 2020 22:47:15 -0700	[thread overview]
Message-ID: <CAPhsuW5e5B8AShod0frVaDdDA_5f3xeyd6gr9sTqUSy4YM1pBA@mail.gmail.com> (raw)
In-Reply-To: <20200729045056.3363921-1-andriin@fb.com>

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
>

  parent reply	other threads:[~2020-07-29  5:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-07-29  6:16   ` Andrii Nakryiko
2020-07-29 23:12 ` Daniel Borkmann

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=CAPhsuW5e5B8AShod0frVaDdDA_5f3xeyd6gr9sTqUSy4YM1pBA@mail.gmail.com \
    --to=song@kernel.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=zhuyifei@google.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).