All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Arnaldo Carvalho de Melo" <acme@redhat.com>
To: Stephen Hemminger <shemminger@linux-foundation.org>
Cc: "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org
Subject: Re: [PATCH] inet: race in wait for connect.
Date: Mon, 29 Oct 2007 19:29:06 -0200	[thread overview]
Message-ID: <20071029212906.GE21178@ghostprotocols.net> (raw)
In-Reply-To: <20071029135222.2ad073ff@freepuppy.rosehill>

Em Mon, Oct 29, 2007 at 01:52:22PM -0700, Stephen Hemminger escreveu:
> Fix possible race while waiting for connections in accept. I don't
> know of a test case that could reproduce this directly.
> 
> The state of the socket should be checked before checking the queue.
> If the socket has left the TCP_LISTEN state, then the accept queue
> is no longer valid.

Well if it left from LISTEN to CLOSED inet_csk_listen_stop must have
been called, and that calls reqsk_queue_yank_acceptq, that sets it to
NULL, reqsk_queue_empty(&icsk->icsk_accept_queue) returns true and we
get to if (sk->sk_state != TCP_LISTEN), returning -EINVAL as with your
patch.  So I can't see a race, just one branch less in one case :-)

- Arnaldo
 
> Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
> 
> --- a/net/ipv4/inet_connection_sock.c	2007-10-26 11:54:41.000000000 -0700
> +++ b/net/ipv4/inet_connection_sock.c	2007-10-29 08:34:03.000000000 -0700
> @@ -203,12 +203,12 @@ static int inet_csk_wait_for_connect(str
>  		if (reqsk_queue_empty(&icsk->icsk_accept_queue))
>  			timeo = schedule_timeout(timeo);
>  		lock_sock(sk);
> -		err = 0;
> -		if (!reqsk_queue_empty(&icsk->icsk_accept_queue))
> -			break;
>  		err = -EINVAL;
>  		if (sk->sk_state != TCP_LISTEN)
>  			break;
> +		err = 0;
> +		if (!reqsk_queue_empty(&icsk->icsk_accept_queue))
> +			break;
>  		err = sock_intr_errno(timeo);
>  		if (signal_pending(current))
>  			break;

  reply	other threads:[~2007-10-29 21:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-29 20:52 [PATCH] inet: race in wait for connect Stephen Hemminger
2007-10-29 21:29 ` Arnaldo Carvalho de Melo [this message]
2007-10-29 21:37   ` Stephen Hemminger
2007-10-29 22:38     ` David Miller
2007-10-29 23:16       ` Stephen Hemminger

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=20071029212906.GE21178@ghostprotocols.net \
    --to=acme@redhat.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.