• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From f7c9598655420102353ff87946f5bf77ebf465bc Mon Sep 17 00:00:00 2001
2From: "lihaoxiang (F)" <lihaoxiang9@huawei.com>
3Date: Tue, 29 Nov 2022 14:58:12 +0800
4Subject: [PATCH] tune2fs: check return value of ext2fs_mmp_update2 in
5 rewrite_metadata_checksums
6
7Tune2fs hasn't consider about the result of executing ext2fs_mmp_update2
8when it try to rewrite_metadata_checksums. If the ext2fs_mmp_update2
9failed, multi-mount protection couldn't guard there has the only node
10(i.e. this program) accessing this device in the meantime.
11
12We solve this problem to verify the return value of ext2fs_mmp_update2.
13It terminate rewrite_metadata_checksums and exit immediately if the
14wrong error code returned.
15
16Signed-off-by: lihaoxiang <lihaoxiang9@huawei.com>
17Signed-off-by: Theodore Ts'o <tytso@mit.edu>
18---
19 misc/tune2fs.c | 17 +++++++++++++----
20 1 file changed, 13 insertions(+), 4 deletions(-)
21
22diff --git a/misc/tune2fs.c b/misc/tune2fs.c
23index b1e49b3..cb5f575 100644
24--- a/misc/tune2fs.c
25+++ b/misc/tune2fs.c
26@@ -930,7 +930,7 @@ static void rewrite_inodes(ext2_filsys fs, unsigned int flags)
27 	ext2fs_free_mem(&ctx.ea_buf);
28 }
29
30-static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
31+static errcode_t rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
32 {
33 	errcode_t retval;
34 	dgrp_t i;
35@@ -945,7 +945,9 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
36 	rewrite_inodes(fs, flags);
37 	ext2fs_mark_ib_dirty(fs);
38 	ext2fs_mark_bb_dirty(fs);
39-	ext2fs_mmp_update2(fs, 1);
40+	retval = ext2fs_mmp_update2(fs, 1);
41+	if (retval)
42+		return retval;
43 	fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
44 	fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
45 	if (ext2fs_has_feature_metadata_csum(fs->super))
46@@ -953,6 +955,7 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
47 	else
48 		fs->super->s_checksum_type = 0;
49 	ext2fs_mark_super_dirty(fs);
50+	return 0;
51 }
52
53 static void enable_uninit_bg(ext2_filsys fs)
54@@ -3412,8 +3415,14 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
55 		}
56 	}
57
58-	if (rewrite_checksums)
59-		rewrite_metadata_checksums(fs, rewrite_checksums);
60+	if (rewrite_checksums) {
61+		retval = rewrite_metadata_checksums(fs, rewrite_checksums);
62+		if (retval != 0) {
63+			printf("Failed to rewrite metadata checksums\n");
64+			rc = 1;
65+			goto closefs;
66+		}
67+	}
68
69 	if (l_flag)
70 		list_super(sb);
71--
721.8.3.1
73
74