diff options
Diffstat (limited to 'net/core/sock_map.c')
| -rw-r--r-- | net/core/sock_map.c | 18 | 
1 files changed, 16 insertions, 2 deletions
| diff --git a/net/core/sock_map.c b/net/core/sock_map.c index b08dfae10f88..00a26cf2cfe9 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -343,7 +343,14 @@ static struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key)  static void *sock_map_lookup(struct bpf_map *map, void *key)  { -	return __sock_map_lookup_elem(map, *(u32 *)key); +	struct sock *sk; + +	sk = __sock_map_lookup_elem(map, *(u32 *)key); +	if (!sk || !sk_fullsock(sk)) +		return NULL; +	if (sk_is_refcounted(sk) && !refcount_inc_not_zero(&sk->sk_refcnt)) +		return NULL; +	return sk;  }  static void *sock_map_lookup_sys(struct bpf_map *map, void *key) @@ -1051,7 +1058,14 @@ static void *sock_hash_lookup_sys(struct bpf_map *map, void *key)  static void *sock_hash_lookup(struct bpf_map *map, void *key)  { -	return __sock_hash_lookup_elem(map, key); +	struct sock *sk; + +	sk = __sock_hash_lookup_elem(map, key); +	if (!sk || !sk_fullsock(sk)) +		return NULL; +	if (sk_is_refcounted(sk) && !refcount_inc_not_zero(&sk->sk_refcnt)) +		return NULL; +	return sk;  }  static void sock_hash_release_progs(struct bpf_map *map) | 
