diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-01-08 11:12:11 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-01-08 11:12:48 +0100 |
commit | 1058be94c269251bf3e39fa832b121296f347cd0 (patch) | |
tree | 931f04ba768a2002abb503d60743b239e35bb8ef | |
parent | 0c73927077d559570b35b50903e7aefe53bde529 (diff) |
socket: check for null socket before fishing out sport
Otherwise we could have a null pointer dereference.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/socket.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/socket.c b/src/socket.c index 7de45b9..8eefa87 100644 --- a/src/socket.c +++ b/src/socket.c @@ -36,13 +36,14 @@ static inline int send4(struct wireguard_device *wg, struct sk_buff *skb, struct rcu_read_lock_bh(); sock = rcu_dereference_bh(wg->sock4); - fl.fl4_sport = inet_sk(sock)->inet_sport; if (unlikely(!sock)) { ret = -ENONET; goto err; } + fl.fl4_sport = inet_sk(sock)->inet_sport; + if (cache) rt = dst_cache_get_ip4(cache, &fl.saddr); @@ -107,13 +108,14 @@ static inline int send6(struct wireguard_device *wg, struct sk_buff *skb, struct rcu_read_lock_bh(); sock = rcu_dereference_bh(wg->sock6); - fl.fl6_sport = inet_sk(sock)->inet_sport; if (unlikely(!sock)) { ret = -ENONET; goto err; } + fl.fl6_sport = inet_sk(sock)->inet_sport; + if (cache) dst = dst_cache_get_ip6(cache, &fl.saddr); |