bpf, sockmap: fix race in sock_map_free()
[platform/kernel/linux-rpi.git] / net / core / sock_map.c
index 4f4bc16..ae6013a 100644 (file)
@@ -349,11 +349,13 @@ static void sock_map_free(struct bpf_map *map)
 
                sk = xchg(psk, NULL);
                if (sk) {
+                       sock_hold(sk);
                        lock_sock(sk);
                        rcu_read_lock();
                        sock_map_unref(sk, psk);
                        rcu_read_unlock();
                        release_sock(sk);
+                       sock_put(sk);
                }
        }