Skip to content

Commit 0b2dc83

Browse files
jsitnickiborkmann
authored andcommitted
bpf, sockhash: Synchronize_rcu before free'ing map
We need to have a synchronize_rcu before free'ing the sockhash because any outstanding psock references will have a pointer to the map and when they use it, this could trigger a use after free. This is a sister fix for sockhash, following commit 2bb90e5 ("bpf: sockmap, synchronize_rcu before free'ing map") which addressed sockmap, which comes from a manual audit. Fixes: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Jakub Sitnicki <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent db6a501 commit 0b2dc83

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/core/sock_map.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ static void sock_map_free(struct bpf_map *map)
250250
}
251251
raw_spin_unlock_bh(&stab->lock);
252252

253+
/* wait for psock readers accessing its map link */
253254
synchronize_rcu();
254255

255256
bpf_map_area_free(stab->sks);
@@ -877,6 +878,9 @@ static void sock_hash_free(struct bpf_map *map)
877878
raw_spin_unlock_bh(&bucket->lock);
878879
}
879880

881+
/* wait for psock readers accessing its map link */
882+
synchronize_rcu();
883+
880884
bpf_map_area_free(htab->buckets);
881885
kfree(htab);
882886
}

0 commit comments

Comments
 (0)