Skip to content

tcp: Fix connect() races with timewait sockets

Eric Dumazet netdev netfilter 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tcp: Fix a connect() race with timewait socketsinclude/net/inet6_hashtables.h include/net/inet_hashtables.h net/dccp/ipv4.c +5 more+35 -175 replies
2/2tcp: Fix a connect() race with timewait socketsinclude/net/inet_timewait_sock.h net/ipv4/inet_hashtables.c net/ipv4/inet_timewait_sock.c+26 -81 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] tcp: Fix connect() races with timewait sockets
Quoted 11 lines · Eric Dumazet

[PATCH] tcp: Fix a connect() race with timewait sockets

When we find a timewait connection in __inet_hash_connect() and reuse it for a new connection request, we have a race window, releasing bind list lock and reacquiring it in __inet_twsk_kill() to remove timewait socket from list.

Another thread might find the timewait socket we already chose, leading to list corruption and crashes.

Fix is to remove timewait socket from bind list before releasing the lock.

I cooked two patches on top of net-next-2.6 to solve the two last race problems I am aware of.

Kapil, if you want to test them, make sure you take last net-next-2.6 snapshot.

First patch changes __inet_hash_nolisten() and __inet6_hash() to get a timewait parameter to be able to unhash it from ehash at same time the new socket is inserted into ehash.

Second patch is a respin of the first patch I sent :
It makes sure __inet_has_connect() cannot give same timewait socket to different threads.

Thanks !