* [PATCH 0/2] NFSv4/pNFS: fix client kernel panic from malformed GETDEVICEINFO
@ 2026-05-23 1:40 Michael Bommarito
2026-05-23 1:40 ` [PATCH 1/2] NFSv4/pNFS: reject zero-length r_addr in nfs4_decode_mp_ds_addr Michael Bommarito
2026-05-23 1:40 ` [PATCH 2/2] NFSv4/flexfile,filelayout: bound multipath DS count in GETDEVICEINFO Michael Bommarito
0 siblings, 2 replies; 4+ messages in thread
From: Michael Bommarito @ 2026-05-23 1:40 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: Jeff Layton, Tom Haynes, Peng Tao, Kees Cook, Mike Snitzer,
Tigran Mkrtchyan, linux-nfs, linux-kernel, stable
A malicious or compromised NFSv4.1+ pNFS metadata server can panic any
pNFS-flexfile client by returning a GETDEVICEINFO body with a
multipath-DS count of >= 3 and exactly one valid (netid, uaddr) pair.
The unbounded inner loop in nfs4_ff_alloc_deviceid_node() (and the
parallel site in nfs4_fl_alloc_deviceid_node() for the legacy file
layout) keeps iterating after the first netaddr is decoded, consuming
the trailing version_count / version / minor words of the body as
opaque netid + uaddr pairs. Both come out as zero-length strings;
xdr_stream_decode_string_dup() sets *str = NULL and returns 0; the
caller in nfs4_decode_mp_ds_addr() only checks "< 0" and immediately
calls strrchr(NULL, '.').
A QEMU/KASAN reproducer is described in the second patch. The
shortest crashing GETDEVICEINFO body is 56 bytes, the panic is 5/5
deterministic at multipath_count = 10, and it fires before any
user-level read can complete on the first pNFS file the client
touches.
Patch 1 closes the NULL dereference itself by changing the two
xdr_stream_decode_string_dup() return-value checks in
nfs4_decode_mp_ds_addr() from "< 0" to "<= 0". Patch 2 promotes
NFS4_PNFS_MAX_MULTI_CNT to include/linux/nfs4.h so flexfile and the
legacy file layout can share it, bounds the inner mp_count loop in
both drivers against that cap, and breaks the loop on the first NULL
return from nfs4_decode_mp_ds_addr() so a hostile server cannot drive
the decoder past a single malformed entry. Either patch alone closes
the panic; both together close the latent unbounded-decode class.
The unbound on mp_count predates the flexfile driver: the same loop
exists in the legacy file layout since 35124a0994fc ("Cleanup XDR
parsing for LAYOUTGET, GETDEVICEINFO", 2011) and was carried into
flexfile by d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout
Driver", 2014). The NULL-deref site was introduced by 6b7f3cf96364
("nfs41: pull decode_ds_addr from file layout to generic pnfs") when
the netaddr decode was unified. Stable backporting wanted for all
three.
Cc: stable@vger.kernel.org
Michael Bommarito (2):
NFSv4/pNFS: reject zero-length r_addr in nfs4_decode_mp_ds_addr
NFSv4/flexfile,filelayout: bound multipath DS count in GETDEVICEINFO
fs/nfs/filelayout/filelayout.h | 2 +-
fs/nfs/filelayout/filelayoutdev.c | 7 +++++--
fs/nfs/flexfilelayout/flexfilelayoutdev.c | 10 ++++++++--
fs/nfs/pnfs_nfs.c | 4 ++--
include/linux/nfs4.h | 3 +++
5 files changed, 19 insertions(+), 7 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] NFSv4/pNFS: reject zero-length r_addr in nfs4_decode_mp_ds_addr 2026-05-23 1:40 [PATCH 0/2] NFSv4/pNFS: fix client kernel panic from malformed GETDEVICEINFO Michael Bommarito @ 2026-05-23 1:40 ` Michael Bommarito 2026-05-23 1:40 ` [PATCH 2/2] NFSv4/flexfile,filelayout: bound multipath DS count in GETDEVICEINFO Michael Bommarito 1 sibling, 0 replies; 4+ messages in thread From: Michael Bommarito @ 2026-05-23 1:40 UTC (permalink / raw) To: Trond Myklebust, Anna Schumaker Cc: Jeff Layton, Tom Haynes, Peng Tao, Kees Cook, Mike Snitzer, Tigran Mkrtchyan, linux-nfs, linux-kernel, stable nfs4_decode_mp_ds_addr() decodes the r_netid and r_addr opaques of a netaddr4 from a GETDEVICEINFO multipath-DS body, then immediately calls strrchr(buf, '.') to locate the port separator. Both decodes use xdr_stream_decode_string_dup(), and the current code checks only "nlen < 0" / "rlen < 0" before dereferencing the returned string. When the on-wire opaque has length zero, xdr_stream_decode_opaque_inline() returns 0 and xdr_stream_decode_string_dup() falls through to its "*str = NULL; return ret" tail, leaving buf NULL with a return value of 0. The "< 0" check does not catch this, and the next line is strrchr(NULL, '.'), a kernel NULL pointer dereference reachable from any pNFS-flexfile client mounted against a malicious or compromised metadata server. Reject the zero-length cases explicitly so the decoder fails with -EBADMSG (treated as a malformed GETDEVICEINFO body) instead of panicking the client. Cc: stable@vger.kernel.org Fixes: 6b7f3cf96364 ("nfs41: pull decode_ds_addr from file layout to generic pnfs") Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> --- fs/nfs/pnfs_nfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Reproduced via a malicious NFSv4.1/pNFS server returning a flexfile GETDEVICEINFO body with multipath_count >= 3 and one valid (netid, uaddr) pair. Linux 7.0-rc7 + KASAN, QEMU/KVM. Stock kernel: Oops: general protection fault [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:strrchr+0x24/0x80 Call Trace: nfs4_decode_mp_ds_addr+0xca/0x570 nfs4_ff_alloc_deviceid_node+0x357/0x1370 nfs4_find_get_deviceid+0x6b6/0xa90 nfs4_ff_layout_prepare_ds+0x3cf/0xa40 ff_layout_choose_ds_for_read+0x14c/0x350 ff_layout_pg_init_read+0x2a2/0xb90 ... nfs_file_splice_read+0xcf/0x190 do_sendfile+0x8eb/0xdf0 Kernel panic - not syncing: Fatal exception Deterministic for any multipath_count >= 3; multipath_count <= 2 does not crash because the loop ends before consuming the malformed trailing bytes. Patched kernel rejects the same crafted body and a baseline multipath_count = 1 mount + read completes normally. diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c index 12632a706da88..0ff43dbcb7cd7 100644 --- a/fs/nfs/pnfs_nfs.c +++ b/fs/nfs/pnfs_nfs.c @@ -1075,14 +1075,14 @@ nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags) /* r_netid */ nlen = xdr_stream_decode_string_dup(xdr, &netid, XDR_MAX_NETOBJ, gfp_flags); - if (unlikely(nlen < 0)) + if (unlikely(nlen <= 0)) goto out_err; /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */ /* port is ".ABC.DEF", 8 chars max */ rlen = xdr_stream_decode_string_dup(xdr, &buf, INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8, gfp_flags); - if (unlikely(rlen < 0)) + if (unlikely(rlen <= 0)) goto out_free_netid; /* replace port '.' with '-' */ -- 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] NFSv4/flexfile,filelayout: bound multipath DS count in GETDEVICEINFO 2026-05-23 1:40 [PATCH 0/2] NFSv4/pNFS: fix client kernel panic from malformed GETDEVICEINFO Michael Bommarito 2026-05-23 1:40 ` [PATCH 1/2] NFSv4/pNFS: reject zero-length r_addr in nfs4_decode_mp_ds_addr Michael Bommarito @ 2026-05-23 1:40 ` Michael Bommarito 2026-05-26 19:57 ` Anna Schumaker 1 sibling, 1 reply; 4+ messages in thread From: Michael Bommarito @ 2026-05-23 1:40 UTC (permalink / raw) To: Trond Myklebust, Anna Schumaker Cc: Jeff Layton, Tom Haynes, Peng Tao, Kees Cook, Mike Snitzer, Tigran Mkrtchyan, linux-nfs, linux-kernel, stable Both the flexfile and the (legacy) file pNFS layout drivers decode a multipath-DS count from a server-supplied GETDEVICEINFO body and then iterate it via nfs4_decode_mp_ds_addr() without any upper bound. The filelayout driver already caps the outer ds_num against NFS4_PNFS_MAX_MULTI_CNT (== 256) but applies no equivalent cap to the inner mp_count; the flexfile driver applies no cap on either. In addition, both inner loops ignore a NULL return from nfs4_decode_mp_ds_addr(), so once the on-wire data no longer matches a valid netaddr4 encoding the loop is free to consume the trailing bytes of the device_addr opaque as garbage netid + uaddr pairs. A malicious or compromised pNFS metadata server can therefore drive the inner loop indefinitely (up to 2^32 - 1 iterations) against a fixed-size 56-byte body, with each iteration triggering an allocation / kmemdup_nul cycle inside the decoder. Promote NFS4_PNFS_MAX_MULTI_CNT from the filelayout private header to include/linux/nfs4.h so both drivers (and any future pNFS layout driver that decodes a multipath address list) bound the wire-level field consistently. Apply the cap to the inner mp_count in both drivers, matching the existing ds_num check, and bail on the first NULL return so a server that lies about mp_count cannot quietly extend the loop into the trailing layout-body bytes. This is defense-in-depth on top of the companion patch which closes the NULL-deref in nfs4_decode_mp_ds_addr(); either patch alone closes the kernel-panic shape, both together close the latent unbounded-decode class. Cc: stable@vger.kernel.org Fixes: 35124a0994fc ("Cleanup XDR parsing for LAYOUTGET, GETDEVICEINFO") Fixes: d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout Driver") Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> --- fs/nfs/filelayout/filelayout.h | 2 +- fs/nfs/filelayout/filelayoutdev.c | 7 +++++-- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 10 ++++++++-- include/linux/nfs4.h | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) With this patch alone the crafted GETDEVICEINFO at multipath_count >= 3 is rejected at the bound check; malformed netaddr in the inner loop bails on the first NULL return. Either this patch or the companion 1/2 closes the panic; both together close the unbounded-decode class. Baseline multipath_count = 1 mount + read completes normally. diff --git a/fs/nfs/filelayout/filelayout.h b/fs/nfs/filelayout/filelayout.h index c7bb5da93307d..03298f2e7cd69 100644 --- a/fs/nfs/filelayout/filelayout.h +++ b/fs/nfs/filelayout/filelayout.h @@ -39,7 +39,7 @@ * RFC 5661 multipath_list4 structures. */ #define NFS4_PNFS_MAX_STRIPE_CNT 4096 -#define NFS4_PNFS_MAX_MULTI_CNT 256 /* 256 fit into a u8 stripe_index */ +/* NFS4_PNFS_MAX_MULTI_CNT now in <linux/nfs4.h>; shared with flexfile. */ enum stripetype4 { STRIPE_SPARSE = 1, diff --git a/fs/nfs/filelayout/filelayoutdev.c b/fs/nfs/filelayout/filelayoutdev.c index 7226989ee4d53..c58c786dcf011 100644 --- a/fs/nfs/filelayout/filelayoutdev.c +++ b/fs/nfs/filelayout/filelayoutdev.c @@ -159,10 +159,13 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, goto out_err_free_deviceid; mp_count = be32_to_cpup(p); /* multipath count */ + if (mp_count > NFS4_PNFS_MAX_MULTI_CNT) + goto out_err_free_deviceid; for (j = 0; j < mp_count; j++) { da = nfs4_decode_mp_ds_addr(net, &stream, gfp_flags); - if (da) - list_add_tail(&da->da_node, &dsaddrs); + if (!da) + break; + list_add_tail(&da->da_node, &dsaddrs); } if (list_empty(&dsaddrs)) { dprintk("%s: no suitable DS addresses found\n", diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c b/fs/nfs/flexfilelayout/flexfilelayoutdev.c index c40395ae08142..faed05cbe9f1c 100644 --- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c +++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c @@ -78,12 +78,18 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, goto out_err_drain_dsaddrs; mp_count = be32_to_cpup(p); dprintk("%s: multipath ds count %d\n", __func__, mp_count); + if (mp_count > NFS4_PNFS_MAX_MULTI_CNT) { + dprintk("%s: multipath count %u greater than supported maximum %d\n", + __func__, mp_count, NFS4_PNFS_MAX_MULTI_CNT); + goto out_err_drain_dsaddrs; + } for (i = 0; i < mp_count; i++) { /* multipath ds */ da = nfs4_decode_mp_ds_addr(net, &stream, gfp_flags); - if (da) - list_add_tail(&da->da_node, &dsaddrs); + if (!da) + break; + list_add_tail(&da->da_node, &dsaddrs); } if (list_empty(&dsaddrs)) { dprintk("%s: no suitable DS addresses found\n", diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index d87be1f25273a..bfc30baa8159a 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -767,6 +767,9 @@ enum pnfs_block_extent_state { PNFS_BLOCK_NONE_DATA = 3, }; +/* Maximum NFSv4.1 pNFS multipath data-server address count */ +#define NFS4_PNFS_MAX_MULTI_CNT 256 + /* on the wire size of a block layout extent */ #define PNFS_BLOCK_EXTENT_SIZE \ (7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE) -- 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] NFSv4/flexfile,filelayout: bound multipath DS count in GETDEVICEINFO 2026-05-23 1:40 ` [PATCH 2/2] NFSv4/flexfile,filelayout: bound multipath DS count in GETDEVICEINFO Michael Bommarito @ 2026-05-26 19:57 ` Anna Schumaker 0 siblings, 0 replies; 4+ messages in thread From: Anna Schumaker @ 2026-05-26 19:57 UTC (permalink / raw) To: Michael Bommarito, Trond Myklebust Cc: Jeff Layton, Tom Haynes, Peng Tao, Kees Cook, Mike Snitzer, Tigran Mkrtchyan, linux-nfs, linux-kernel, stable Hi Michael, On Fri, May 22, 2026, at 9:40 PM, Michael Bommarito wrote: > Both the flexfile and the (legacy) file pNFS layout drivers decode a > multipath-DS count from a server-supplied GETDEVICEINFO body and then > iterate it via nfs4_decode_mp_ds_addr() without any upper bound. The > filelayout driver already caps the outer ds_num against > NFS4_PNFS_MAX_MULTI_CNT (== 256) but applies no equivalent cap to the > inner mp_count; the flexfile driver applies no cap on either. > > In addition, both inner loops ignore a NULL return from > nfs4_decode_mp_ds_addr(), so once the on-wire data no longer matches > a valid netaddr4 encoding the loop is free to consume the trailing > bytes of the device_addr opaque as garbage netid + uaddr pairs. A > malicious or compromised pNFS metadata server can therefore drive > the inner loop indefinitely (up to 2^32 - 1 iterations) against a > fixed-size 56-byte body, with each iteration triggering an > allocation / kmemdup_nul cycle inside the decoder. > > Promote NFS4_PNFS_MAX_MULTI_CNT from the filelayout private header to > include/linux/nfs4.h so both drivers (and any future pNFS layout > driver that decodes a multipath address list) bound the wire-level > field consistently. Apply the cap to the inner mp_count in both > drivers, matching the existing ds_num check, and bail on the first > NULL return so a server that lies about mp_count cannot quietly > extend the loop into the trailing layout-body bytes. This is > defense-in-depth on top of the companion patch which closes the > NULL-deref in nfs4_decode_mp_ds_addr(); either patch alone closes > the kernel-panic shape, both together close the latent > unbounded-decode class. > > Cc: stable@vger.kernel.org > Fixes: 35124a0994fc ("Cleanup XDR parsing for LAYOUTGET, GETDEVICEINFO") > Fixes: d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout Driver") > Assisted-by: Claude:claude-opus-4-7 > Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> > --- > fs/nfs/filelayout/filelayout.h | 2 +- > fs/nfs/filelayout/filelayoutdev.c | 7 +++++-- > fs/nfs/flexfilelayout/flexfilelayoutdev.c | 10 ++++++++-- > include/linux/nfs4.h | 3 +++ > 4 files changed, 17 insertions(+), 5 deletions(-) > > With this patch alone the crafted GETDEVICEINFO at multipath_count >= 3 > is rejected at the bound check; malformed netaddr in the inner loop > bails on the first NULL return. Either this patch or the companion > 1/2 closes the panic; both together close the unbounded-decode class. > > Baseline multipath_count = 1 mount + read completes normally. > > > diff --git a/fs/nfs/filelayout/filelayout.h b/fs/nfs/filelayout/filelayout.h > index c7bb5da93307d..03298f2e7cd69 100644 > --- a/fs/nfs/filelayout/filelayout.h > +++ b/fs/nfs/filelayout/filelayout.h > @@ -39,7 +39,7 @@ > * RFC 5661 multipath_list4 structures. > */ > #define NFS4_PNFS_MAX_STRIPE_CNT 4096 > -#define NFS4_PNFS_MAX_MULTI_CNT 256 /* 256 fit into a u8 stripe_index */ > +/* NFS4_PNFS_MAX_MULTI_CNT now in <linux/nfs4.h>; shared with flexfile. */ I don't think we need the comment saying that the value has moved. > > enum stripetype4 { > STRIPE_SPARSE = 1, > diff --git a/fs/nfs/filelayout/filelayoutdev.c > b/fs/nfs/filelayout/filelayoutdev.c > index 7226989ee4d53..c58c786dcf011 100644 > --- a/fs/nfs/filelayout/filelayoutdev.c > +++ b/fs/nfs/filelayout/filelayoutdev.c > @@ -159,10 +159,13 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server > *server, struct pnfs_device *pdev, > goto out_err_free_deviceid; > > mp_count = be32_to_cpup(p); /* multipath count */ > + if (mp_count > NFS4_PNFS_MAX_MULTI_CNT) > + goto out_err_free_deviceid; > for (j = 0; j < mp_count; j++) { > da = nfs4_decode_mp_ds_addr(net, &stream, gfp_flags); > - if (da) > - list_add_tail(&da->da_node, &dsaddrs); > + if (!da) > + break; > + list_add_tail(&da->da_node, &dsaddrs); > } > if (list_empty(&dsaddrs)) { > dprintk("%s: no suitable DS addresses found\n", > diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c > b/fs/nfs/flexfilelayout/flexfilelayoutdev.c > index c40395ae08142..faed05cbe9f1c 100644 > --- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c > +++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c > @@ -78,12 +78,18 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server > *server, struct pnfs_device *pdev, > goto out_err_drain_dsaddrs; > mp_count = be32_to_cpup(p); > dprintk("%s: multipath ds count %d\n", __func__, mp_count); > + if (mp_count > NFS4_PNFS_MAX_MULTI_CNT) { > + dprintk("%s: multipath count %u greater than supported maximum %d\n", > + __func__, mp_count, NFS4_PNFS_MAX_MULTI_CNT); > + goto out_err_drain_dsaddrs; > + } > > for (i = 0; i < mp_count; i++) { > /* multipath ds */ > da = nfs4_decode_mp_ds_addr(net, &stream, gfp_flags); > - if (da) > - list_add_tail(&da->da_node, &dsaddrs); > + if (!da) > + break; > + list_add_tail(&da->da_node, &dsaddrs); > } > if (list_empty(&dsaddrs)) { > dprintk("%s: no suitable DS addresses found\n", > diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h > index d87be1f25273a..bfc30baa8159a 100644 > --- a/include/linux/nfs4.h > +++ b/include/linux/nfs4.h > @@ -767,6 +767,9 @@ enum pnfs_block_extent_state { > PNFS_BLOCK_NONE_DATA = 3, > }; > > +/* Maximum NFSv4.1 pNFS multipath data-server address count */ > +#define NFS4_PNFS_MAX_MULTI_CNT 256 In the original location, this had a comment saying where the 256 came from. Can you carry that over to here too, please? Thanks, Anna > + > /* on the wire size of a block layout extent */ > #define PNFS_BLOCK_EXTENT_SIZE \ > (7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE) > -- > 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-26 19:58 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-05-23 1:40 [PATCH 0/2] NFSv4/pNFS: fix client kernel panic from malformed GETDEVICEINFO Michael Bommarito 2026-05-23 1:40 ` [PATCH 1/2] NFSv4/pNFS: reject zero-length r_addr in nfs4_decode_mp_ds_addr Michael Bommarito 2026-05-23 1:40 ` [PATCH 2/2] NFSv4/flexfile,filelayout: bound multipath DS count in GETDEVICEINFO Michael Bommarito 2026-05-26 19:57 ` Anna Schumaker
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®