Skip to content

Commit 75ead69

Browse files
jtlaytonbrauner
authored andcommitted
fs: don't let statmount return empty strings
When one of the statmount_string() handlers doesn't emit anything to seq, the kernel currently sets the corresponding flag and emits an empty string. Given that statmount() returns a mask of accessible fields, just leave the bit unset in this case, and skip any NULL termination. If nothing was emitted to the seq, then the EOVERFLOW and EAGAIN cases aren't applicable and the function can just return immediately. Signed-off-by: Jeff Layton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Miklos Szeredi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent c4d7d90 commit 75ead69

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

fs/namespace.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5044,29 +5044,36 @@ static int statmount_string(struct kstatmount *s, u64 flag)
50445044
size_t kbufsize;
50455045
struct seq_file *seq = &s->seq;
50465046
struct statmount *sm = &s->sm;
5047+
u32 start = seq->count;
50475048

50485049
switch (flag) {
50495050
case STATMOUNT_FS_TYPE:
5050-
sm->fs_type = seq->count;
5051+
sm->fs_type = start;
50515052
ret = statmount_fs_type(s, seq);
50525053
break;
50535054
case STATMOUNT_MNT_ROOT:
5054-
sm->mnt_root = seq->count;
5055+
sm->mnt_root = start;
50555056
ret = statmount_mnt_root(s, seq);
50565057
break;
50575058
case STATMOUNT_MNT_POINT:
5058-
sm->mnt_point = seq->count;
5059+
sm->mnt_point = start;
50595060
ret = statmount_mnt_point(s, seq);
50605061
break;
50615062
case STATMOUNT_MNT_OPTS:
5062-
sm->mnt_opts = seq->count;
5063+
sm->mnt_opts = start;
50635064
ret = statmount_mnt_opts(s, seq);
50645065
break;
50655066
default:
50665067
WARN_ON_ONCE(true);
50675068
return -EINVAL;
50685069
}
50695070

5071+
/*
5072+
* If nothing was emitted, return to avoid setting the flag
5073+
* and terminating the buffer.
5074+
*/
5075+
if (seq->count == start)
5076+
return ret;
50705077
if (unlikely(check_add_overflow(sizeof(*sm), seq->count, &kbufsize)))
50715078
return -EOVERFLOW;
50725079
if (kbufsize >= s->bufsize)

0 commit comments

Comments
 (0)