mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									0382a25af3
								
							
						
					
					
						commit
						a3c18422a4
					
				
					 2 changed files with 12 additions and 10 deletions
				
			
		| 
						 | 
					@ -183,13 +183,14 @@ static int l2tp_ip_recv(struct sk_buff *skb)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		read_lock_bh(&l2tp_ip_lock);
 | 
							read_lock_bh(&l2tp_ip_lock);
 | 
				
			||||||
		sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id);
 | 
							sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id);
 | 
				
			||||||
 | 
							if (!sk) {
 | 
				
			||||||
			read_unlock_bh(&l2tp_ip_lock);
 | 
								read_unlock_bh(&l2tp_ip_lock);
 | 
				
			||||||
 | 
								goto discard;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (sk == NULL)
 | 
					 | 
				
			||||||
		goto discard;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		sock_hold(sk);
 | 
							sock_hold(sk);
 | 
				
			||||||
 | 
							read_unlock_bh(&l2tp_ip_lock);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
 | 
						if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
 | 
				
			||||||
		goto discard_put;
 | 
							goto discard_put;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -198,13 +198,14 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
 | 
				
			||||||
		read_lock_bh(&l2tp_ip6_lock);
 | 
							read_lock_bh(&l2tp_ip6_lock);
 | 
				
			||||||
		sk = __l2tp_ip6_bind_lookup(net, &iph->daddr,
 | 
							sk = __l2tp_ip6_bind_lookup(net, &iph->daddr,
 | 
				
			||||||
					    0, tunnel_id);
 | 
										    0, tunnel_id);
 | 
				
			||||||
 | 
							if (!sk) {
 | 
				
			||||||
			read_unlock_bh(&l2tp_ip6_lock);
 | 
								read_unlock_bh(&l2tp_ip6_lock);
 | 
				
			||||||
 | 
								goto discard;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (sk == NULL)
 | 
					 | 
				
			||||||
		goto discard;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		sock_hold(sk);
 | 
							sock_hold(sk);
 | 
				
			||||||
 | 
							read_unlock_bh(&l2tp_ip6_lock);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
 | 
						if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
 | 
				
			||||||
		goto discard_put;
 | 
							goto discard_put;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue