Whamcloud - gitweb
tune2fs: fix tune2fs segfault when ext2fs_run_ext3_journal() fails
authorZhiqiang Liu <liuzhiqiang26@huawei.com>
Mon, 5 Sep 2022 11:16:03 +0000 (19:16 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 12 Sep 2022 11:50:54 +0000 (07:50 -0400)
commit66ecb6abe5d2c74191bb4bc24f3da036e5fa1213
tree9c0cf95afd49cf1dbbceb4912b3159114195ea07
parent836e8a61b4b10e69f698f43c27a0a43c81993eb2
tune2fs: fix tune2fs segfault when ext2fs_run_ext3_journal() fails

When ext2fs_run_ext3_journal() fails, tune2fs cmd will occur one
segfault problem as follows.
(gdb) bt
#0  0x00007fdadad69917 in ext2fs_mmp_stop (fs=0x0) at mmp.c:405
#1  0x0000558fa5a9365a in main (argc=<optimized out>, argv=<optimized out>) at tune2fs.c:3440

misc/tune2fs.c:
main()
  -> ext2fs_open2(&fs)
    -> ext2fs_mmp_start
  ......
  -> retval = ext2fs_run_ext3_journal(&fs)
  -> if (retval)
    // if ext2fs_run_ext3_journal fails, close and free fs.
    -> ext2fs_close_free(&fs)
    -> rc = 1
    -> goto closefs
  ......
closefs:
  -> if (rc)
    -> ext2fs_mmp_stop(fs)     // fs has been set to NULL, boom!!
  -> (ext2fs_close_free(&fs) ? 1 : 0); // close and free fs

In main() of tune2fs cmd, if ext2fs_run_ext3_journal() fails,
we should set rc=1 and goto closefs tag, in which will release fs
resource.

Fix: a2292f8a5108 ("tune2fs: reset MMP state on error exit")
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/tune2fs.c