Skip to content

Commit 9b30889

Browse files
committed
SUNRPC: Ensure we always close the socket after a connection shuts down
Ensure that we release the TCP socket once it is in the TCP_CLOSE or TCP_TIME_WAIT state (and only then) so that we don't confuse rkhunter and its ilk. Signed-off-by: Trond Myklebust <[email protected]>
1 parent e231c68 commit 9b30889

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

net/sunrpc/xprtsock.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,6 @@ static void xs_sock_reset_connection_flags(struct rpc_xprt *xprt)
807807
smp_mb__after_atomic();
808808
}
809809

810-
static void xs_sock_mark_closed(struct rpc_xprt *xprt)
811-
{
812-
xs_sock_reset_connection_flags(xprt);
813-
/* Mark transport as closed and wake up all pending tasks */
814-
xprt_disconnect_done(xprt);
815-
}
816-
817810
/**
818811
* xs_error_report - callback to handle TCP socket state errors
819812
* @sk: socket
@@ -833,9 +826,6 @@ static void xs_error_report(struct sock *sk)
833826
err = -sk->sk_err;
834827
if (err == 0)
835828
goto out;
836-
/* Is this a reset event? */
837-
if (sk->sk_state == TCP_CLOSE)
838-
xs_sock_mark_closed(xprt);
839829
dprintk("RPC: xs_error_report client %p, error=%d...\n",
840830
xprt, -err);
841831
trace_rpc_socket_error(xprt, sk->sk_socket, err);
@@ -1655,9 +1645,11 @@ static void xs_tcp_state_change(struct sock *sk)
16551645
if (test_and_clear_bit(XPRT_SOCK_CONNECTING,
16561646
&transport->sock_state))
16571647
xprt_clear_connecting(xprt);
1648+
clear_bit(XPRT_CLOSING, &xprt->state);
16581649
if (sk->sk_err)
16591650
xprt_wake_pending_tasks(xprt, -sk->sk_err);
1660-
xs_sock_mark_closed(xprt);
1651+
/* Trigger the socket release */
1652+
xs_tcp_force_close(xprt);
16611653
}
16621654
out:
16631655
read_unlock_bh(&sk->sk_callback_lock);
@@ -2265,14 +2257,19 @@ static void xs_tcp_shutdown(struct rpc_xprt *xprt)
22652257
{
22662258
struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
22672259
struct socket *sock = transport->sock;
2260+
int skst = transport->inet ? transport->inet->sk_state : TCP_CLOSE;
22682261

22692262
if (sock == NULL)
22702263
return;
2271-
if (xprt_connected(xprt)) {
2264+
switch (skst) {
2265+
default:
22722266
kernel_sock_shutdown(sock, SHUT_RDWR);
22732267
trace_rpc_socket_shutdown(xprt, sock);
2274-
} else
2268+
break;
2269+
case TCP_CLOSE:
2270+
case TCP_TIME_WAIT:
22752271
xs_reset_transport(transport);
2272+
}
22762273
}
22772274

22782275
static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,

0 commit comments

Comments
 (0)