Skip to content

Commit b2e191a

Browse files
Miklos Szeredimehmetb0
authored andcommitted
statmount: let unset strings be empty
BugLink: https://bugs.launchpad.net/bugs/2114239 commit e52e97f upstream. Just like it's normal for unset values to be zero, unset strings should be empty instead of containing random values. It seems to be a typical mistake that the mask returned by statmount is not checked, which can result in various bugs. With this fix, these bugs are prevented, since it is highly likely that userspace would just want to turn the missing mask case into an empty string anyway (most of the recently found cases are of this type). Link: https://lore.kernel.org/all/CAJfpegsVCPfCn2DpM8iiYSS5DpMsLB8QBUCHecoj6s0Vxf4jzg@mail.gmail.com/ Fixes: 68385d7 ("statmount: simplify string option retrieval") Fixes: 46eae99 ("add statmount(2) syscall") Cc: stable@vger.kernel.org # v6.8 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Link: https://lore.kernel.org/r/20250130121500.113446-1-mszeredi@redhat.com Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [nwager: Drop hunk due to missing commit: f9af549 ("fs: export mount options via statmount()")] Signed-off-by: Noah Wager <noah.wager@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent 79a95c2 commit b2e191a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

fs/namespace.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,18 +4855,25 @@ static int statmount_string(struct kstatmount *s, u64 flag)
48554855
size_t kbufsize;
48564856
struct seq_file *seq = &s->seq;
48574857
struct statmount *sm = &s->sm;
4858+
u32 start, *offp;
4859+
4860+
/* Reserve an empty string at the beginning for any unset offsets */
4861+
if (!seq->count)
4862+
seq_putc(seq, 0);
4863+
4864+
start = seq->count;
48584865

48594866
switch (flag) {
48604867
case STATMOUNT_FS_TYPE:
4861-
sm->fs_type = seq->count;
4868+
offp = &sm->fs_type;
48624869
ret = statmount_fs_type(s, seq);
48634870
break;
48644871
case STATMOUNT_MNT_ROOT:
4865-
sm->mnt_root = seq->count;
4872+
offp = &sm->mnt_root;
48664873
ret = statmount_mnt_root(s, seq);
48674874
break;
48684875
case STATMOUNT_MNT_POINT:
4869-
sm->mnt_point = seq->count;
4876+
offp = &sm->mnt_point;
48704877
ret = statmount_mnt_point(s, seq);
48714878
break;
48724879
default:
@@ -4888,6 +4895,7 @@ static int statmount_string(struct kstatmount *s, u64 flag)
48884895

48894896
seq->buf[seq->count++] = '\0';
48904897
sm->mask |= flag;
4898+
*offp = start;
48914899
return 0;
48924900
}
48934901

0 commit comments

Comments
 (0)