public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Tom Marshall <tdm.code@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: Small problem with tcp_poll and RST
Date: Wed, 15 Sep 2010 22:41:47 +0200	[thread overview]
Message-ID: <1284583307.2462.29.camel@edumazet-laptop> (raw)
In-Reply-To: <AANLkTik-FQ7aF0Cp0NicERYLG1vFG4SAe4aeeMHzxNhO@mail.gmail.com>

Le mercredi 15 septembre 2010 à 13:17 -0700, Tom Marshall a écrit :
> 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;
> 

Hi Tom

Unfortunately this might shorten the race window.

Are you saying an application is blocked on a poll(events=POLLOUT) ?

If yes, we have a bug elsewhere (in RST processing)




      reply	other threads:[~2010-09-15 20:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-15 20:17 Small problem with tcp_poll and RST Tom Marshall
2010-09-15 20:41 ` Eric Dumazet [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284583307.2462.29.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=tdm.code@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox