statmount: retry an overflowed seq buffer before any other check
PATCH v2 1/1 statmount: retry an overflowed seq buffer before any other check
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.
---
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/[email protected]/
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(-)
fs/namespace.c +4 -4
@@ -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;
Signature · 1 line
2.47.3