Skip to contentSkip to conversation

tune2fs: prohibit toggling uninit_bg on live filesystems

PATCH Applied Darrick J. Wong 2 participants 2 messages Nov 20, 2019 – Nov 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tune2fs: prohibit toggling uninit_bg on live filesystems

From: Darrick J. Wong <[email protected]>

An internal customer followed an erroneous AskUbuntu article[1] to try to change the UUID of a live ext4 filesystem. The article claims that you can work around tune2fs' "cannot change UUID on live fs" error by disabling uninit_bg, changing the UUID, and re-enabling the feature.

This led to metadata corruption because tune2fs' journal descriptor rewrite races with regular filesystem writes. Therefore, prevent administrators from turning on or off uninit_bg on a mounted fs.

[1] https://askubuntu.com/questions/132079/how-do-i-change-uuid-of-a-disk-to-whatever-i-want/195839#459097

---
 misc/tune2fs.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
misc/tune2fs.c +12 -0
index 8368a733..150dc916 100644
@@ -1312,6 +1312,12 @@ static int update_feature_set(ext2_filsys fs, char *features)
 
 	if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
 		       EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
+		if (mount_flags & EXT2_MF_MOUNTED) {
+			fputs(_("Cannot enable uninit_bg on a mounted "
+				"filesystem!\n"), stderr);
+			exit(1);
+		}
+
 		/* Do not enable uninit_bg when metadata_csum enabled */
 		if (ext2fs_has_feature_metadata_csum(fs->super))
 			ext2fs_clear_feature_gdt_csum(fs->super);
@@ -1321,6 +1327,12 @@ static int update_feature_set(ext2_filsys fs, char *features)
 
 	if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
 			EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
+		if (mount_flags & EXT2_MF_MOUNTED) {
+			fputs(_("Cannot disable uninit_bg on a mounted "
+				"filesystem!\n"), stderr);
+			exit(1);
+		}
+
 		err = disable_uninit_bg(fs,
 				EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
 		if (err)
#1 lore raw
Quoted 7 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

An internal customer followed an erroneous AskUbuntu article[1] to try to change the UUID of a live ext4 filesystem. The article claims that you can work around tune2fs' "cannot change UUID on live fs" error by disabling uninit_bg, changing the UUID, and re-enabling the feature.

Quoted 7 lines

This led to metadata corruption because tune2fs' journal descriptor rewrite races with regular filesystem writes. Therefore, prevent administrators from turning on or off uninit_bg on a mounted fs.

[1] https://askubuntu.com/questions/132079/how-do-i-change-uuid-of-a-disk-to-whatever-i-want/195839#459097

Thanks, applied.

- Ted