summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSowmini Varadhan <sowmini.varadhan@oracle.com>2016-05-02 14:24:51 -0400
committerDavid S. Miller <davem@davemloft.net>2016-05-03 16:03:44 -0400
commiteb192840266fab3e3da644018121eed30153355d (patch)
tree882f8ee60fe758e2e78275cdf00349cce1878000 /net
parent42c8819b8d7245f54d5cfa6c2ec5a436818aeda9 (diff)
RDS:TCP: Synchronize rds_tcp_accept_one with rds_send_xmit when resetting t_sock
There is a race condition between rds_send_xmit -> rds_tcp_xmit and the code that deals with resolution of duelling syns added by commit 241b271952eb ("RDS-TCP: Reset tcp callbacks if re-using an outgoing socket in rds_tcp_accept_one()"). Specifically, we may end up derefencing a null pointer in rds_send_xmit if we have the interleaving sequence: rds_tcp_accept_one rds_send_xmit conn is RDS_CONN_UP, so invoke rds_tcp_xmit tc = conn->c_transport_data rds_tcp_restore_callbacks /* reset t_sock */ null ptr deref from tc->t_sock The race condition can be avoided without adding the overhead of additional locking in the xmit path: have rds_tcp_accept_one wait for rds_tcp_xmit threads to complete before resetting callbacks. The synchronization can be done in the same manner as rds_conn_shutdown(). First set the rds_conn_state to something other than RDS_CONN_UP (so that new threads cannot get into rds_tcp_xmit()), then wait for RDS_IN_XMIT to be cleared in the conn->c_flags indicating that any threads in rds_tcp_xmit are done. Fixes: 241b271952eb ("RDS-TCP: Reset tcp callbacks if re-using an outgoing socket in rds_tcp_accept_one()") Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com> Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/rds/tcp.c2
-rw-r--r--net/rds/tcp_listen.c40
2 files changed, 25 insertions, 17 deletions
diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index 61ed2a8764ba..9134544941c2 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -127,7 +127,7 @@ void rds_tcp_restore_callbacks(struct socket *sock,
127 127
128/* 128/*
129 * This is the only path that sets tc->t_sock. Send and receive trust that 129 * This is the only path that sets tc->t_sock. Send and receive trust that
130 * it is set. The RDS_CONN_CONNECTED bit protects those paths from being 130 * it is set. The RDS_CONN_UP bit protects those paths from being
131 * called while it isn't set. 131 * called while it isn't set.
132 */ 132 */
133void rds_tcp_set_callbacks(struct socket *sock, struct rds_connection *conn) 133void rds_tcp_set_callbacks(struct socket *sock, struct rds_connection *conn)
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 0936a4a32b47..0896187243d6 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -115,24 +115,32 @@ int rds_tcp_accept_one(struct socket *sock)
115 * rds_tcp_state_change() will do that cleanup 115 * rds_tcp_state_change() will do that cleanup
116 */ 116 */
117 rs_tcp = (struct rds_tcp_connection *)conn->c_transport_data; 117 rs_tcp = (struct rds_tcp_connection *)conn->c_transport_data;
118 if (rs_tcp->t_sock &&
119 ntohl(inet->inet_saddr) < ntohl(inet->inet_daddr)) {
120 struct sock *nsk = new_sock->sk;
121
122 nsk->sk_user_data = NULL;
123 nsk->sk_prot->disconnect(nsk, 0);
124 tcp_done(nsk);
125 new_sock = NULL;
126 ret = 0;
127 goto out;
128 } else if (rs_tcp->t_sock) {
129 rds_tcp_restore_callbacks(rs_tcp->t_sock, rs_tcp);
130 conn->c_outgoing = 0;
131 }
132
133 rds_conn_transition(conn, RDS_CONN_DOWN, RDS_CONN_CONNECTING); 118 rds_conn_transition(conn, RDS_CONN_DOWN, RDS_CONN_CONNECTING);
119 if (rs_tcp->t_sock) {
120 /* Need to resolve a duelling SYN between peers.
121 * We have an outstanding SYN to this peer, which may
122 * potentially have transitioned to the RDS_CONN_UP state,
123 * so we must quiesce any send threads before resetting
124 * c_transport_data.
125 */
126 wait_event(conn->c_waitq,
127 !test_bit(RDS_IN_XMIT, &conn->c_flags));
128 if (ntohl(inet->inet_saddr) < ntohl(inet->inet_daddr)) {
129 struct sock *nsk = new_sock->sk;
130
131 nsk->sk_user_data = NULL;
132 nsk->sk_prot->disconnect(nsk, 0);
133 tcp_done(nsk);
134 new_sock = NULL;
135 ret = 0;
136 goto out;
137 } else if (rs_tcp->t_sock) {
138 rds_tcp_restore_callbacks(rs_tcp->t_sock, rs_tcp);
139 conn->c_outgoing = 0;
140 }
141 }
134 rds_tcp_set_callbacks(new_sock, conn); 142 rds_tcp_set_callbacks(new_sock, conn);
135 rds_connect_complete(conn); 143 rds_connect_complete(conn); /* marks RDS_CONN_UP */
136 new_sock = NULL; 144 new_sock = NULL;
137 ret = 0; 145 ret = 0;
138 146