From: Hui Peng <benquike@gmail.com>
To: Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Hui Peng <benquike@gmail.com>
Subject: [PATCH 1/2] nsfs: fix u32-vs-bytes unit mismatch in nsfs_fh_to_dentry()
Date: Sat, 19 Sep 2026 08:08:49 +0000 [thread overview]
Message-ID: <20260919080850.3005810-1-benquike@gmail.com> (raw)
In nsfs_fh_to_dentry(), both fh_len and NSFS_FID_SIZE_U32_LATEST (4) are
expressed in units of 4-byte u32 words rather than bytes, whereas
pointer arithmetic on (void *)fid and the byte count passed to
memchr_inv() are in bytes (NSFS_FILE_HANDLE_SIZE_LATEST = 16).
Passing (void *)fid + NSFS_FID_SIZE_U32_LATEST and
fh_len - NSFS_FID_SIZE_U32_LATEST to memchr_inv() inspects bytes
[4 .. fh_len) inside struct nsfs_file_handle (fid->ns_id and
fid->ns_type) instead of the trailing bytes [16 .. fh_len * 4) after
struct nsfs_file_handle. Consequently:
1. Valid zero-padded handles with handle_bytes >= 36 (fh_len >= 9) where
fid->ns_type != 0 (at byte offset 8) are falsely rejected with
-ESTALE.
2. Non-zero trailing garbage in bytes [16 .. fh_len * 4) is ignored when
the upper 32 bits of fid->ns_id (bytes [4..7]) are zero.
Fix this by offsetting (void *)fid by NSFS_FILE_HANDLE_SIZE_LATEST (16)
and multiplying (fh_len - NSFS_FID_SIZE_U32_LATEST) by sizeof(u32).
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
fs/nsfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index c3b6ae765..a1842e12f 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -529,8 +529,8 @@
/* Check that any trailing bytes are zero. */
if ((fh_len > NSFS_FID_SIZE_U32_LATEST) &&
- memchr_inv((void *)fid + NSFS_FID_SIZE_U32_LATEST, 0,
- fh_len - NSFS_FID_SIZE_U32_LATEST))
+ memchr_inv((void *)fid + NSFS_FILE_HANDLE_SIZE_LATEST, 0,
+ (fh_len - NSFS_FID_SIZE_U32_LATEST) * sizeof(u32)))
return NULL;
switch (fh_type) {
--
2.43.0
next reply other threads:[~2026-09-19 8:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 8:08 Hui Peng [this message]
2026-09-19 8:08 ` [PATCH 2/2] nsfs: fix namespace reference leak on unsupported ns_type in nsfs_fh_to_dentry() Hui Peng
2026-09-19 11:25 ` [PATCH v2 1/2] nsfs: fix u32-vs-bytes unit mismatch " Hui Peng
2026-09-19 11:25 ` [PATCH v2 2/2] nsfs: fix namespace reference leak on unsupported ns_type " Hui Peng
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=20260919080850.3005810-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.