@@ -136,47 +136,16 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb)
136136}
137137
138138#ifdef CONFIG_INET6_ESPINTCP
139- struct esp_tcp_sk {
140- struct sock * sk ;
141- struct rcu_head rcu ;
142- };
143-
144- static void esp_free_tcp_sk (struct rcu_head * head )
145- {
146- struct esp_tcp_sk * esk = container_of (head , struct esp_tcp_sk , rcu );
147-
148- sock_put (esk -> sk );
149- kfree (esk );
150- }
151-
152139static struct sock * esp6_find_tcp_sk (struct xfrm_state * x )
153140{
154141 struct xfrm_encap_tmpl * encap = x -> encap ;
155142 struct net * net = xs_net (x );
156- struct esp_tcp_sk * esk ;
157143 __be16 sport , dport ;
158- struct sock * nsk ;
159144 struct sock * sk ;
160145
161- sk = rcu_dereference (x -> encap_sk );
162- if (sk && sk -> sk_state == TCP_ESTABLISHED )
163- return sk ;
164-
165146 spin_lock_bh (& x -> lock );
166147 sport = encap -> encap_sport ;
167148 dport = encap -> encap_dport ;
168- nsk = rcu_dereference_protected (x -> encap_sk ,
169- lockdep_is_held (& x -> lock ));
170- if (sk && sk == nsk ) {
171- esk = kmalloc (sizeof (* esk ), GFP_ATOMIC );
172- if (!esk ) {
173- spin_unlock_bh (& x -> lock );
174- return ERR_PTR (- ENOMEM );
175- }
176- RCU_INIT_POINTER (x -> encap_sk , NULL );
177- esk -> sk = sk ;
178- call_rcu (& esk -> rcu , esp_free_tcp_sk );
179- }
180149 spin_unlock_bh (& x -> lock );
181150
182151 sk = __inet6_lookup_established (net , net -> ipv4 .tcp_death_row .hashinfo , & x -> id .daddr .in6 ,
@@ -189,20 +158,6 @@ static struct sock *esp6_find_tcp_sk(struct xfrm_state *x)
189158 return ERR_PTR (- EINVAL );
190159 }
191160
192- spin_lock_bh (& x -> lock );
193- nsk = rcu_dereference_protected (x -> encap_sk ,
194- lockdep_is_held (& x -> lock ));
195- if (encap -> encap_sport != sport ||
196- encap -> encap_dport != dport ) {
197- sock_put (sk );
198- sk = nsk ?: ERR_PTR (- EREMCHG );
199- } else if (sk == nsk ) {
200- sock_put (sk );
201- } else {
202- rcu_assign_pointer (x -> encap_sk , sk );
203- }
204- spin_unlock_bh (& x -> lock );
205-
206161 return sk ;
207162}
208163
@@ -215,8 +170,10 @@ static int esp_output_tcp_finish(struct xfrm_state *x, struct sk_buff *skb)
215170
216171 sk = esp6_find_tcp_sk (x );
217172 err = PTR_ERR_OR_ZERO (sk );
218- if (err )
173+ if (err ) {
174+ kfree_skb (skb );
219175 goto out ;
176+ }
220177
221178 bh_lock_sock (sk );
222179 if (sock_owned_by_user (sk ))
@@ -225,6 +182,8 @@ static int esp_output_tcp_finish(struct xfrm_state *x, struct sk_buff *skb)
225182 err = espintcp_push_skb (sk , skb );
226183 bh_unlock_sock (sk );
227184
185+ sock_put (sk );
186+
228187out :
229188 rcu_read_unlock ();
230189 return err ;
@@ -429,6 +388,8 @@ static struct ip_esp_hdr *esp6_output_tcp_encap(struct xfrm_state *x,
429388 if (IS_ERR (sk ))
430389 return ERR_CAST (sk );
431390
391+ sock_put (sk );
392+
432393 * lenp = htons (len );
433394 esph = (struct ip_esp_hdr * )(lenp + 1 );
434395
0 commit comments