Skip to content

Commit e68b60a

Browse files
Trond Myklebustgregkh
authored andcommitted
SUNRPC: Ensure we flush any closed sockets before xs_xprt_free()
commit f004320 upstream. We must ensure that all sockets are closed before we call xprt_free() and release the reference to the net namespace. The problem is that calling fput() will defer closing the socket until delayed_fput() gets called. Let's fix the situation by allowing rpciod and the transport teardown code (which runs on the system wq) to call __fput_sync(), and directly close the socket. Reported-by: Felix Fu <[email protected]> Acked-by: Al Viro <[email protected]> Fixes: a73881c ("SUNRPC: Fix an Oops in udp_poll()") Cc: [email protected] # 5.1.x: 3be232f: SUNRPC: Prevent immediate close+reconnect Cc: [email protected] # 5.1.x: 89f4249: SUNRPC: Don't call connect() more than once on a TCP socket Cc: [email protected] # 5.1.x Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Meena Shanmugam <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent dbe6974 commit e68b60a

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

fs/file_table.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ void __fput_sync(struct file *file)
376376
}
377377

378378
EXPORT_SYMBOL(fput);
379+
EXPORT_SYMBOL(__fput_sync);
379380

380381
void __init files_init(void)
381382
{

include/trace/events/sunrpc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ DEFINE_RPC_XPRT_LIFETIME_EVENT(connect);
10061006
DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_auto);
10071007
DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_done);
10081008
DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_force);
1009-
DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_cleanup);
10101009
DEFINE_RPC_XPRT_LIFETIME_EVENT(destroy);
10111010

10121011
DECLARE_EVENT_CLASS(rpc_xprt_event,

net/sunrpc/xprt.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,7 @@ void xprt_connect(struct rpc_task *task)
886886
if (!xprt_lock_write(xprt, task))
887887
return;
888888

889-
if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state)) {
890-
trace_xprt_disconnect_cleanup(xprt);
891-
xprt->ops->close(xprt);
892-
}
893-
894-
if (!xprt_connected(xprt)) {
889+
if (!xprt_connected(xprt) && !test_bit(XPRT_CLOSE_WAIT, &xprt->state)) {
895890
task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie;
896891
rpc_sleep_on_timeout(&xprt->pending, task, NULL,
897892
xprt_request_timeout(task->tk_rqstp));

net/sunrpc/xprtsock.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static int xs_local_send_request(struct rpc_rqst *req)
871871

872872
/* Close the stream if the previous transmission was incomplete */
873873
if (xs_send_request_was_aborted(transport, req)) {
874-
xs_close(xprt);
874+
xprt_force_disconnect(xprt);
875875
return -ENOTCONN;
876876
}
877877

@@ -909,7 +909,7 @@ static int xs_local_send_request(struct rpc_rqst *req)
909909
-status);
910910
fallthrough;
911911
case -EPIPE:
912-
xs_close(xprt);
912+
xprt_force_disconnect(xprt);
913913
status = -ENOTCONN;
914914
}
915915

@@ -1191,6 +1191,16 @@ static void xs_reset_transport(struct sock_xprt *transport)
11911191

11921192
if (sk == NULL)
11931193
return;
1194+
/*
1195+
* Make sure we're calling this in a context from which it is safe
1196+
* to call __fput_sync(). In practice that means rpciod and the
1197+
* system workqueue.
1198+
*/
1199+
if (!(current->flags & PF_WQ_WORKER)) {
1200+
WARN_ON_ONCE(1);
1201+
set_bit(XPRT_CLOSE_WAIT, &xprt->state);
1202+
return;
1203+
}
11941204

11951205
if (atomic_read(&transport->xprt.swapper))
11961206
sk_clear_memalloc(sk);
@@ -1214,7 +1224,7 @@ static void xs_reset_transport(struct sock_xprt *transport)
12141224
mutex_unlock(&transport->recv_mutex);
12151225

12161226
trace_rpc_socket_close(xprt, sock);
1217-
fput(filp);
1227+
__fput_sync(filp);
12181228

12191229
xprt_disconnect_done(xprt);
12201230
}

0 commit comments

Comments
 (0)