[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <AANLkTik-FQ7aF0Cp0NicERYLG1vFG4SAe4aeeMHzxNhO@mail.gmail.com>
Date: Wed, 15 Sep 2010 13:17:39 -0700
From: Tom Marshall <tdm.code@...il.com>
To: netdev@...r.kernel.org
Subject: Small problem with tcp_poll and RST
The code in tcp_poll seems to suffer from a race condition which can
result in POLLIN but not POLLOUT for an outbound socket connection to
a closed peer.
This can happen if, for example, the RST comes in immediately after
checking sk->sk_err. It is a small window of opportunity and so it
only happens rarely.
Note this code has remained pretty much unchanged in 2.6.x for years,
and the problem readily reproduces on a wide variety of systems (RHEL
5.x, Ubuntu 10.04, etc.)
I suppose it is arguable whether this is a bug or whether it deserves
to be fixed, but it did cause an issue with some (admittedly broken)
userspace code at my company.
I do not fully understand the intricacies of the interactions between
the TCP state machine and the tcp_poll function (which runs unlocked).
However, I did find that the below appears to fix the issue. Since
the overhead is minimal when the socket state does not change, it
should have very little performance impact.
unsigned char oldstate;
again:
oldstate = sk->sk_state;
/* body of tcp_poll */
if (sk->sk_state != oldstate)
goto again;
Thanks!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists