All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: Jean Tourrilhes <jt@hpl.hp.com>
Cc: Max Krasnyansky <maxk@qualcomm.com>,
	BlueZ Mailing List <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] Re: L2CAP non-blocking socket nasty race conditions
Date: Thu, 05 Feb 2004 19:17:37 +0100	[thread overview]
Message-ID: <1076005057.2806.7.camel@pegasus> (raw)
In-Reply-To: <20040205171919.GA5417@bougret.hpl.hp.com>

[-- Attachment #1: Type: text/plain, Size: 924 bytes --]

Hi Jean,

> > I had the attached patch in mind. Please check if this also works for
> > you, because it should produce less code execution. I think we can also
> > remove the list_empty() check from bt_sock_listen_poll(), because the
> > list_for_each_safe() gives us the same result.
> 
> 	This should produce the same result. I'll try.

attached is a slight modified version of my patch.

> > I already checked the IPV4 code and they also work with an accept queue,
> > but at the moment I don't understand when they put the new socket on it
> > and how they keep track of it.
> 
> 	Actually, I will double check, because I belive that it may be
> normal behavior. More later.

The TCP code uses its own open_request structure for the accept queue,
but I think the problem of non-blocking listen() will be the same as in
Bluetooth.

However the fix for the sendmsg() race is correct and must be applied.

Regards

Marcel


[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 1572 bytes --]

diff -urN linux-2.6.2/net/bluetooth/af_bluetooth.c linux-2.6.2-mh/net/bluetooth/af_bluetooth.c
--- linux-2.6.2/net/bluetooth/af_bluetooth.c	2004-02-04 04:43:16.000000000 +0100
+++ linux-2.6.2-mh/net/bluetooth/af_bluetooth.c	2004-02-05 18:56:16.000000000 +0100
@@ -236,15 +236,31 @@
 	return err ? : copied;
 }
 
+static inline unsigned int bt_accept_poll(struct sock *parent)
+{
+	struct list_head *p, *n;
+	struct sock *sk;
+
+	list_for_each_safe(p, n, &bt_sk(parent)->accept_q) {
+		sk = (struct sock *) list_entry(p, struct bt_sock, accept_q);
+		if (sk->sk_state == BT_CONNECTED)
+			return POLLIN | POLLRDNORM;
+	}
+
+	return 0;
+}
+
 unsigned int bt_sock_poll(struct file * file, struct socket *sock, poll_table *wait)
 {
 	struct sock *sk = sock->sk;
-	unsigned int mask;
+	unsigned int mask = 0;
 
 	BT_DBG("sock %p, sk %p", sock, sk);
 
 	poll_wait(file, sk->sk_sleep, wait);
-	mask = 0;
+
+	if (sk->sk_state == BT_LISTEN)
+		return bt_accept_poll(sk);
 
 	if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
 		mask |= POLLERR;
@@ -253,16 +269,17 @@
 		mask |= POLLHUP;
 
 	if (!skb_queue_empty(&sk->sk_receive_queue) || 
-			!list_empty(&bt_sk(sk)->accept_q) ||
 			(sk->sk_shutdown & RCV_SHUTDOWN))
 		mask |= POLLIN | POLLRDNORM;
 
 	if (sk->sk_state == BT_CLOSED)
 		mask |= POLLHUP;
 
-	if (sk->sk_state == BT_CONNECT || sk->sk_state == BT_CONNECT2)
+	if (sk->sk_state == BT_CONNECT ||
+			sk->sk_state == BT_CONNECT2 ||
+			sk->sk_state == BT_CONFIG)
 		return mask;
-	
+
 	if (sock_writeable(sk))
 		mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
 	else

  reply	other threads:[~2004-02-05 18:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-04  1:58 L2CAP non-blocking socket nasty race conditions Jean Tourrilhes
2004-02-04  7:17 ` [Bluez-devel] " Marcel Holtmann
2004-02-04 17:58   ` Jean Tourrilhes
2004-02-04 19:58     ` [Bluez-devel] " Marcel Holtmann
2004-02-04 21:45       ` Jean Tourrilhes
2004-02-05  1:00         ` [Bluez-devel] " Marcel Holtmann
2004-02-05  1:11           ` Jean Tourrilhes
2004-02-05  1:30             ` [Bluez-devel] " Marcel Holtmann
2004-02-05  1:40               ` Jean Tourrilhes
2004-02-05  2:21                 ` [Bluez-devel] " Marcel Holtmann
2004-02-05  2:26                   ` Jean Tourrilhes
2004-02-05  2:36                     ` [Bluez-devel] " Marcel Holtmann
2004-02-05  2:42                       ` Jean Tourrilhes
2004-02-05  3:30                       ` Jean Tourrilhes
2004-02-05 13:49                         ` [Bluez-devel] " Marcel Holtmann
2004-02-05 17:19                           ` Jean Tourrilhes
2004-02-05 18:17                             ` Marcel Holtmann [this message]
2004-02-05 23:13                               ` Jean Tourrilhes
2004-02-05 23:37                                 ` [Bluez-devel] " Marcel Holtmann
2004-02-05 23:43                                   ` Jean Tourrilhes
2004-02-04 11:23 ` [Bluez-devel] bluez & qos Mauro Tortonesi
2004-02-04 11:36   ` Marcel Holtmann
2004-02-04 17:46   ` [Bluez-devel] " Jean Tourrilhes
2004-02-05 10:46     ` Mauro Tortonesi
2004-02-05 17:22       ` Jean Tourrilhes

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=1076005057.2806.7.camel@pegasus \
    --to=marcel@holtmann.org \
    --cc=bluez-devel@lists.sourceforge.net \
    --cc=jt@hpl.hp.com \
    --cc=maxk@qualcomm.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 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.