* [PATCH] statmount: retry an overflowed string before reporting -EOVERFLOW
@ 2026-11-20 3:36 Ding Feng
2026-11-24 13:32 ` Kyuwon Cho
0 siblings, 1 reply; 2+ messages 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 [flat|nested] 2+ messages in thread
* Re: [PATCH] statmount: retry an overflowed string before reporting -EOVERFLOW
2026-11-20 3:36 [PATCH] statmount: retry an overflowed string before reporting -EOVERFLOW Ding Feng
@ 2026-11-24 13:32 ` Kyuwon Cho
0 siblings, 0 replies; 2+ messages in thread
From: Kyuwon Cho @ 2026-11-24 13:32 UTC (permalink / raw)
To: Ding Feng
Cc: Christian Brauner, Alexander Viro, Jan Kara, Ian Kent,
linux-fsdevel, linux-kernel
Hi Ding,
Moving the check one step further up, above the "seq->count == start"
return, also fixes a case where a string is dropped without any error:
/* signal a retry */
if (unlikely(seq_has_overflowed(seq)))
return -EAGAIN;
if (seq->count == start)
return ret;
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. For
example, 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, with or
without your patch, and returns it with the check moved up.
Could you fold this into a v2?
We found this with an LLM-guided test generator, a research prototype
we are developing.
Thanks,
Kyuwon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 13:32 UTC | newest]
Thread overview: 2+ messages (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
2026-11-24 13:32 ` Kyuwon Cho
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®