Skip to content

Commit b82ba72

Browse files
q2vendavem330
authored andcommitted
tcp: Iterate tb->bhash2 in inet_csk_bind_conflict().
Sockets in bhash are also linked to bhash2, but TIME_WAIT sockets are linked separately in tb2->deathrow. Let's replace tb->owners iteration in inet_csk_bind_conflict() with two iterations over tb2->owners and tb2->deathrow. This can be done safely under bhash's lock because socket insertion/ deletion in bhash2 happens with bhash's lock held. Note that twsk_for_each_bound_bhash() will be removed later. Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 58655bc commit b82ba72

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

net/ipv4/inet_connection_sock.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ static bool inet_bhash2_conflict(const struct sock *sk,
236236
return false;
237237
}
238238

239+
#define sk_for_each_bound_bhash(__sk, __tb2, __tb) \
240+
hlist_for_each_entry(__tb2, &(__tb)->bhash2, bhash_node) \
241+
sk_for_each_bound_bhash2(sk2, &(__tb2)->owners)
242+
243+
#define twsk_for_each_bound_bhash(__sk, __tb2, __tb) \
244+
hlist_for_each_entry(__tb2, &(__tb)->bhash2, bhash_node) \
245+
sk_for_each_bound_bhash2(sk2, &(__tb2)->deathrow)
246+
239247
/* This should be called only when the tb and tb2 hashbuckets' locks are held */
240248
static int inet_csk_bind_conflict(const struct sock *sk,
241249
const struct inet_bind_bucket *tb,
@@ -267,7 +275,15 @@ static int inet_csk_bind_conflict(const struct sock *sk,
267275
* in tb->owners and tb2->owners list belong
268276
* to the same net - the one this bucket belongs to.
269277
*/
270-
sk_for_each_bound(sk2, &tb->owners) {
278+
sk_for_each_bound_bhash(sk2, tb2, tb) {
279+
if (!inet_bind_conflict(sk, sk2, uid, relax, reuseport_cb_ok, reuseport_ok))
280+
continue;
281+
282+
if (inet_rcv_saddr_equal(sk, sk2, true))
283+
return true;
284+
}
285+
286+
twsk_for_each_bound_bhash(sk2, tb2, tb) {
271287
if (!inet_bind_conflict(sk, sk2, uid, relax, reuseport_cb_ok, reuseport_ok))
272288
continue;
273289

0 commit comments

Comments
 (0)