Skip to content

Commit f43cb0d

Browse files
lmbborkmann
authored andcommitted
selftests: bpf: Fix detach from sockmap tests
Fix sockmap tests which rely on old bpf_prog_dispatch behaviour. In the first case, the tests check that detaching without giving a program succeeds. Since these are not the desired semantics, invert the condition. In the second case, the clean up code doesn't supply the necessary program fds. Fixes: bb0de31 ("bpf: sockmap: Require attach_bpf_fd when detaching a program") Reported-by: Martin KaFai Lau <[email protected]> Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent c9a368f commit f43cb0d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tools/testing/selftests/bpf/test_maps.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -789,19 +789,19 @@ static void test_sockmap(unsigned int tasks, void *data)
789789
}
790790

791791
err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER);
792-
if (err) {
792+
if (!err) {
793793
printf("Failed empty parser prog detach\n");
794794
goto out_sockmap;
795795
}
796796

797797
err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT);
798-
if (err) {
798+
if (!err) {
799799
printf("Failed empty verdict prog detach\n");
800800
goto out_sockmap;
801801
}
802802

803803
err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT);
804-
if (err) {
804+
if (!err) {
805805
printf("Failed empty msg verdict prog detach\n");
806806
goto out_sockmap;
807807
}
@@ -1090,19 +1090,19 @@ static void test_sockmap(unsigned int tasks, void *data)
10901090
assert(status == 0);
10911091
}
10921092

1093-
err = bpf_prog_detach(map_fd_rx, __MAX_BPF_ATTACH_TYPE);
1093+
err = bpf_prog_detach2(parse_prog, map_fd_rx, __MAX_BPF_ATTACH_TYPE);
10941094
if (!err) {
10951095
printf("Detached an invalid prog type.\n");
10961096
goto out_sockmap;
10971097
}
10981098

1099-
err = bpf_prog_detach(map_fd_rx, BPF_SK_SKB_STREAM_PARSER);
1099+
err = bpf_prog_detach2(parse_prog, map_fd_rx, BPF_SK_SKB_STREAM_PARSER);
11001100
if (err) {
11011101
printf("Failed parser prog detach\n");
11021102
goto out_sockmap;
11031103
}
11041104

1105-
err = bpf_prog_detach(map_fd_rx, BPF_SK_SKB_STREAM_VERDICT);
1105+
err = bpf_prog_detach2(verdict_prog, map_fd_rx, BPF_SK_SKB_STREAM_VERDICT);
11061106
if (err) {
11071107
printf("Failed parser prog detach\n");
11081108
goto out_sockmap;

0 commit comments

Comments
 (0)