* [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe
@ 2026-11-30 8:33 Hyunsol Mun
2026-11-30 18:58 ` Chuck Lever
2026-12-02 11:49 ` Jeff Layton
0 siblings, 2 replies; 4+ messages in thread
From: Hyunsol Mun @ 2026-11-30 8:33 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton, Trond Myklebust, Anna Schumaker
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Dan Carpenter,
linux-nfs, stable, bobtobabz
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
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe
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
1 sibling, 1 reply; 4+ messages in thread
From: Chuck Lever @ 2026-11-30 18:58 UTC (permalink / raw)
To: Jeff Layton, Trond Myklebust, Anna Schumaker, Hyunsol Mun
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs,
stable, bobtobabz, Dan Carpenter
On Mon, 30 Nov 2026 17:33:39 +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.
>
> [...]
Applied to nfsd-testing, thanks!
[1/1] SUNRPC: make XDR_QUADLEN() overflow-safe
commit: f61d4acd903a15bff7302f4aaa056f4c43d74858
--
Chuck Lever
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe
2026-11-30 18:58 ` Chuck Lever
@ 2026-12-01 5:21 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-12-01 5:21 UTC (permalink / raw)
To: Chuck Lever
Cc: Jeff Layton, Trond Myklebust, Anna Schumaker, Hyunsol Mun,
NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs,
stable, bobtobabz
On Mon, Nov 30, 2026 at 01:58:51PM -0500, Chuck Lever wrote:
> On Mon, 30 Nov 2026 17:33:39 +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.
> >
> > [...]
>
> Applied to nfsd-testing, thanks!
>
> [1/1] SUNRPC: make XDR_QUADLEN() overflow-safe
> commit: f61d4acd903a15bff7302f4aaa056f4c43d74858
Hooray!
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe
2026-11-30 8:33 [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe Hyunsol Mun
2026-11-30 18:58 ` Chuck Lever
@ 2026-12-02 11:49 ` Jeff Layton
1 sibling, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2026-12-02 11:49 UTC (permalink / raw)
To: Hyunsol Mun, Chuck Lever, Trond Myklebust, Anna Schumaker
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Dan Carpenter,
linux-nfs, stable, bobtobabz
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 11:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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.