Skip to content

Commit e52e97f

Browse files
Miklos Szeredibrauner
authored andcommitted
statmount: let unset strings be empty
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: [email protected] # v6.8 Signed-off-by: Miklos Szeredi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 4e74872 commit e52e97f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

fs/namespace.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5191,39 +5191,45 @@ static int statmount_string(struct kstatmount *s, u64 flag)
51915191
size_t kbufsize;
51925192
struct seq_file *seq = &s->seq;
51935193
struct statmount *sm = &s->sm;
5194-
u32 start = seq->count;
5194+
u32 start, *offp;
5195+
5196+
/* Reserve an empty string at the beginning for any unset offsets */
5197+
if (!seq->count)
5198+
seq_putc(seq, 0);
5199+
5200+
start = seq->count;
51955201

51965202
switch (flag) {
51975203
case STATMOUNT_FS_TYPE:
5198-
sm->fs_type = start;
5204+
offp = &sm->fs_type;
51995205
ret = statmount_fs_type(s, seq);
52005206
break;
52015207
case STATMOUNT_MNT_ROOT:
5202-
sm->mnt_root = start;
5208+
offp = &sm->mnt_root;
52035209
ret = statmount_mnt_root(s, seq);
52045210
break;
52055211
case STATMOUNT_MNT_POINT:
5206-
sm->mnt_point = start;
5212+
offp = &sm->mnt_point;
52075213
ret = statmount_mnt_point(s, seq);
52085214
break;
52095215
case STATMOUNT_MNT_OPTS:
5210-
sm->mnt_opts = start;
5216+
offp = &sm->mnt_opts;
52115217
ret = statmount_mnt_opts(s, seq);
52125218
break;
52135219
case STATMOUNT_OPT_ARRAY:
5214-
sm->opt_array = start;
5220+
offp = &sm->opt_array;
52155221
ret = statmount_opt_array(s, seq);
52165222
break;
52175223
case STATMOUNT_OPT_SEC_ARRAY:
5218-
sm->opt_sec_array = start;
5224+
offp = &sm->opt_sec_array;
52195225
ret = statmount_opt_sec_array(s, seq);
52205226
break;
52215227
case STATMOUNT_FS_SUBTYPE:
5222-
sm->fs_subtype = start;
5228+
offp = &sm->fs_subtype;
52235229
statmount_fs_subtype(s, seq);
52245230
break;
52255231
case STATMOUNT_SB_SOURCE:
5226-
sm->sb_source = start;
5232+
offp = &sm->sb_source;
52275233
ret = statmount_sb_source(s, seq);
52285234
break;
52295235
default:
@@ -5251,6 +5257,7 @@ static int statmount_string(struct kstatmount *s, u64 flag)
52515257

52525258
seq->buf[seq->count++] = '\0';
52535259
sm->mask |= flag;
5260+
*offp = start;
52545261
return 0;
52555262
}
52565263

0 commit comments

Comments
 (0)