mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@gmail.com>
To: zhugl3@xiaopeng.com
Cc: anna@kernel.org, linux-nfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, 	liuwb@xiaopeng.com
Subject: Re: [PATCH] NFSv4: fix bitmap length check in decode_bitmap()
Date: Sun, 29 Nov 2026 17:04:46 -0500	[thread overview]
Message-ID: <413396f84dc887a43ccd3a752cd78ad58b7c1670.camel@gmail.com> (raw)
In-Reply-To: <20261012090834.920912-1-zhugl3@xiaopeng.com>

On Mon, 12 Oct 2026 17:08:34 +0800, Guanglei Zhu <zhugl3@xiaopeng.com>
wrote:
> Reject attrlen values larger than 3, the size of the bitmap array.

The wrap is real, but bitmap4 is a variable length array, and a
well-formed bitmap with four or more words, for instance one with
trailing zero words, is legal.  The current code accepts such a bitmap
in
CB_GETATTR and CB_RECALL_ANY, and ignores the words past bitmap[2].

[ ... ]

> + /* bitmap[] has only 3 words; also stops attrlen<<2 from wrapping
*/
> + if (unlikely(attrlen > 3))
> + return htonl(NFS4ERR_BADXDR);

Doesn't this make both of those callbacks fail with NFS4ERR_BADXDR for
such a bitmap?

Could the length be bounded without rejecting long bitmaps instead?
xdr_stream_decode_uint32_array() checks the count against
SIZE_MAX / sizeof(__be32) before it calls xdr_inline_decode(), and
returns
-EMSGSIZE for an array longer than the destination.  decode_bitmap4()
in
fs/nfs/nfs4xdr.c already treats that -EMSGSIZE as success.

Anna is also reworking this function in "NFS: Modernize the callback
decode_bitmap() function", and has said that her v2 will keep the
current
behaviour for long bitmaps, so the two changes would need to be
reconciled.

[ ... ]

I've dropped this from my testing branch for now.

On Mon, Oct 12, 2026 05:08 AM, Guanglei Zhu <zhugl3@xiaopeng.com>
wrote:
> decode_bitmap() reads attrlen from the callback message and passes
> attrlen << 2 to xdr_inline_decode() as the number of bytes to
> consume.  The shift is done in 32-bit arithmetic, so an attrlen of
> 0x40000000 wraps to zero, the bounds check in
> __xdr_inline_decode() passes, and the subsequent reads of
> bitmap[0..2] walk up to 12 bytes past the end of the received
> buffer.
> 
> Reject attrlen values larger than 3, the size of the bitmap array.
> 
> Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
> ---
> Verified with an ASAN build of an exact user-space replica of
> decode_bitmap() and __xdr_inline_decode(): attrlen=0x40000000 with
> the message ending right after the attrlen word results in a
> heap-buffer-overflow READ of size 4, 0 bytes after the allocation.
> 
>  fs/nfs/callback_xdr.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
> index 88e1af0fd..bea967e0c 100644
> --- a/fs/nfs/callback_xdr.c
> +++ b/fs/nfs/callback_xdr.c
> @@ -109,6 +109,9 @@ static __be32 decode_bitmap(struct xdr_stream
> *xdr, uint32_t *bitmap)
>         if (unlikely(p == NULL))
>                 return htonl(NFS4ERR_RESOURCE);
>         attrlen = ntohl(*p);
> +       /* bitmap[] has only 3 words; also stops attrlen<<2 from
> wrapping */
> +       if (unlikely(attrlen > 3))
> +               return htonl(NFS4ERR_BADXDR);
>         p = xdr_inline_decode(xdr, attrlen << 2);
>         if (unlikely(p == NULL))
>                 return htonl(NFS4ERR_RESOURCE);
> -- 
> 2.43.0
> 

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com

      reply	other threads:[~2026-11-29 22:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12  9:08 Guanglei Zhu
2026-11-29 22:04 ` Trond Myklebust [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=413396f84dc887a43ccd3a752cd78ad58b7c1670.camel@gmail.com \
    --to=trondmy@gmail.com \
    --cc=anna@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=liuwb@xiaopeng.com \
    --cc=zhugl3@xiaopeng.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®