Skip to content

Commit f8201ab

Browse files
Ingo Molnartorvalds
authored andcommitted
ramfs: fix double freeing s_fs_info on failed mount
If ramfs mount fails, s_fs_info will be freed twice in ramfs_fill_super() and ramfs_kill_sb(), leading to kernel oops. Consolidate and beautify the code. Make sure s_fs_info and s_root are in known good states. Acked-by: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4ef4327 commit f8201ab

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎fs/ramfs/inode.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,37 +221,40 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent)
221221
save_mount_options(sb, data);
222222

223223
fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
224+
sb->s_fs_info = fsi;
224225
if (!fsi) {
225226
err = -ENOMEM;
226227
goto fail;
227228
}
228-
sb->s_fs_info = fsi;
229229

230230
err = ramfs_parse_options(data, &fsi->mount_opts);
231231
if (err)
232232
goto fail;
233233

234-
sb->s_maxbytes = MAX_LFS_FILESIZE;
235-
sb->s_blocksize = PAGE_CACHE_SIZE;
236-
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
237-
sb->s_magic = RAMFS_MAGIC;
238-
sb->s_op = &ramfs_ops;
239-
sb->s_time_gran = 1;
234+
sb->s_maxbytes = MAX_LFS_FILESIZE;
235+
sb->s_blocksize = PAGE_CACHE_SIZE;
236+
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
237+
sb->s_magic = RAMFS_MAGIC;
238+
sb->s_op = &ramfs_ops;
239+
sb->s_time_gran = 1;
240+
240241
inode = ramfs_get_inode(sb, S_IFDIR | fsi->mount_opts.mode, 0);
241242
if (!inode) {
242243
err = -ENOMEM;
243244
goto fail;
244245
}
245246

246247
root = d_alloc_root(inode);
248+
sb->s_root = root;
247249
if (!root) {
248250
err = -ENOMEM;
249251
goto fail;
250252
}
251-
sb->s_root = root;
253+
252254
return 0;
253255
fail:
254256
kfree(fsi);
257+
sb->s_fs_info = NULL;
255258
iput(inode);
256259
return err;
257260
}

0 commit comments

Comments
 (0)