selftests/bpf: don't destroy failed link
Subsystems (5)
PATCH 1/1 selftests/bpf: don't destroy failed link
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.
--- .../bpf/prog_tests/cg_storage_multi.c | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-)
tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c +28 -14
@@ -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); }
Signature · 1 line
2.24.1
Quoted 5 lines · Andrii Nakryiko
Check that link is NULL or proper pointer before invoking
bpf_link__destroy(). Not doing this causes crash intest_progs, whencg_storage_multiselftest fails.
Quoted 7 lines
Cc YiFei Zhu <[email protected]>Fixes 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")Signed-off-by Andrii Nakryiko <[email protected]>--- .../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.
Quoted 8 lines · Andrii Nakryiko
Check that link is NULL or proper pointer before invoking
bpf_link__destroy(). Not doing this causes crash intest_progs, whencg_storage_multiselftest fails.Cc YiFei Zhu <[email protected]>Fixes 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")Signed-off-by Andrii Nakryiko <[email protected]>
btw: maybe we can move the IS_ERR() check to bpf_link__destroy()?
Quoted 74 lines
--- .../bpf/prog_tests/cg_storage_multi.c | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-)tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c +28
-15@@ -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
Quoted 7 lines · Song Liu
Quoted 5 lines · Andrii Nakryiko
Check that link is NULL or proper pointer before invoking
bpf_link__destroy(). Not doing this causes crash intest_progs, whencg_storage_multiselftest fails.
Quoted 7 lines
Quoted 3 lines
Cc YiFei Zhu <[email protected]>Fixes 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")Signed-off-by Andrii Nakryiko <[email protected]>Acked-by Song Liu <[email protected]>btw: maybe we can move the
IS_ERR()check tobpf_link__destroy()?
Yeah, given how common this mistake seems to be, that wouldn't be a bad idea.
Quoted 5 lines
Quoted 5 lines
--- .../bpf/prog_tests/cg_storage_multi.c | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-)
[...]
Quoted 7 lines · Andrii Nakryiko
Check that link is NULL or proper pointer before invoking
bpf_link__destroy(). Not doing this causes crash intest_progs, whencg_storage_multiselftest fails.Cc YiFei Zhu <[email protected]>Fixes 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")Signed-off-by Andrii Nakryiko <[email protected]>
Applied, thanks!