@@ -242,42 +242,40 @@ static int inet_csk_bind_conflict(const struct sock *sk,
242
242
const struct inet_bind2_bucket * tb2 , /* may be null */
243
243
bool relax , bool reuseport_ok )
244
244
{
245
- bool reuseport_cb_ok ;
246
- struct sock_reuseport * reuseport_cb ;
247
245
kuid_t uid = sock_i_uid ((struct sock * )sk );
246
+ struct sock_reuseport * reuseport_cb ;
247
+ bool reuseport_cb_ok ;
248
+ struct sock * sk2 ;
248
249
249
250
rcu_read_lock ();
250
251
reuseport_cb = rcu_dereference (sk -> sk_reuseport_cb );
251
252
/* paired with WRITE_ONCE() in __reuseport_(add|detach)_closed_sock */
252
253
reuseport_cb_ok = !reuseport_cb || READ_ONCE (reuseport_cb -> num_closed_socks );
253
254
rcu_read_unlock ();
254
255
255
- /*
256
- * Unlike other sk lookup places we do not check
256
+ /* Conflicts with an existing IPV6_ADDR_ANY (if ipv6) or INADDR_ANY (if
257
+ * ipv4) should have been checked already. We need to do these two
258
+ * checks separately because their spinlocks have to be acquired/released
259
+ * independently of each other, to prevent possible deadlocks
260
+ */
261
+ if (inet_use_bhash2_on_bind (sk ))
262
+ return tb2 && inet_bhash2_conflict (sk , tb2 , uid , relax ,
263
+ reuseport_cb_ok , reuseport_ok );
264
+
265
+ /* Unlike other sk lookup places we do not check
257
266
* for sk_net here, since _all_ the socks listed
258
267
* in tb->owners and tb2->owners list belong
259
268
* to the same net - the one this bucket belongs to.
260
269
*/
270
+ sk_for_each_bound (sk2 , & tb -> owners ) {
271
+ if (!inet_bind_conflict (sk , sk2 , uid , relax , reuseport_cb_ok , reuseport_ok ))
272
+ continue ;
261
273
262
- if (!inet_use_bhash2_on_bind (sk )) {
263
- struct sock * sk2 ;
264
-
265
- sk_for_each_bound (sk2 , & tb -> owners )
266
- if (inet_bind_conflict (sk , sk2 , uid , relax ,
267
- reuseport_cb_ok , reuseport_ok ) &&
268
- inet_rcv_saddr_equal (sk , sk2 , true))
269
- return true;
270
-
271
- return false;
274
+ if (inet_rcv_saddr_equal (sk , sk2 , true))
275
+ return true;
272
276
}
273
277
274
- /* Conflicts with an existing IPV6_ADDR_ANY (if ipv6) or INADDR_ANY (if
275
- * ipv4) should have been checked already. We need to do these two
276
- * checks separately because their spinlocks have to be acquired/released
277
- * independently of each other, to prevent possible deadlocks
278
- */
279
- return tb2 && inet_bhash2_conflict (sk , tb2 , uid , relax , reuseport_cb_ok ,
280
- reuseport_ok );
278
+ return false;
281
279
}
282
280
283
281
/* Determine if there is a bind conflict with an existing IPV6_ADDR_ANY (if ipv6) or
0 commit comments