From: Elkin Cruz <elkin@google.com>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, irogers@google.com,
Elkin Cruz <elkin@google.com>,
stable@vger.kernel.org
Subject: [PATCH] nfs/blocklayout: use div64_u64() for chunk_size in bl_map_stripe()
Date: Wed, 25 Nov 2026 22:18:12 +0000 [thread overview]
Message-ID: <20261125221812.1423319-1-elkin@google.com> (raw)
In bl_map_stripe(), dev->chunk_size is a 64-bit integer (u64) decoded
from XDR. Passing dev->chunk_size to div_u64() silently truncates the
divisor to 32 bits, causing division by zero if chunk_size is a multiple
of 4 GiB and silent miscalculation for other values above U32_MAX.
Use div64_u64() to preserve full 64-bit division by dev->chunk_size,
and reject zero chunk_size or volumes_count upfront in bl_parse_stripe().
Fixes: 5466112f0935 ("pnfs/blocklayout: Fix a 64-bit division/remainder issue in bl_map_stripe")
Fixes: 5c83746a0cf2 ("pnfs/blocklayout: in-kernel GETDEVICEINFO XDR parsing")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkin
Note: Liu Chao posted a patch on 2026-10-16 checking !chunk_size
(https://lore.kernel.org/r/20261016041139.2292455-1-liuc63@xiaopeng.com),
which is not yet in linux-next. This patch additionally fixes the 64-bit
truncation in div_u64() (which still divides by zero for non-zero multiples
of 4 GiB) and zero volumes_count. Happy to rebase on top of that patch if
it is already queued.
fs/nfs/blocklayout/dev.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
index 00462e6affb1..8c7af13d45d0 100644
--- a/fs/nfs/blocklayout/dev.c
+++ b/fs/nfs/blocklayout/dev.c
@@ -274,7 +274,7 @@ static bool bl_map_stripe(struct pnfs_block_dev *dev, u64 offset,
u64 disk_chunk;
u64 disk_offset;
- chunk = div_u64(offset, dev->chunk_size);
+ chunk = div64_u64(offset, dev->chunk_size);
disk_chunk = div_u64_rem(chunk, dev->nr_children, &chunk_idx);
if (chunk_idx >= dev->nr_children) {
@@ -536,6 +536,9 @@ bl_parse_stripe(struct nfs_server *server, struct pnfs_block_dev *d,
u64 len = 0;
int ret, i;
+ if (!v->stripe.chunk_size || !v->stripe.volumes_count)
+ return -EINVAL;
+
d->children = kzalloc_objs(struct pnfs_block_dev,
v->stripe.volumes_count, gfp_mask);
if (!d->children)
--
2.56.1.839.g22a8290db9-goog
reply other threads:[~2026-11-25 22:18 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=20261125221812.1423319-1-elkin@google.com \
--to=elkin@google.com \
--cc=anna@kernel.org \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--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
all inboxes | Powered by JetHome®