mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lockd: Fix host reference leak in nlmclnt_recovery()
@ 2026-09-16  7:40 Wentao Liang
  2026-09-16 11:07 ` Jeff Layton
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-16  7:40 UTC (permalink / raw)
  To: Dai.Ngo
  Cc: anna, chuck.lever, jlayton, linux-kernel, linux-nfs, neil,
	okorniev, tom, trondmy, Wentao Liang, stable

In nlmclnt_recovery(), nlm_get_host(host) is called to take a reference
on the host before spawning the reclaimer thread via kthread_run(). If
kthread_run() fails, the reference is never released, and
host->h_reclaiming remains incremented, preventing subsequent reclaim
attempts.

Fix this by releasing the host reference with nlmclnt_release_host(host)
and resetting host->h_reclaiming to 0 on kthread_run() error.

Fixes: df94f000c46c ("lockd: convert reclaimer thread to kthread interface")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 fs/lockd/clntlock.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c
index 8fa30c42c92a..aba37847356c 100644
--- a/fs/lockd/clntlock.c
+++ b/fs/lockd/clntlock.c
@@ -216,10 +216,13 @@ nlmclnt_recovery(struct nlm_host *host)
 	if (!host->h_reclaiming++) {
 		nlm_get_host(host);
 		task = kthread_run(reclaimer, host, "%s-reclaim", host->h_name);
-		if (IS_ERR(task))
+		if (IS_ERR(task)) {
 			printk(KERN_ERR "lockd: unable to spawn reclaimer "
 				"thread. Locks for %s won't be reclaimed! "
 				"(%ld)\n", host->h_name, PTR_ERR(task));
+			host->h_reclaiming = 0;
+			nlmclnt_release_host(host);
+		}
 	}
 }
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] lockd: Fix host reference leak in nlmclnt_recovery()
  2026-09-16  7:40 [PATCH] lockd: Fix host reference leak in nlmclnt_recovery() Wentao Liang
@ 2026-09-16 11:07 ` Jeff Layton
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2026-09-16 11:07 UTC (permalink / raw)
  To: Wentao Liang, Dai.Ngo
  Cc: anna, chuck.lever, linux-kernel, linux-nfs, neil, okorniev, tom,
	trondmy, stable

On Wed, 2026-09-16 at 07:40 +0000, Wentao Liang wrote:
> In nlmclnt_recovery(), nlm_get_host(host) is called to take a reference
> on the host before spawning the reclaimer thread via kthread_run(). If
> kthread_run() fails, the reference is never released, and
> host->h_reclaiming remains incremented, preventing subsequent reclaim
> attempts.
> 
> Fix this by releasing the host reference with nlmclnt_release_host(host)
> and resetting host->h_reclaiming to 0 on kthread_run() error.
> 
> Fixes: df94f000c46c ("lockd: convert reclaimer thread to kthread interface")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  fs/lockd/clntlock.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c
> index 8fa30c42c92a..aba37847356c 100644
> --- a/fs/lockd/clntlock.c
> +++ b/fs/lockd/clntlock.c
> @@ -216,10 +216,13 @@ nlmclnt_recovery(struct nlm_host *host)
>  	if (!host->h_reclaiming++) {
>  		nlm_get_host(host);
>  		task = kthread_run(reclaimer, host, "%s-reclaim", host->h_name);
> -		if (IS_ERR(task))
> +		if (IS_ERR(task)) {
>  			printk(KERN_ERR "lockd: unable to spawn reclaimer "
>  				"thread. Locks for %s won't be reclaimed! "
>  				"(%ld)\n", host->h_name, PTR_ERR(task));
> +			host->h_reclaiming = 0;
> +			nlmclnt_release_host(host);
> +		}
>  	}
>  }
>  

Good catch!

Reviewed-by: Jeff Layton <jlayton@kernel.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-16 11:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16  7:40 [PATCH] lockd: Fix host reference leak in nlmclnt_recovery() Wentao Liang
2026-09-16 11:07 ` Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®