* [PATCH v2] statmount: retry an overflowed seq buffer before any other check
@ 2026-11-25 17:13 Ding Feng
2026-11-26 6:01 ` Kyuwon Cho
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ding Feng @ 2026-11-25 17:13 UTC (permalink / raw)
To: Christian Brauner
Cc: Alexander Viro, Jan Kara, Ian Kent, Jeff Layton, Kyuwon Cho,
linux-fsdevel, linux-kernel
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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] statmount: retry an overflowed seq buffer before any other check
2026-11-25 17:13 [PATCH v2] statmount: retry an overflowed seq buffer before any other check Ding Feng
@ 2026-11-26 6:01 ` Kyuwon Cho
2026-11-27 15:27 ` Jan Kara
2026-12-01 13:08 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Kyuwon Cho @ 2026-11-26 6:01 UTC (permalink / raw)
To: Ding Feng
Cc: Christian Brauner, Alexander Viro, Jan Kara, Ian Kent,
Jeff Layton, linux-fsdevel, linux-kernel
Hi Ding,
On Thu, Nov 26, 2026 at 01:13:48AM +0800, Ding Feng wrote:
> Check for the overflow before both, so the string is regenerated in a
> larger seq buffer.
On v7.4-rc3 (x86_64, QEMU), our reproducer, a tmpfs mounted on a
12278-byte path, gets STATMOUNT_SB_SOURCE back with this patch. Without
the patch, statmount() returns 0 and leaves it out of the mask.
Tested-by: Kyuwon Cho <kyuwoncho18@gmail.com>
Thanks,
Kyuwon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] statmount: retry an overflowed seq buffer before any other check
2026-11-25 17:13 [PATCH v2] statmount: retry an overflowed seq buffer before any other check Ding Feng
2026-11-26 6:01 ` Kyuwon Cho
@ 2026-11-27 15:27 ` Jan Kara
2026-12-01 13:08 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2026-11-27 15:27 UTC (permalink / raw)
To: Ding Feng
Cc: Christian Brauner, Alexander Viro, Jan Kara, Ian Kent,
Jeff Layton, Kyuwon Cho, linux-fsdevel, linux-kernel
On Thu 26-11-26 01:13:48, Ding Feng wrote:
> 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>
Looks good to me. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
>
> 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
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] statmount: retry an overflowed seq buffer before any other check
2026-11-25 17:13 [PATCH v2] statmount: retry an overflowed seq buffer before any other check Ding Feng
2026-11-26 6:01 ` Kyuwon Cho
2026-11-27 15:27 ` Jan Kara
@ 2026-12-01 13:08 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-12-01 13:08 UTC (permalink / raw)
To: Ding Feng
Cc: Alexander Viro, Jan Kara, Ian Kent, Jeff Layton, Kyuwon Cho,
linux-fsdevel, linux-kernel
On Thu, 26 Nov 2026 01:13:48 +0800, Ding Feng wrote:
> 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.
>
> [...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] statmount: retry an overflowed seq buffer before any other check
https://git.kernel.org/vfs/vfs/c/d9a8b561f8d3
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 13:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 17:13 [PATCH v2] statmount: retry an overflowed seq buffer before any other check Ding Feng
2026-11-26 6:01 ` Kyuwon Cho
2026-11-27 15:27 ` Jan Kara
2026-12-01 13:08 ` Christian Brauner
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.