From: Andrii Nakryiko <andriin@fb.com>
Date: Tue, 28 Jul 2020 21:50:56 -0700
Subject: selftests/bpf: Don't destroy failed link
Patch-mainline: v5.9-rc1
Git-commit: 80546ac4586c0bd326aa7ce80f076646db02bcd0
References: bsc#1177028
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.
Fixes: 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200729045056.3363921-1-andriin@fb.com
Acked-by: Gary Lin <glin@suse.com>
---
tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c | 42 +++++++++-----
1 file changed, 28 insertions(+), 14 deletions(-)
--- 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_
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_cgr
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_cgrou
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);
}