Linux NFS development
 help / color / mirror / Atom feed
* [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe
@ 2026-11-30  8:33 Hyunsol Mun
  0 siblings, 0 replies; only message 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] only message in thread

only message in thread, other threads:[~2026-11-30  8:34 UTC | newest]

Thread overview: (only message) (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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox