Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: bb0de3131f4c ("bpf: sockmap: Require attach_bpf_fd when detaching a program")
Reported-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/20200709115151.75829-1-lmb@cloudflare.com

authored by

Lorenz Bauer and committed by
Daniel Borkmann
f43cb0d6 c9a368f1

+6 -6
+6 -6
tools/testing/selftests/bpf/test_maps.c
··· 789 789 } 790 790 791 791 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER); 792 - if (err) { 792 + if (!err) { 793 793 printf("Failed empty parser prog detach\n"); 794 794 goto out_sockmap; 795 795 } 796 796 797 797 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT); 798 - if (err) { 798 + if (!err) { 799 799 printf("Failed empty verdict prog detach\n"); 800 800 goto out_sockmap; 801 801 } 802 802 803 803 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT); 804 - if (err) { 804 + if (!err) { 805 805 printf("Failed empty msg verdict prog detach\n"); 806 806 goto out_sockmap; 807 807 } ··· 1090 1090 assert(status == 0); 1091 1091 } 1092 1092 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); 1094 1094 if (!err) { 1095 1095 printf("Detached an invalid prog type.\n"); 1096 1096 goto out_sockmap; 1097 1097 } 1098 1098 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); 1100 1100 if (err) { 1101 1101 printf("Failed parser prog detach\n"); 1102 1102 goto out_sockmap; 1103 1103 } 1104 1104 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); 1106 1106 if (err) { 1107 1107 printf("Failed parser prog detach\n"); 1108 1108 goto out_sockmap;