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 <viro@zeniv.linux.org.uk>
Acked-by: Josh Boyer <jwboyer@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Al Viro and committed by Linus Torvalds d6042eac 8a88951b

Changed files
+17 -17
fs
minix
+17 -17
fs/minix/inode.c
··· 263 goto out_no_root; 264 } 265 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 - 283 /* Apparently minix can create filesystems that allocate more blocks for 284 * the bitmaps than needed. We simply ignore that, but verify it didn't 285 * create one with not enough blocks and bail out if so. ··· 282 "zmap blocks allocated. Refusing to mount.\n"); 283 goto out_iput; 284 } 285 286 return 0; 287
··· 263 goto out_no_root; 264 } 265 266 /* Apparently minix can create filesystems that allocate more blocks for 267 * the bitmaps than needed. We simply ignore that, but verify it didn't 268 * create one with not enough blocks and bail out if so. ··· 299 "zmap blocks allocated. Refusing to mount.\n"); 300 goto out_iput; 301 } 302 + 303 + ret = -ENOMEM; 304 + s->s_root = d_alloc_root(root_inode); 305 + if (!s->s_root) 306 + goto out_iput; 307 + 308 + if (!(s->s_flags & MS_RDONLY)) { 309 + if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */ 310 + ms->s_state &= ~MINIX_VALID_FS; 311 + mark_buffer_dirty(bh); 312 + } 313 + if (!(sbi->s_mount_state & MINIX_VALID_FS)) 314 + printk("MINIX-fs: mounting unchecked file system, " 315 + "running fsck is recommended\n"); 316 + else if (sbi->s_mount_state & MINIX_ERROR_FS) 317 + printk("MINIX-fs: mounting file system with errors, " 318 + "running fsck is recommended\n"); 319 320 return 0; 321