mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Wentao Liang <vulab@iscas.ac.cn>, Dai.Ngo@oracle.com
Cc: akpm@osdl.org, chuck.lever@oracle.com,
	linux-kernel@vger.kernel.org,  linux-nfs@vger.kernel.org,
	neil@brown.name, okorniev@redhat.com, tom@talpey.com,
		stable@vger.kernel.org
Subject: Re: [PATCH] nfsd: Fix id-to-name cache entry leak in idtoname_parse()
Date: Thu, 17 Sep 2026 14:10:50 -0400	[thread overview]
Message-ID: <f0ce5336a4062ff88775f81ba26726085dcb95a2.camel@kernel.org> (raw)
In-Reply-To: <20260917163154.2162438-1-vulab@iscas.ac.cn>

On Thu, 2026-09-17 at 16:31 +0000, Wentao Liang wrote:
> idtoname_lookup() returns the id-to-name cache entry with a new
> reference. The name is parsed between the lookup and the update call,
> and when the parsed name is malformed (negative length or longer than
> IDMAP_NAMESZ), idtoname_parse() jumps to the error label without
> dropping the reference returned by idtoname_lookup(), leaking the cache
> entry.
> 
> Release the reference with cache_put() before taking the error exit.
> 
> Fixes: f9ecc921b5b5 ("[PATCH] knfsd: Use new cache code for name/id lookup caches")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  fs/nfsd/nfs4idmap.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
> index ba06d3d3e6dd..e0f1bebdf660 100644
> --- a/fs/nfsd/nfs4idmap.c
> +++ b/fs/nfsd/nfs4idmap.c
> @@ -252,8 +252,10 @@ idtoname_parse(struct cache_detail *cd, char *buf, int buflen)
>  	/* Name */
>  	error = -EINVAL;
>  	len = qword_get(&buf, buf1, PAGE_SIZE);
> -	if (len < 0 || len >= IDMAP_NAMESZ)
> +	if (len < 0 || len >= IDMAP_NAMESZ) {
> +		cache_put(&res->h, cd);
>  		goto out;
> +	}
>  	if (len == 0)
>  		set_bit(CACHE_NEGATIVE, &ent.h.flags);
>  	else

Looks like we have the same bug later if idtoname_update() fails too? I
think it would be better to restructure the code near the end of the
function for better error handling. Something like this maybe?

diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
index 4e5297593963..9fba65bb6ba4 100644
--- a/fs/nfsd/nfs4idmap.c
+++ b/fs/nfsd/nfs4idmap.c
@@ -255,7 +255,7 @@ idtoname_parse(struct cache_detail *cd, char *buf,
int buflen)
        error = -EINVAL;
        len = qword_get(&buf, buf1, PAGE_SIZE);
        if (len < 0 || len >= IDMAP_NAMESZ)
-               goto out;
+               goto out_put;
        if (len == 0)
                set_bit(CACHE_NEGATIVE, &ent.h.flags);
        else
@@ -263,10 +263,11 @@ idtoname_parse(struct cache_detail *cd, char
*buf, int buflen)
        error = -ENOMEM;
        res = idtoname_update(cd, &ent, res);
        if (res == NULL)
-               goto out;
+               goto out_put;
 
-       cache_put(&res->h, cd);
        error = 0;
+out_put:
+       cache_put(&res->h, cd);
 out:
        kfree(buf1);
        return error;

  reply	other threads:[~2026-09-17 18:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 16:31 Wentao Liang
2026-09-17 18:10 ` Jeff Layton [this message]
2026-09-17 18:53   ` Chuck Lever
2026-09-17 20:04     ` Jeff Layton
2026-09-18  1:57 ` Chuck Lever

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=f0ce5336a4062ff88775f81ba26726085dcb95a2.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=akpm@osdl.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    --cc=vulab@iscas.ac.cn \
    /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®