aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2016-11-29 07:09:45 -0500
committerDavid S. Miller <davem@davemloft.net>2016-11-30 14:14:07 -0500
commita3c18422a4b4e108bcf6a2328f48867e1003fd95 (patch)
treeeeca3ead29ffaf135c31d9a11b29b082766b22cc /net
parent0382a25af3c771a8e4d5e417d1834cbe28c2aaac (diff)
l2tp: hold socket before dropping lock in l2tp_ip{, 6}_recv()
Socket must be held while under the protection of the l2tp lock; there is no guarantee that sk remains valid after the read_unlock_bh() call. Same issue for l2tp_ip and l2tp_ip6. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/l2tp/l2tp_ip.c11
-rw-r--r--net/l2tp/l2tp_ip6.c11
2 files changed, 12 insertions, 10 deletions
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 1f57094d3111..4d1c942cc91b 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -183,14 +183,15 @@ pass_up:
183 183
184 read_lock_bh(&l2tp_ip_lock); 184 read_lock_bh(&l2tp_ip_lock);
185 sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id); 185 sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id);
186 if (!sk) {
187 read_unlock_bh(&l2tp_ip_lock);
188 goto discard;
189 }
190
191 sock_hold(sk);
186 read_unlock_bh(&l2tp_ip_lock); 192 read_unlock_bh(&l2tp_ip_lock);
187 } 193 }
188 194
189 if (sk == NULL)
190 goto discard;
191
192 sock_hold(sk);
193
194 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) 195 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
195 goto discard_put; 196 goto discard_put;
196 197
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index af9abfff637c..e3fc7786f188 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -198,14 +198,15 @@ pass_up:
198 read_lock_bh(&l2tp_ip6_lock); 198 read_lock_bh(&l2tp_ip6_lock);
199 sk = __l2tp_ip6_bind_lookup(net, &iph->daddr, 199 sk = __l2tp_ip6_bind_lookup(net, &iph->daddr,
200 0, tunnel_id); 200 0, tunnel_id);
201 if (!sk) {
202 read_unlock_bh(&l2tp_ip6_lock);
203 goto discard;
204 }
205
206 sock_hold(sk);
201 read_unlock_bh(&l2tp_ip6_lock); 207 read_unlock_bh(&l2tp_ip6_lock);
202 } 208 }
203 209
204 if (sk == NULL)
205 goto discard;
206
207 sock_hold(sk);
208
209 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) 210 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
210 goto discard_put; 211 goto discard_put;
211 212