summary refs log tree commit diff
diff options
context:
space:
mode:
authorBenjamin Coddington <bcodding@redhat.com>2023-03-03 16:08:32 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-03-17 08:50:28 +0100
commit7a3720361068ab520aed4608bad31ea9a6cc7fe7 (patch)
tree2c6b819682dd6db613bc8934776de095d7c74f2a
parentb93ed36b31c3009b9bacc237ba6b01ab1bcf7d04 (diff)
downloadlinux-7a3720361068ab520aed4608bad31ea9a6cc7fe7.tar.gz
SUNRPC: Fix a server shutdown leak
[ Upstream commit 9ca6705d9d609441d34f8b853e1e4a6369b3b171 ]

Fix a race where kthread_stop() may prevent the threadfn from ever getting
called.  If that happens the svc_rqst will not be cleaned up.

Fixes: ed6473ddc704 ("NFSv4: Fix callback server shutdown")
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--net/sunrpc/svc.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 24577d1b9907..9ee32e06f877 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -787,6 +787,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 static int
 svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 {
+	struct svc_rqst	*rqstp;
 	struct task_struct *task;
 	unsigned int state = serv->sv_nrthreads-1;
 
@@ -795,7 +796,10 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 		task = choose_victim(serv, pool, &state);
 		if (task == NULL)
 			break;
-		kthread_stop(task);
+		rqstp = kthread_data(task);
+		/* Did we lose a race to svo_function threadfn? */
+		if (kthread_stop(task) == -EINTR)
+			svc_exit_thread(rqstp);
 		nrservs++;
 	} while (nrservs < 0);
 	return 0;