Skip to content

Commit d6042ea

Browse files
Al Virotorvalds
authored andcommitted
minixfs: misplaced checks lead to dentry leak
bitmap size sanity checks should be done *before* allocating ->s_root; there their cleanup on failure would be correct. As it is, we do iput() on root inode, but leak the root dentry... Signed-off-by: Al Viro <[email protected]> Acked-by: Josh Boyer <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8a88951 commit d6042ea

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

fs/minix/inode.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,23 +263,6 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
263263
goto out_no_root;
264264
}
265265

266-
ret = -ENOMEM;
267-
s->s_root = d_alloc_root(root_inode);
268-
if (!s->s_root)
269-
goto out_iput;
270-
271-
if (!(s->s_flags & MS_RDONLY)) {
272-
if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
273-
ms->s_state &= ~MINIX_VALID_FS;
274-
mark_buffer_dirty(bh);
275-
}
276-
if (!(sbi->s_mount_state & MINIX_VALID_FS))
277-
printk("MINIX-fs: mounting unchecked file system, "
278-
"running fsck is recommended\n");
279-
else if (sbi->s_mount_state & MINIX_ERROR_FS)
280-
printk("MINIX-fs: mounting file system with errors, "
281-
"running fsck is recommended\n");
282-
283266
/* Apparently minix can create filesystems that allocate more blocks for
284267
* the bitmaps than needed. We simply ignore that, but verify it didn't
285268
* create one with not enough blocks and bail out if so.
@@ -300,6 +283,23 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
300283
goto out_iput;
301284
}
302285

286+
ret = -ENOMEM;
287+
s->s_root = d_alloc_root(root_inode);
288+
if (!s->s_root)
289+
goto out_iput;
290+
291+
if (!(s->s_flags & MS_RDONLY)) {
292+
if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
293+
ms->s_state &= ~MINIX_VALID_FS;
294+
mark_buffer_dirty(bh);
295+
}
296+
if (!(sbi->s_mount_state & MINIX_VALID_FS))
297+
printk("MINIX-fs: mounting unchecked file system, "
298+
"running fsck is recommended\n");
299+
else if (sbi->s_mount_state & MINIX_ERROR_FS)
300+
printk("MINIX-fs: mounting file system with errors, "
301+
"running fsck is recommended\n");
302+
303303
return 0;
304304

305305
out_iput:

0 commit comments

Comments
 (0)