All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Hyunsol Mun <muumthf@gmail.com>, Chuck Lever <cel@kernel.org>,
	Trond Myklebust <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>
Cc: NeilBrown <neil@brown.name>,
	Olga Kornievskaia <okorniev@redhat.com>,
	 Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	Dan Carpenter <dan.carpenter@linaro.org>,
		linux-nfs@vger.kernel.org, stable@vger.kernel.org,
	bobtobabz@gmail.com
Subject: Re: [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe
Date: Wed, 02 Dec 2026 06:49:16 -0500	[thread overview]
Message-ID: <994d8c080ad4f455b2a5c66aaf44962ebfd589ed.camel@kernel.org> (raw)
In-Reply-To: <20261130083340.226981-1-muumthf@gmail.com>

On Mon, 2026-11-30 at 17:33 +0900, Hyunsol Mun wrote:
> XDR_QUADLEN() rounds a byte count up by adding three before dividing
> by four. On 32-bit systems, a length near UINT_MAX wraps the addition
> and can produce a zero word count. __xdr_inline_decode() then accepts
> the length without advancing the stream because its bounds checks
> operate on the wrapped result.
> 
> A malformed NFSv4 SETATTR request can supply UINT_MAX as the
> FATTR4_OWNER length. The zero word count bypasses the XDR bounds check,
> after which NFSD passes the original length to its name-to-ID mapper
> and attempts an oversized copy into a fixed-size stack buffer.
> 
> Dan Carpenter reported the XDR_QUADLEN() overflow in 2024. The proposed
> size_add() conversion was not usable because XDR_QUADLEN() is also
> required in integer constant expressions.
> 
> Use DIV_ROUND_UP_POW2(), which avoids the overflowing addition and
> remains a constant expression. The decoded word count for UINT_MAX is
> then 0x40000000, so the existing stream bounds check rejects the
> request.
> 
> On nfsd-testing 36fd4049e3c2, an unpatched i386 QEMU server returned
> NFS4ERR_NOFILEHANDLE for a normal-length control request. The UINT_MAX
> request reached do_name_to_id(), triggered a double fault, and panicked.
> With the patch, the control status was unchanged and the malformed
> request returned NFS4ERR_BADXDR without an Oops, warning, or panic.
> 
> The unpatched and patched i386 kernels and the patched x86-64 kernel
> built with GCC 13.3 and W=1. A patched x86-64 NFSv4.2 mount, write,
> fsync, readback, unlink, and unmount completed successfully.
> 
> The vulnerability research and validation were conducted by members of
> the Tobabz team as part of the Best of the Best 15th program.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/r/bbf929d6-18d2-4b7e-a660-a19460af0a3c@moroto.mountain
> Link: https://lore.kernel.org/oe-kbuild-all/202405100445.DwegLXyZ-lkp@intel.com/
> Cc: stable@vger.kernel.org
> Signed-off-by: Hyunsol Mun <muumthf@gmail.com>
> ---
>  include/linux/sunrpc/xdr.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
> index 2b33fc64be..46151478ee 100644
> --- a/include/linux/sunrpc/xdr.h
> +++ b/include/linux/sunrpc/xdr.h
> @@ -12,6 +12,7 @@
>  #define _SUNRPC_XDR_H_
>  
>  #include <linux/uio.h>
> +#include <linux/math.h>
>  #include <asm/byteorder.h>
>  #include <linux/unaligned.h>
>  #include <linux/scatterlist.h>
> @@ -29,7 +30,7 @@ struct rpc_rqst;
>  /*
>   * Buffer adjustment
>   */
> -#define XDR_QUADLEN(l)		(((l) + 3) >> 2)
> +#define XDR_QUADLEN(l)		DIV_ROUND_UP_POW2(l, XDR_UNIT)
>  
>  /*
>   * Generic opaque `network object.'
> 
> base-commit: 36fd4049e3c2bb901118e11be63bf7a7922bea8c

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

      parent reply	other threads:[~2026-12-02 11:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  8:33 [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe Hyunsol Mun
2026-11-30 18:58 ` Chuck Lever
2026-12-01  5:21   ` Dan Carpenter
2026-12-02 11:49 ` 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=994d8c080ad4f455b2a5c66aaf44962ebfd589ed.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=bobtobabz@gmail.com \
    --cc=cel@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=muumthf@gmail.com \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.