Skip to content

Commit 5028027

Browse files
jrfastabborkmann
authored andcommitted
bpf: test_maps, only support ESTABLISHED socks
Ensure that sockets added to a sock{map|hash} that is not in the ESTABLISHED state is rejected. Fixes: 1aa12bd ("bpf: sockmap, add sock close() hook to remove socks") Signed-off-by: John Fastabend <[email protected]> Acked-by: Yonghong Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent b05545e commit 5028027

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/testing/selftests/bpf/test_maps.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,11 @@ static void test_sockmap(int tasks, void *data)
580580
/* Test update without programs */
581581
for (i = 0; i < 6; i++) {
582582
err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY);
583-
if (err) {
583+
if (i < 2 && !err) {
584+
printf("Allowed update sockmap '%i:%i' not in ESTABLISHED\n",
585+
i, sfd[i]);
586+
goto out_sockmap;
587+
} else if (i >= 2 && err) {
584588
printf("Failed noprog update sockmap '%i:%i'\n",
585589
i, sfd[i]);
586590
goto out_sockmap;
@@ -741,7 +745,7 @@ static void test_sockmap(int tasks, void *data)
741745
}
742746

743747
/* Test map update elem afterwards fd lives in fd and map_fd */
744-
for (i = 0; i < 6; i++) {
748+
for (i = 2; i < 6; i++) {
745749
err = bpf_map_update_elem(map_fd_rx, &i, &sfd[i], BPF_ANY);
746750
if (err) {
747751
printf("Failed map_fd_rx update sockmap %i '%i:%i'\n",
@@ -845,7 +849,7 @@ static void test_sockmap(int tasks, void *data)
845849
}
846850

847851
/* Delete the elems without programs */
848-
for (i = 0; i < 6; i++) {
852+
for (i = 2; i < 6; i++) {
849853
err = bpf_map_delete_elem(fd, &i);
850854
if (err) {
851855
printf("Failed delete sockmap %i '%i:%i'\n",

0 commit comments

Comments
 (0)