NFSv4.1/pnfs: bound GETDEVICEINFO notification bitmap length
Subsystems (2)
cover NFSv4.1/pnfs: bound GETDEVICEINFO notification bitmap length
decode_getdeviceinfo() scales a server-supplied notification bitmap length by four for xdr_inline_decode(). The 32-bit multiply wraps to 0 for len >= 0x40000000, so the bounds check passes on an empty request and the verify loop reads up to ~2^30 words past the inline XDR buffer. A malicious or compromised pNFS server, or a man in the middle on an unprotected mount, can drive this out-of-bounds read while the client decodes a GETDEVICEINFO reply. It is a read, not a leak: the loop only checks each word for nonzero and returns -EIO on the first, so over-read contents are never returned.
A conformant reply uses a single notification word. Patch 1 bounds the length before the scale so it cannot wrap. Patch 2 adds KUnit coverage and is offered separately so it can be taken or dropped on its own.
Tested on QEMU x86_64 with KASAN: a Level-2 KUnit case drives the real decode_getdeviceinfo() and reports a slab-out-of-bounds read on stock, returning -EIO after patch 1; two benign controls drive the same decoder in bounds and pass on both stock and fixed trees.
Michael Bommarito (2):
NFSv4.1/pnfs: bound notification bitmap length in decode_getdeviceinfo NFSv4.1/pnfs: add KUnit coverage for GETDEVICEINFO notification decode
fs/nfs/Kconfig | 14 ++++ fs/nfs/getdeviceinfo_notify_kunit.c | 110 ++++++++++++++++++++++++++++ fs/nfs/nfs4xdr.c | 10 ++- include/linux/nfs4.h | 3 + 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 fs/nfs/getdeviceinfo_notify_kunit.c
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
Signature · 1 line
2.53.0
PATCH 1/2 NFSv4.1/pnfs: bound notification bitmap length in decode_getdeviceinfo
decode_getdeviceinfo() reads a server-supplied notification bitmap length into a u32 and scales it by four for xdr_inline_decode(). The multiply is 32-bit and wraps to 0 for len >= 0x40000000, so the !p bounds check passes on an empty request and the verify loop reads up to ~2^30 words past the inline XDR buffer. A malicious or compromised pNFS server, or a man in the middle on an unprotected mount, can drive this out-of-bounds read while the client decodes a GETDEVICEINFO reply.
RFC 8881 defines only the CHANGE and DELETE deviceid notification bits, both in word 0, so a conformant reply uses a single word. Bound len to NFS4_GETDEVICEINFO_NOTIFY_MAXWORDS before scaling, which cannot wrap and still tolerates trailing zero words the decoder keeps verifying.
Reproduced under KASAN on QEMU via a KUnit case driving the real decode_getdeviceinfo(); the out-of-bounds read is gone after this change.
---
Reproduction (v7.1-rc4, x86_64 QEMU/KVM, KASAN):
BUG: KASAN: slab-out-of-bounds in decode_getdeviceinfo
A KUnit case (patch 2) drives the real decode_getdeviceinfo() with a 0x40000000 notification length placed at a page edge; the wrapped 4*len multiply over-reads the receive buffer on stock and faults. Patched, the length is rejected with -EIO. Two benign in-bounds controls pass on both stock and patched. fs/nfs has no existing kselftest for this decoder.
fs/nfs/nfs4xdr.c | 6 +++++- include/linux/nfs4.h | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-)
fs/nfs/nfs4xdr.c +5 -1
@@ -6089,7 +6089,11 @@ static int decode_getdeviceinfo(struct xdr_stream *xdr,if (len) {uint32_t i; - p =xdr_inline_decode (xdr,4 * len); +/* Bound len so len << 2 cannot wrap and defeat the check below. */ +if (len >NFS4_GETDEVICEINFO_NOTIFY_MAXWORDS ) +return -EIO ; + + p =xdr_inline_decode (xdr, len <<2 );if (unlikely (!p))return -EIO ;
include/linux/nfs4.h +3 -0
@@ -752,6 +752,9 @@ enum pnfs_notify_deviceid_type4 { NOTIFY_DEVICEID4_DELETE = 1 << 2, }; +/* All defined deviceid notification bits live in word 0; bound the decoder. */ +#define NFS4_GETDEVICEINFO_NOTIFY_MAXWORDS 4 +enum pnfs_block_volume_type {PNFS_BLOCK_VOLUME_SIMPLE =0 ,PNFS_BLOCK_VOLUME_SLICE =1 ,
Signature · 1 line
2.53.0
PATCH 2/2 NFSv4.1/pnfs: add KUnit coverage for GETDEVICEINFO notification decode
In reply to Michael BommaritoAdd a KUnit suite driving the real file-local decode_getdeviceinfo() over a crafted GETDEVICEINFO reply to cover the notification-bitmap length pass. It is included into nfs4xdr.c (gated by CONFIG_NFS_GETDEVICEINFO_KUNIT_TEST) to reach the static decoder without exporting it.
A trigger supplies the wrapping length and two benign controls drive the same decoder in bounds. Integer overflow has no sanitizer, so the oracle is the downstream KASAN slab-out-of-bounds read: on QEMU x86_64 with KASAN the trigger faults on stock and passes after patch 1, while both controls pass on stock and fixed trees.
---
On QEMU x86_64 with KASAN: the trigger faults on stock (slab-out-of- bounds READ) and passes after patch 1; both benign controls pass on stock and patched. The suite builds the reply in a kmalloc(PAGE_SIZE) buffer with the notification fields in the XDR tail.
fs/nfs/Kconfig | 14 ++++ fs/nfs/getdeviceinfo_notify_kunit.c | 110 ++++++++++++++++++++++++++++ fs/nfs/nfs4xdr.c | 4 + 3 files changed, 128 insertions(+) create mode 100644 fs/nfs/getdeviceinfo_notify_kunit.c
fs/nfs/Kconfig +14 -0
@@ -215,3 +215,17 @@ config NFS_V4_2_READ_PLUS default y help Choose Y here to enable use of the NFS v4.2 READ_PLUS operation. + +config NFS_GETDEVICEINFO_KUNIT_TEST + tristate "KUnit test for pNFS GETDEVICEINFO notification decode" if !KUNIT_ALL_TESTS + depends on NFS_V4 && KUNIT + default KUNIT_ALL_TESTS + help + Builds KUnit coverage for the notification-bitmap length pass in + the NFS client pNFS GETDEVICEINFO reply decoder. The test drives + the real decode_getdeviceinfo() over a crafted reply and, on an + unfixed kernel built with CONFIG_KASAN, reports the slab-out-of- + bounds read caused by a 32-bit overflow in the notification-bitmap + length handling. + + If unsure, say N.
fs/nfs/getdeviceinfo_notify_kunit.c new file +100 -0
100 lines not on this page · raw message
fs/nfs/nfs4xdr.c +4 -0
@@ -7788,3 +7788,7 @@ const struct rpc_version nfs_version4 = { .procs = nfs4_procedures, .counts = nfs_version4_counts, }; + +#if IS_ENABLED (CONFIG_NFS_GETDEVICEINFO_KUNIT_TEST ) +#include "getdeviceinfo_notify_kunit.c" +#endif
Signature · 1 line
2.53.0