Commit c5184717 authored by David S. Miller's avatar David S. Miller

Merge branch 'tipc-socket-connection-hangs'

Parthasarathy Bhuvaragan says:

====================
tipc: fix hanging socket connections

This patch series contains fixes for the socket layer to
prevent hanging / stale connections.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f8324608 c1be7756
...@@ -866,6 +866,14 @@ static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb, ...@@ -866,6 +866,14 @@ static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb,
if (!tsk_peer_msg(tsk, hdr)) if (!tsk_peer_msg(tsk, hdr))
goto exit; 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; tsk->probe_unacked = false;
if (mtyp == CONN_PROBE) { if (mtyp == CONN_PROBE) {
...@@ -1259,7 +1267,10 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop) ...@@ -1259,7 +1267,10 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop)
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
DEFINE_WAIT(wait); DEFINE_WAIT(wait);
long timeo = *timeop; long timeo = *timeop;
int err; int err = sock_error(sk);
if (err)
return err;
for (;;) { for (;;) {
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
...@@ -1281,6 +1292,10 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop) ...@@ -1281,6 +1292,10 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop)
err = sock_intr_errno(timeo); err = sock_intr_errno(timeo);
if (signal_pending(current)) if (signal_pending(current))
break; break;
err = sock_error(sk);
if (err)
break;
} }
finish_wait(sk_sleep(sk), &wait); finish_wait(sk_sleep(sk), &wait);
*timeop = timeo; *timeop = timeo;
...@@ -1551,6 +1566,8 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1551,6 +1566,8 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
struct sock *sk = &tsk->sk; struct sock *sk = &tsk->sk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct tipc_msg *hdr = buf_msg(skb); struct tipc_msg *hdr = buf_msg(skb);
u32 pport = msg_origport(hdr);
u32 pnode = msg_orignode(hdr);
if (unlikely(msg_mcast(hdr))) if (unlikely(msg_mcast(hdr)))
return false; return false;
...@@ -1558,18 +1575,28 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1558,18 +1575,28 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
switch (sk->sk_state) { switch (sk->sk_state) {
case TIPC_CONNECTING: case TIPC_CONNECTING:
/* Accept only ACK or NACK message */ /* Accept only ACK or NACK message */
if (unlikely(!msg_connected(hdr))) if (unlikely(!msg_connected(hdr))) {
return false; 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))) { if (unlikely(msg_errcode(hdr))) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING); tipc_set_sk_state(sk, TIPC_DISCONNECTING);
sk->sk_err = ECONNREFUSED; sk->sk_err = ECONNREFUSED;
sk->sk_state_change(sk);
return true; return true;
} }
if (unlikely(!msg_isdata(hdr))) { if (unlikely(!msg_isdata(hdr))) {
tipc_set_sk_state(sk, TIPC_DISCONNECTING); tipc_set_sk_state(sk, TIPC_DISCONNECTING);
sk->sk_err = EINVAL; sk->sk_err = EINVAL;
sk->sk_state_change(sk);
return true; return true;
} }
...@@ -1581,8 +1608,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) ...@@ -1581,8 +1608,7 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
return true; return true;
/* If empty 'ACK-' message, wake up sleeping connect() */ /* If empty 'ACK-' message, wake up sleeping connect() */
if (waitqueue_active(sk_sleep(sk))) sk->sk_data_ready(sk);
wake_up_interruptible(sk_sleep(sk));
/* 'ACK-' message is neither accepted nor rejected: */ /* 'ACK-' message is neither accepted nor rejected: */
msg_set_dest_droppable(hdr, 1); msg_set_dest_droppable(hdr, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment