From: Ding Feng <dingf3ng@gmail.com>
To: Christian Brauner <brauner@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Ian Kent <raven@themaw.net>, Jeff Layton <jlayton@kernel.org>,
Kyuwon Cho <kyuwoncho18@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] statmount: retry an overflowed seq buffer before any other check
Date: Thu, 26 Nov 2026 01:13:48 +0800 [thread overview]
Message-ID: <20261125-statmount-retry-v2-1-dingf3ng@gmail.com> (raw)
statmount_string() checks whether the seq_file overflowed only after
two earlier returns, and both can hide the overflow.
The size check runs first. 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.
The early return for a string that emits nothing runs before both. The
NUL written after a string that ends one byte before the end of the seq
buffer leaves seq->count == seq->size. The next string then emits
nothing, and the early return drops it with no error and no retry. With
a tmpfs mounted on a 12278-byte path, statmount() for
STATMOUNT_FS_TYPE | STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT |
STATMOUNT_SB_SOURCE returns 0 without STATMOUNT_SB_SOURCE.
Check for the overflow before both, so the string is regenerated in a
larger seq buffer.
Fixes: 68385d77c05b ("statmount: simplify string option retrieval")
Fixes: 75ead69a7173 ("fs: don't let statmount return empty strings")
Reported-by: Kyuwon Cho <kyuwoncho18@gmail.com>
Closes: https://lore.kernel.org/all/179552693473.1490262.10477620788152048784@gmail.com/
Suggested-by: Kyuwon Cho <kyuwoncho18@gmail.com>
Assisted-by: Claude:claude-opus-5-5 Frama-C
Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
Notes:
v2: move the check above the "seq->count == start" return as well,
which also fixes the dropped string Kyuwon found.
v1: https://lore.kernel.org/all/20261120033644.99834-1-dingf3ng@gmail.com/
Tested on v7.4-rc3 (65e4fd942), arm64 tinyconfig in QEMU:
case v7.4-rc3 v1 v2
STATMOUNT_MNT_ROOT, 3765-byte root of spaces,
bufsize 8192 or 12800 EOVERFLOW ok ok
bufsize 4096 EOVERFLOW EOVERFLOW EOVERFLOW
tmpfs on a 12278-byte path, SB_SOURCE missing missing tmpfs
tmpfs on a 12276, 12277, 12279 or 12280-byte
path, SB_SOURCE tmpfs tmpfs tmpfs
A plain bind mount gives the same results on all three (1024 ok, 512
EOVERFLOW).
A string that legitimately emits nothing after a full seq buffer now
costs one retry, and a buffer too small for a string longer than the
seq buffer costs one or more retries before -EOVERFLOW.
fs/namespace.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index aecd05ac0..3c41fd42c 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5807,6 +5807,10 @@ static int statmount_string(struct kstatmount *s, u64 flag)
return -EINVAL;
}
+ /* signal a retry */
+ if (unlikely(seq_has_overflowed(seq)))
+ return -EAGAIN;
+
/*
* If nothing was emitted, return to avoid setting the flag
* and terminating the buffer.
@@ -5818,10 +5822,6 @@ static int statmount_string(struct kstatmount *s, u64 flag)
if (kbufsize >= s->bufsize)
return -EOVERFLOW;
- /* signal a retry */
- if (unlikely(seq_has_overflowed(seq)))
- return -EAGAIN;
-
if (ret)
return ret;
--
2.47.3
next reply other threads:[~2026-11-25 17:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:13 Ding Feng [this message]
2026-11-26 6:01 ` [PATCH v2] statmount: retry an overflowed seq buffer before any other check Kyuwon Cho
2026-11-27 15:27 ` Jan Kara
2026-12-01 13:08 ` Christian Brauner
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=20261125-statmount-retry-v2-1-dingf3ng@gmail.com \
--to=dingf3ng@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=kyuwoncho18@gmail.com \
--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 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.