summaryrefslogtreecommitdiffstats
path: root/sys/netatm
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2005-02-21 21:58:17 +0000
committerrwatson <rwatson@FreeBSD.org>2005-02-21 21:58:17 +0000
commit26df80bf2cb36ff3fb93ad6eef085062a90896c6 (patch)
tree485f480fc21fe953c9c79e4896f5536a96968c9f /sys/netatm
parentbc73e0ad821773b13eec9322408d7da1c61edeb6 (diff)
downloadFreeBSD-src-26df80bf2cb36ff3fb93ad6eef085062a90896c6.zip
FreeBSD-src-26df80bf2cb36ff3fb93ad6eef085062a90896c6.tar.gz
In the current world order, solisten() implements the state transition of
a socket from a regular socket to a listening socket able to accept new connections. As part of this state transition, solisten() calls into the protocol to update protocol-layer state. There were several bugs in this implementation that could result in a race wherein a TCP SYN received in the interval between the protocol state transition and the shortly following socket layer transition would result in a panic in the TCP code, as the socket would be in the TCPS_LISTEN state, but the socket would not have the SO_ACCEPTCONN flag set. This change does the following: - Pushes the socket state transition from the socket layer solisten() to to socket "library" routines called from the protocol. This permits the socket routines to be called while holding the protocol mutexes, preventing a race exposing the incomplete socket state transition to TCP after the TCP state transition has completed. The check for a socket layer state transition is performed by solisten_proto_check(), and the actual transition is performed by solisten_proto(). - Holds the socket lock for the duration of the socket state test and set, and over the protocol layer state transition, which is now possible as the socket lock is acquired by the protocol layer, rather than vice versa. This prevents additional state related races in the socket layer. This permits the dual transition of socket layer and protocol layer state to occur while holding locks for both layers, making the two changes atomic with respect to one another. Similar changes are likely require elsewhere in the socket/protocol code. Reported by: Peter Holm <peter@holm.cc> Review and fixes from: emax, Antoine Brodin <antoine.brodin@laposte.net> Philosophical head nod: gnn
Diffstat (limited to 'sys/netatm')
-rw-r--r--sys/netatm/atm_cm.c14
-rw-r--r--sys/netatm/atm_socket.c2
-rw-r--r--sys/netatm/atm_var.h4
-rw-r--r--sys/netatm/ipatm/ipatm_load.c4
4 files changed, 18 insertions, 6 deletions
diff --git a/sys/netatm/atm_cm.c b/sys/netatm/atm_cm.c
index 2da05b3..60bf482 100644
--- a/sys/netatm/atm_cm.c
+++ b/sys/netatm/atm_cm.c
@@ -524,6 +524,7 @@ done:
* atm_cm_release().
*
* Arguments:
+ * so optional socket pointer -- if present, will set listen state
* epp pointer to endpoint definition structure
* token endpoint's listen instance token
* ap pointer to listening connection attributes
@@ -535,7 +536,8 @@ done:
*
*/
int
-atm_cm_listen(epp, token, ap, copp)
+atm_cm_listen(so, epp, token, ap, copp)
+ struct socket *so;
Atm_endpoint *epp;
void *token;
Atm_attributes *ap;
@@ -718,7 +720,13 @@ atm_cm_listen(epp, token, ap, copp)
/*
* Now try to register the listening connection
*/
+ if (so != NULL)
+ SOCK_LOCK(so);
s = splnet();
+ if (so != NULL)
+ err = solisten_proto_check(so);
+ if (err)
+ goto donex;
if (atm_cm_match(cop->co_lattr, NULL) != NULL) {
/*
* Can't have matching listeners
@@ -728,9 +736,13 @@ atm_cm_listen(epp, token, ap, copp)
}
cop->co_state = COS_LISTEN;
LINK2TAIL(cop, Atm_connection, atm_listen_queue, co_next);
+ if (so != NULL)
+ solisten_proto(so);
donex:
(void) splx(s);
+ if (so != NULL)
+ SOCK_UNLOCK(so);
done:
if (err) {
diff --git a/sys/netatm/atm_socket.c b/sys/netatm/atm_socket.c
index a851537..37ea86d 100644
--- a/sys/netatm/atm_socket.c
+++ b/sys/netatm/atm_socket.c
@@ -350,7 +350,7 @@ atm_sock_listen(so, epp)
/*
* Start listening for incoming calls
*/
- return (atm_cm_listen(epp, atp, &atp->atp_attr, &atp->atp_conn));
+ return (atm_cm_listen(so, epp, atp, &atp->atp_attr, &atp->atp_conn));
}
diff --git a/sys/netatm/atm_var.h b/sys/netatm/atm_var.h
index e014bf6..3332c92 100644
--- a/sys/netatm/atm_var.h
+++ b/sys/netatm/atm_var.h
@@ -81,8 +81,8 @@ void atm_aal5_init(void);
/* atm_cm.c */
int atm_cm_connect(Atm_endpoint *, void *, Atm_attributes *,
Atm_connection **);
-int atm_cm_listen(Atm_endpoint *, void *, Atm_attributes *,
- Atm_connection **);
+int atm_cm_listen(struct socket *, Atm_endpoint *, void *,
+ Atm_attributes *, Atm_connection **);
int atm_cm_addllc(Atm_endpoint *, void *, struct attr_llc *,
Atm_connection *, Atm_connection **);
int atm_cm_addparty(Atm_connection *, int, struct t_atm_sap *);
diff --git a/sys/netatm/ipatm/ipatm_load.c b/sys/netatm/ipatm/ipatm_load.c
index 3df5e8f..638c0ce 100644
--- a/sys/netatm/ipatm/ipatm_load.c
+++ b/sys/netatm/ipatm/ipatm_load.c
@@ -522,8 +522,8 @@ ipatm_start()
/*
* Now start listening
*/
- if ((err = atm_cm_listen(&ipatm_endpt, (void *)(intptr_t)i,
- &ipatm_listeners[i].attr,
+ if ((err = atm_cm_listen(NULL, &ipatm_endpt,
+ (void *)(intptr_t)i, &ipatm_listeners[i].attr,
&ipatm_listeners[i].conn)) != 0)
goto done;
}
OpenPOWER on IntegriCloud