* [PATCH net v1 1/3] tipc: Fix missing connection request handling
2017-04-26 8:04 [PATCH net v1 0/3] tipc: fix hanging socket connections Parthasarathy Bhuvaragan
@ 2017-04-26 8:05 ` Parthasarathy Bhuvaragan
2017-04-26 8:05 ` [PATCH net v1 2/3] tipc: improve error validations for sockets in CONNECTING state Parthasarathy Bhuvaragan
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Parthasarathy Bhuvaragan @ 2017-04-26 8:05 UTC (permalink / raw)
To: netdev; +Cc: tipc-discussion
In filter_connect, we use waitqueue_active() to check for any
connections to wakeup. But waitqueue_active() is missing memory
barriers while accessing the critical sections, leading to
inconsistent results.
In this commit, we replace this with an SMP safe wq_has_sleeper()
using the generic socket callback sk_data_ready().
Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
---
net/tipc/socket.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 566906795c8c..3b8df510a80c 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1581,8 +1581,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
return true;
/* If empty 'ACK-' message, wake up sleeping connect() */
- if (waitqueue_active(sk_sleep(sk)))
- wake_up_interruptible(sk_sleep(sk));
+ sk->sk_data_ready(sk);
/* 'ACK-' message is neither accepted nor rejected: */
msg_set_dest_droppable(hdr, 1);
--
2.1.4
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH net v1 2/3] tipc: improve error validations for sockets in CONNECTING state
2017-04-26 8:04 [PATCH net v1 0/3] tipc: fix hanging socket connections Parthasarathy Bhuvaragan
2017-04-26 8:05 ` [PATCH net v1 1/3] tipc: Fix missing connection request handling Parthasarathy Bhuvaragan
@ 2017-04-26 8:05 ` Parthasarathy Bhuvaragan
2017-04-26 8:05 ` [PATCH net v1 3/3] tipc: close the connection if protocol messages contain errors Parthasarathy Bhuvaragan
2017-04-28 16:20 ` [PATCH net v1 0/3] tipc: fix hanging socket connections David Miller
3 siblings, 0 replies; 5+ messages in thread
From: Parthasarathy Bhuvaragan @ 2017-04-26 8:05 UTC (permalink / raw)
To: netdev; +Cc: tipc-discussion
Until now, the checks for sockets in CONNECTING state was based on
the assumption that the incoming message was always from the
peer's accepted data socket.
However an application using a non-blocking socket sends an implicit
connect, this socket which is in CONNECTING state can receive error
messages from the peer's listening socket. As we discard these
messages, the application socket hangs as there due to inactivity.
In addition to this, there are other places where we process errors
but do not notify the user.
In this commit, we process such incoming error messages and notify
our users about them using sk_state_change().
Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
---
net/tipc/socket.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 3b8df510a80c..38c367f6ced4 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1259,7 +1259,10 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop)
struct sock *sk = sock->sk;
DEFINE_WAIT(wait);
long timeo = *timeop;
- int err;
+ int err = sock_error(sk);
+
+ if (err)
+ return err;
for (;;) {
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
@@ -1281,6 +1284,10 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop)
err = sock_intr_errno(timeo);
if (signal_pending(current))
break;
+
+ err = sock_error(sk);
+ if (err)
+ break;
}
finish_wait(sk_sleep(sk), &wait);
*timeop = timeo;
@@ -1551,6 +1558,8 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
struct sock *sk = &tsk->sk;
struct net *net = sock_net(sk);
struct tipc_msg *hdr = buf_msg(skb);
+ u32 pport = msg_origport(hdr);
+ u32 pnode = msg_orignode(hdr);
if (unlikely(msg_mcast(hdr)))
return false;
@@ -1558,18 +1567,28 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
switch (sk->sk_state) {
case TIPC_CONNECTING:
/* Accept only ACK or NACK message */
- if (unlikely(!msg_connected(hdr)))
- return false;
+ if (unlikely(!msg_connected(hdr))) {
+ if (pport != tsk_peer_port(tsk) ||
+ pnode != tsk_peer_node(tsk))
+ return false;
+
+ tipc_set_sk_state(sk, TIPC_DISCONNECTING);
+ sk->sk_err = ECONNREFUSED;
+ sk->sk_state_change(sk);
+ return true;
+ }
if (unlikely(msg_errcode(hdr))) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
sk->sk_err = ECONNREFUSED;
+ sk->sk_state_change(sk);
return true;
}
if (unlikely(!msg_isdata(hdr))) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
sk->sk_err = EINVAL;
+ sk->sk_state_change(sk);
return true;
}
--
2.1.4
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH net v1 3/3] tipc: close the connection if protocol messages contain errors
2017-04-26 8:04 [PATCH net v1 0/3] tipc: fix hanging socket connections Parthasarathy Bhuvaragan
2017-04-26 8:05 ` [PATCH net v1 1/3] tipc: Fix missing connection request handling Parthasarathy Bhuvaragan
2017-04-26 8:05 ` [PATCH net v1 2/3] tipc: improve error validations for sockets in CONNECTING state Parthasarathy Bhuvaragan
@ 2017-04-26 8:05 ` Parthasarathy Bhuvaragan
2017-04-28 16:20 ` [PATCH net v1 0/3] tipc: fix hanging socket connections David Miller
3 siblings, 0 replies; 5+ messages in thread
From: Parthasarathy Bhuvaragan @ 2017-04-26 8:05 UTC (permalink / raw)
To: netdev; +Cc: tipc-discussion
When a socket is shutting down, we notify the peer node about the
connection termination by reusing an incoming message if possible.
If the last received message was a connection acknowledgment
message, we reverse this message and set the error code to
TIPC_ERR_NO_PORT and send it to peer.
In tipc_sk_proto_rcv(), we never check for message errors while
processing the connection acknowledgment or probe messages. Thus
this message performs the usual flow control accounting and leaves
the session hanging.
In this commit, we terminate the connection when we receive such
error messages.
Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
---
net/tipc/socket.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 38c367f6ced4..bdce99f9407a 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -866,6 +866,14 @@ static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb,
if (!tsk_peer_msg(tsk, hdr))
goto exit;
+ if (unlikely(msg_errcode(hdr))) {
+ tipc_set_sk_state(sk, TIPC_DISCONNECTING);
+ tipc_node_remove_conn(sock_net(sk), tsk_peer_node(tsk),
+ tsk_peer_port(tsk));
+ sk->sk_state_change(sk);
+ goto exit;
+ }
+
tsk->probe_unacked = false;
if (mtyp == CONN_PROBE) {
--
2.1.4
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net v1 0/3] tipc: fix hanging socket connections
2017-04-26 8:04 [PATCH net v1 0/3] tipc: fix hanging socket connections Parthasarathy Bhuvaragan
` (2 preceding siblings ...)
2017-04-26 8:05 ` [PATCH net v1 3/3] tipc: close the connection if protocol messages contain errors Parthasarathy Bhuvaragan
@ 2017-04-28 16:20 ` David Miller
3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-04-28 16:20 UTC (permalink / raw)
To: parthasarathy.bhuvaragan; +Cc: netdev, tipc-discussion
From: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Date: Wed, 26 Apr 2017 10:04:59 +0200
> This patch series contains fixes for the socket layer to
> prevent hanging / stale connections.
Series applied, thank you.
^ permalink raw reply [flat|nested] 5+ messages in thread