* [PATCH] statmount: retry an overflowed string before reporting -EOVERFLOW
@ 2026-11-20 3:36 Ding Feng
0 siblings, 0 replies; only message in thread
From: Ding Feng @ 2026-11-20 3:36 UTC (permalink / raw)
To: Christian Brauner
Cc: Ding Feng, Alexander Viro, Jan Kara, Ian Kent, linux-fsdevel,
linux-kernel
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-20 3:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 3:36 [PATCH] statmount: retry an overflowed string before reporting -EOVERFLOW Ding Feng
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.