[PATCH v2 01/23] NFSv4/flexfiles: reject a stripe_unit that does not fit 32 bits
Benjamin Coddington <[email protected]>
| Newsgroups | org.kernel.vger.linux-nfs |
|---|---|
| Message-ID | <09f50acb9f481b3a9c3716e8f70b9b3dbe81888c.1787327939.git.bcodding@hammerspace.com> |
ff_layout_alloc_lseg() decodes stripe_unit as the 64-bit value the
protocol defines, but every consumer treats it as a u32:
nfs4_ff_layout_calc_dss_id() divides by it with do_div(), which casts
the divisor, and ff_layout_pg_test() copies it into a u32 first. A
value that does not fit is silently truncated, so the client stripes on
a unit the server did not specify -- or divides by zero, if the low 32
bits happen to be clear.
Reject it where the existing zero check already is, using -EINVAL so
the layout is discarded and I/O falls back to the MDS, as the fh_count
check below does. That also moves the existing stripe_unit == 0 case
off the -EIO exit it shared, which fails the I/O instead.
Fixes: 20b1d75fb840 ("NFSv4/flexfiles: Add support for striped layouts")
Cc: [email protected]
Assisted-by: Claude:claude-fable-5
Signed-off-by: Benjamin Coddington <[email protected]>
---
fs/nfs/flexfilelayout/flexfilelayout.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index c4aa995026f6..74b75d061c6f 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -515,8 +515,11 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
dss_count == 0)
goto out_err_free;
- if (dss_count > 1 && stripe_unit == 0)
+ if (dss_count > 1 &&
+ (stripe_unit == 0 || stripe_unit > U32_MAX)) {
+ rc = -EINVAL;
goto out_err_free;
+ }
fls->mirror_array[i] = ff_layout_alloc_mirror(dss_count, gfp_flags);
if (fls->mirror_array[i] == NULL) {
--
2.53.0