mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Ran Hongyun <ranhongyun1@huawei.com>,
	cel@kernel.org, trondmy@kernel.org, 	anna@kernel.org,
	viro@zeniv.linux.org.uk
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 chengzhihao1@huawei.com, yangerkun@huawei.com,
	yi.zhang@huawei.com
Subject: Re: [PATCH] lockd: fix NULL pointer dereference in nlmclnt_locks_release_private
Date: Mon, 17 Aug 2026 09:18:44 -0400	[thread overview]
Message-ID: <e7b2ae795a489a07f6f494b8f596f05db0ddc688.camel@kernel.org> (raw)
In-Reply-To: <20260817060820.963195-1-ranhongyun1@huawei.com>

On Mon, 2026-08-17 at 14:08 +0800, Ran Hongyun wrote:
> nlmclnt_locks_init_private() unconditionally sets fl->fl_ops even when
> nlmclnt_find_lockowner() returns NULL due to allocation failure. When
> locks_release_private() later sees a non-NULL fl_ops, it calls
> fl_release_private, which dereferences fl->fl_u.nfs_fl.owner.
> 
> nlmclnt_proc()
> 	nlmclnt_locks_init_private <----set fl->fl_ops unconditionally
> 		if (!fl->fl_u.nfs_fl.owner) <----forget to clear fl->fl_ops
> 
> locks_release_private()
> 	if (fl->fl_ops) <----fl->fl_ops is not NULL but owner is NULL
> 		fl->fl_ops->fl_release_private()
> 			nlmclnt_locks_release_private() <----NULL ptr dereference
> 
> Fix this by clearing fl_ops when nlmclnt_find_lockowner() fails in
> nlmclnt_proc(), so that locks_release_private() skips the
> fl_release_private call path.
> 
> Fixes: bf8848918d75 ("lockd: handle lockowner allocation failure in nlmclnt_proc()")
> Signed-off-by: Ran Hongyun <ranhongyun1@huawei.com>
> ---
>  fs/lockd/clntproc.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
> index f06faf577cea..4b54481fecd5 100644
> --- a/fs/lockd/clntproc.c
> +++ b/fs/lockd/clntproc.c
> @@ -176,6 +176,7 @@ int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl, void *dat
>  	if (!fl->fl_u.nfs_fl.owner) {
>  		/* lockowner allocation has failed */
>  		nlmclnt_release_call(call);
> +		fl->fl_ops = NULL;
>  		return -ENOMEM;
>  	}
>  	/* Set up the argument struct */

The fix looks correct, but I don't like the way that the initialization
and cleanup is spread across multiple functions. I think it would be
better to just get rid of nlmclnt_locks_init_private() altogether and
open code what it does in the single caller (nlmclnt_proc()). Then you
could just not initialize fl_ops if nlmclnt_find_lockowner() fails.

There's also another preexisting bug here. If the lockowner allocation
fails, this function also leaks the references taken in
nlmclnt_alloc_call().

Want to spin up a v2 that fixes all of this?
-- 
Jeff Layton <jlayton@kernel.org>

      reply	other threads:[~2026-08-17 13:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  6:08 Ran Hongyun
2026-08-17 13:18 ` Jeff Layton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7b2ae795a489a07f6f494b8f596f05db0ddc688.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=anna@kernel.org \
    --cc=cel@kernel.org \
    --cc=chengzhihao1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=ranhongyun1@huawei.com \
    --cc=trondmy@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®