From: Benjamin Coddington Date: Fri, 3 Mar 2023 21:08:32 +0000 (-0500) Subject: SUNRPC: Fix a server shutdown leak X-Git-Tag: v6.2.7~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f74b3286859463cd63cc9d4aeaabd8b0c640182a;p=thirdparty%2Fkernel%2Fstable.git 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 Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index f06622814a958..7f9807374b0fb 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -786,6 +786,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; @@ -794,7 +795,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;