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

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 2bb90e5cc90e ("bpf:
sockmap, synchronize_rcu before free'ing map") which addressed sockmap,
which comes from a manual audit.

Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200206111652.694507-3-jakub@cloudflare.com

authored by

Jakub Sitnicki and committed by
Daniel Borkmann
0b2dc839 db6a5018

+4
+4
net/core/sock_map.c
··· 250 250 } 251 251 raw_spin_unlock_bh(&stab->lock); 252 252 253 + /* wait for psock readers accessing its map link */ 253 254 synchronize_rcu(); 254 255 255 256 bpf_map_area_free(stab->sks); ··· 877 876 } 878 877 raw_spin_unlock_bh(&bucket->lock); 879 878 } 879 + 880 + /* wait for psock readers accessing its map link */ 881 + synchronize_rcu(); 880 882 881 883 bpf_map_area_free(htab->buckets); 882 884 kfree(htab);