From: Ding Feng <dingf3ng@gmail.com>
To: Christian Brauner <brauner@kernel.org>
Cc: Ding Feng <dingf3ng@gmail.com>,
Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Ian Kent <raven@themaw.net>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] statmount: retry an overflowed string before reporting -EOVERFLOW
Date: Fri, 20 Nov 2026 11:36:44 +0800 [thread overview]
Message-ID: <20261120033644.99834-1-dingf3ng@gmail.com> (raw)
statmount_string() compares the seq_file count with the caller's buffer
size before it checks whether the seq_file overflowed. After an
overflow, seq->count equals seq->size, so every buffer of up to
sizeof(struct statmount) + seq->size bytes gets -EOVERFLOW, and the
retry with a larger seq buffer never runs.
The result can still fit in such a buffer. statmount_mnt_root() and
statmount_sb_source() write escaped strings and unescape them in place,
so the escaped form can overflow the 3 * PATH_MAX seq buffer while the
final string is much shorter. A bind mount whose root is a 3765-byte
path of spaces needs a 4.3 KiB buffer, but STATMOUNT_MNT_ROOT fails
with -EOVERFLOW for every buffer up to 12800 bytes and succeeds from
12801.
Check for the overflow first, so the string is regenerated in a larger
seq buffer and the size check sees its final length.
Fixes: 68385d77c05b ("statmount: simplify string option retrieval")
Assisted-by: Claude:claude-opus-5-5 Frama-C
Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
Notes:
Tested on v7.4-rc3 (65e4fd942), arm64 tinyconfig in QEMU. The test bind
mounts a tmpfs directory whose path below the tmpfs root is 15 names of
250 spaces (3765 bytes, about 15000 bytes escaped) and calls statmount()
with STATMOUNT_MNT_ROOT; the result needs 4279 bytes:
bufsize unpatched patched
1024 EOVERFLOW EOVERFLOW
4096 EOVERFLOW EOVERFLOW
8192 EOVERFLOW ok
12800 EOVERFLOW ok
12801 ok ok
A plain mount gives the same results on both kernels (1024 ok, 512
EOVERFLOW).
With this order, a buffer too small for a string longer than the seq
buffer now costs one or more retries before -EOVERFLOW, instead of
failing at once.
This came up while proving statmount(2) against its man page with
Frama-C/WP.
fs/namespace.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index aecd05ac0..2c4987942 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5813,15 +5813,15 @@ static int statmount_string(struct kstatmount *s, u64 flag)
*/
if (seq->count == start)
return ret;
+ /* signal a retry */
+ if (unlikely(seq_has_overflowed(seq)))
+ return -EAGAIN;
+
if (unlikely(check_add_overflow(sizeof(*sm), seq->count, &kbufsize)))
return -EOVERFLOW;
if (kbufsize >= s->bufsize)
return -EOVERFLOW;
- /* signal a retry */
- if (unlikely(seq_has_overflowed(seq)))
- return -EAGAIN;
-
if (ret)
return ret;
--
2.47.3
reply other threads:[~2026-11-20 3:36 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=20261120033644.99834-1-dingf3ng@gmail.com \
--to=dingf3ng@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=raven@themaw.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox