Linux-NFS Archive mirror
 help / color / mirror / Atom feed
From: Junrui Luo <moonafterrain@outlook.com>
To: Trond Myklebust <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>,
	 Weston Andros Adamson <dros@primarydata.com>,
	 Tao Peng <bergwolf@primarydata.com>,
	Tom Haynes <loghyr@primarydata.com>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Yuhao Jiang <danisjiang@gmail.com>,
	stable@vger.kernel.org,  Junrui Luo <moonafterrain@outlook.com>
Subject: [PATCH] pnfs/flexfiles: reject zero version_count in GETDEVICEINFO
Date: Mon, 20 Apr 2026 21:01:47 +0800	[thread overview]
Message-ID: <SYBPR01MB78811DDDAA116611B5CA56EBAF2F2@SYBPR01MB7881.ausprd01.prod.outlook.com> (raw)

nfs4_ff_alloc_deviceid_node() parses the flexfiles device address from
a GETDEVICEINFO response and passes version_count to kzalloc_objs()
without validating it is non-zero. A zero count makes kzalloc_objs()
return ZERO_SIZE_PTR, which passes the NULL check.

This leads to a NULL pointer dereference when
nfs4_ff_layout_ds_version() later accesses ds_versions[0] through the
ZERO_SIZE_PTR.

Fix by rejecting version_count == 0 before the allocation.

Fixes: d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout Driver")
Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
---
 fs/nfs/flexfilelayout/flexfilelayoutdev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
index c40395ae0814..d5aa6bf3ecbc 100644
--- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c
+++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
@@ -99,6 +99,11 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
 	version_count = be32_to_cpup(p);
 	dprintk("%s: version count %d\n", __func__, version_count);
 
+	if (version_count == 0) {
+		ret = -EINVAL;
+		goto out_err_drain_dsaddrs;
+	}
+
 	ds_versions = kzalloc_objs(struct nfs4_ff_ds_version, version_count,
 				   gfp_flags);
 	if (!ds_versions)

---
base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260420-fixes-9f910b7b5cde

Best regards,
-- 
Junrui Luo <moonafterrain@outlook.com>


                 reply	other threads:[~2026-04-20 13:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=SYBPR01MB78811DDDAA116611B5CA56EBAF2F2@SYBPR01MB7881.ausprd01.prod.outlook.com \
    --to=moonafterrain@outlook.com \
    --cc=anna@kernel.org \
    --cc=bergwolf@primarydata.com \
    --cc=danisjiang@gmail.com \
    --cc=dros@primarydata.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=loghyr@primarydata.com \
    --cc=stable@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).