• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 66ecb6abe5d2c74191bb4bc24f3da036e5fa1213 Mon Sep 17 00:00:00 2001
2From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
3Date: Mon, 5 Sep 2022 19:16:03 +0800
4Subject: [PATCH] tune2fs: fix tune2fs segfault when ext2fs_run_ext3_journal()
5 fails
6
7When ext2fs_run_ext3_journal() fails, tune2fs cmd will occur one
8segfault problem as follows.
9(gdb) bt
10#0  0x00007fdadad69917 in ext2fs_mmp_stop (fs=0x0) at mmp.c:405
11#1  0x0000558fa5a9365a in main (argc=<optimized out>, argv=<optimized out>) at tune2fs.c:3440
12
13misc/tune2fs.c:
14main()
15  -> ext2fs_open2(&fs)
16    -> ext2fs_mmp_start
17  ......
18  -> retval = ext2fs_run_ext3_journal(&fs)
19  -> if (retval)
20    // if ext2fs_run_ext3_journal fails, close and free fs.
21    -> ext2fs_close_free(&fs)
22    -> rc = 1
23    -> goto closefs
24  ......
25closefs:
26  -> if (rc)
27    -> ext2fs_mmp_stop(fs)     // fs has been set to NULL, boom!!
28  -> (ext2fs_close_free(&fs) ? 1 : 0); // close and free fs
29
30In main() of tune2fs cmd, if ext2fs_run_ext3_journal() fails,
31we should set rc=1 and goto closefs tag, in which will release fs
32resource.
33
34Fix: a2292f8a5108 ("tune2fs: reset MMP state on error exit")
35Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
36Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
37Signed-off-by: Theodore Ts'o <tytso@mit.edu>
38---
39 misc/tune2fs.c | 2 --
40 1 file changed, 2 deletions(-)
41
42diff --git a/misc/tune2fs.c b/misc/tune2fs.c
43index a7ff16de..98e38983 100644
44--- a/misc/tune2fs.c
45+++ b/misc/tune2fs.c
46@@ -3106,8 +3106,6 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
47 			com_err("tune2fs", retval,
48 				"while recovering journal.\n");
49 			printf(_("Please run e2fsck -fy %s.\n"), argv[1]);
50-			if (fs)
51-				ext2fs_close_free(&fs);
52 			rc = 1;
53 			goto closefs;
54 		}
55--
562.33.0
57
58