From 73be22a5ba44f62dbc387586a22a51b8e37b12b3 Mon Sep 17 00:00:00 2001 From: Jens Maus Date: Sat, 16 Sep 2023 22:45:04 +0200 Subject: [PATCH] added new 0018-grub2-fix-incompat-ext2 buildroot upstream patch which patches grub2 to ignore certain newer ext filesystem features which could hinder grub2 from correctly recognized an ext filesystem thought it is still valid. This is especially critical for the metadata checksum seed feature which since the latest e2fsck 1.47.0 version is now a default settings, thus renders new ext filesystems as grub2 incompatible without these upstream grub2 patches not part of buildroot yet. (cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1031325, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1030939) --- .../0018-grub2-fix-incompat-ext2.patch | 123 ++++++++++++++++++ ...gnore-checksum-seed-incompat-feature.patch | 59 +++++++++ ...-checksum-seed-incompat-feature.patch.orig | 0 ...gnore-the-large_dir-incompat-feature.patch | 58 +++++++++ ...-the-large_dir-incompat-feature.patch.orig | 0 5 files changed, 240 insertions(+) create mode 100644 buildroot-patches/0018-grub2-fix-incompat-ext2.patch create mode 100644 buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch create mode 100644 buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch.orig create mode 100644 buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch create mode 100644 buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch.orig diff --git a/buildroot-patches/0018-grub2-fix-incompat-ext2.patch b/buildroot-patches/0018-grub2-fix-incompat-ext2.patch new file mode 100644 index 0000000000..a07884bacf --- /dev/null +++ b/buildroot-patches/0018-grub2-fix-incompat-ext2.patch @@ -0,0 +1,123 @@ +--- buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch.orig ++++ buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch +@@ -0,0 +1,59 @@ ++From 7fd5feff97c4b1f446f8fcf6d37aca0c64e7c763 Mon Sep 17 00:00:00 2001 ++From: Javier Martinez Canillas ++Date: Fri, 11 Jun 2021 21:36:16 +0200 ++Subject: fs/ext2: Ignore checksum seed incompat feature ++ ++This incompat feature is used to denote that the filesystem stored its ++metadata checksum seed in the superblock. This is used to allow tune2fs ++changing the UUID on a mounted metdata_csum filesystem without having ++to rewrite all the disk metadata. However, the GRUB doesn't use the ++metadata checksum at all. So, it can just ignore this feature if it ++is enabled. This is consistent with the GRUB filesystem code in general ++which just does a best effort to access the filesystem's data. ++ ++The checksum seed incompat feature has to be removed from the ignore ++list if the support for metadata checksum verification is added to the ++GRUB ext2 driver later. ++ ++Suggested-by: Eric Sandeen ++Suggested-by: Lukas Czerner ++Signed-off-by: Javier Martinez Canillas ++Reviewed-by: Lukas Czerner ++Reviewed-by: Daniel Kiper ++--- ++ grub-core/fs/ext2.c | 10 ++++++++-- ++ 1 file changed, 8 insertions(+), 2 deletions(-) ++ ++diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c ++index e7dd78e..4953a15 100644 ++--- a/grub-core/fs/ext2.c +++++ b/grub-core/fs/ext2.c ++@@ -103,6 +103,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); ++ #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 ++ #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 ++ #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 +++#define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 ++ #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 ++ ++ /* The set of back-incompatible features this driver DOES support. Add (OR) ++@@ -123,10 +124,15 @@ GRUB_MOD_LICENSE ("GPLv3+"); ++ * mmp: Not really back-incompatible - was added as such to ++ * avoid multiple read-write mounts. Safe to ignore for this ++ * RO driver. +++ * checksum seed: Not really back-incompatible - was added to allow tools +++ * such as tune2fs to change the UUID on a mounted metadata +++ * checksummed filesystem. Safe to ignore for now since the +++ * driver doesn't support checksum verification. However, it +++ * has to be removed from this list if the support is added later. ++ */ ++ #define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER \ ++- | EXT4_FEATURE_INCOMPAT_MMP) ++- +++ | EXT4_FEATURE_INCOMPAT_MMP \ +++ | EXT4_FEATURE_INCOMPAT_CSUM_SEED) ++ ++ #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U ++ ++-- ++cgit v1.1 ++ +--- buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch.orig ++++ buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch +@@ -0,0 +1,58 @@ ++From 2e9fa73a040462b81bfbfe56c0bc7ad2d30b446b Mon Sep 17 00:00:00 2001 ++From: Theodore Ts'o ++Date: Tue, 30 Aug 2022 22:41:59 -0400 ++Subject: fs/ext2: Ignore the large_dir incompat feature ++ ++Recently, ext4 added the large_dir feature, which adds support for ++a 3 level htree directory support. ++ ++The GRUB supports existing file systems with htree directories by ++ignoring their existence, and since the index nodes for the hash tree ++look like deleted directory entries (by design), the GRUB can simply do ++a brute force O(n) linear search of directories. The same is true for ++3 level deep htrees indicated by large_dir feature flag. ++ ++Hence, it is safe for the GRUB to ignore the large_dir incompat feature. ++ ++Fixes: https://savannah.gnu.org/bugs/?61606 ++ ++Signed-off-by: Theodore Ts'o ++Reviewed-by: Daniel Kiper ++--- ++ grub-core/fs/ext2.c | 10 +++++++++- ++ 1 file changed, 9 insertions(+), 1 deletion(-) ++ ++diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c ++index 0989e26..e1cc5e6 100644 ++--- a/grub-core/fs/ext2.c +++++ b/grub-core/fs/ext2.c ++@@ -104,6 +104,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); ++ #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 ++ #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 ++ #define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 +++#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3 level htree */ ++ #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 ++ ++ /* The set of back-incompatible features this driver DOES support. Add (OR) ++@@ -129,10 +130,17 @@ GRUB_MOD_LICENSE ("GPLv3+"); ++ * checksummed filesystem. Safe to ignore for now since the ++ * driver doesn't support checksum verification. However, it ++ * has to be removed from this list if the support is added later. +++ * large_dir: Not back-incompatible given that the GRUB ext2 driver does +++ * not implement EXT2_FEATURE_COMPAT_DIR_INDEX. If the GRUB +++ * eventually supports the htree feature (aka dir_index) +++ * it should support 3 level htrees and then move +++ * EXT4_FEATURE_INCOMPAT_LARGEDIR to +++ * EXT2_DRIVER_SUPPORTED_INCOMPAT. ++ */ ++ #define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER \ ++ | EXT4_FEATURE_INCOMPAT_MMP \ ++- | EXT4_FEATURE_INCOMPAT_CSUM_SEED) +++ | EXT4_FEATURE_INCOMPAT_CSUM_SEED \ +++ | EXT4_FEATURE_INCOMPAT_LARGEDIR) ++ ++ #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U ++ ++-- ++cgit v1.1 ++ diff --git a/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch b/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch new file mode 100644 index 0000000000..27b2277c40 --- /dev/null +++ b/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch @@ -0,0 +1,59 @@ +From 7fd5feff97c4b1f446f8fcf6d37aca0c64e7c763 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 11 Jun 2021 21:36:16 +0200 +Subject: fs/ext2: Ignore checksum seed incompat feature + +This incompat feature is used to denote that the filesystem stored its +metadata checksum seed in the superblock. This is used to allow tune2fs +changing the UUID on a mounted metdata_csum filesystem without having +to rewrite all the disk metadata. However, the GRUB doesn't use the +metadata checksum at all. So, it can just ignore this feature if it +is enabled. This is consistent with the GRUB filesystem code in general +which just does a best effort to access the filesystem's data. + +The checksum seed incompat feature has to be removed from the ignore +list if the support for metadata checksum verification is added to the +GRUB ext2 driver later. + +Suggested-by: Eric Sandeen +Suggested-by: Lukas Czerner +Signed-off-by: Javier Martinez Canillas +Reviewed-by: Lukas Czerner +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ext2.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index e7dd78e..4953a15 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -103,6 +103,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 + #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 + #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 ++#define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 + #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 + + /* The set of back-incompatible features this driver DOES support. Add (OR) +@@ -123,10 +124,15 @@ GRUB_MOD_LICENSE ("GPLv3+"); + * mmp: Not really back-incompatible - was added as such to + * avoid multiple read-write mounts. Safe to ignore for this + * RO driver. ++ * checksum seed: Not really back-incompatible - was added to allow tools ++ * such as tune2fs to change the UUID on a mounted metadata ++ * checksummed filesystem. Safe to ignore for now since the ++ * driver doesn't support checksum verification. However, it ++ * has to be removed from this list if the support is added later. + */ + #define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER \ +- | EXT4_FEATURE_INCOMPAT_MMP) +- ++ | EXT4_FEATURE_INCOMPAT_MMP \ ++ | EXT4_FEATURE_INCOMPAT_CSUM_SEED) + + #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U + +-- +cgit v1.1 + diff --git a/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch.orig b/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0019-Ignore-checksum-seed-incompat-feature.patch.orig new file mode 100644 index 0000000000..e69de29bb2 diff --git a/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch b/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch new file mode 100644 index 0000000000..957b66f2c1 --- /dev/null +++ b/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch @@ -0,0 +1,58 @@ +From 2e9fa73a040462b81bfbfe56c0bc7ad2d30b446b Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Tue, 30 Aug 2022 22:41:59 -0400 +Subject: fs/ext2: Ignore the large_dir incompat feature + +Recently, ext4 added the large_dir feature, which adds support for +a 3 level htree directory support. + +The GRUB supports existing file systems with htree directories by +ignoring their existence, and since the index nodes for the hash tree +look like deleted directory entries (by design), the GRUB can simply do +a brute force O(n) linear search of directories. The same is true for +3 level deep htrees indicated by large_dir feature flag. + +Hence, it is safe for the GRUB to ignore the large_dir incompat feature. + +Fixes: https://savannah.gnu.org/bugs/?61606 + +Signed-off-by: Theodore Ts'o +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ext2.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index 0989e26..e1cc5e6 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -104,6 +104,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 + #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 + #define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 ++#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3 level htree */ + #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 + + /* The set of back-incompatible features this driver DOES support. Add (OR) +@@ -129,10 +130,17 @@ GRUB_MOD_LICENSE ("GPLv3+"); + * checksummed filesystem. Safe to ignore for now since the + * driver doesn't support checksum verification. However, it + * has to be removed from this list if the support is added later. ++ * large_dir: Not back-incompatible given that the GRUB ext2 driver does ++ * not implement EXT2_FEATURE_COMPAT_DIR_INDEX. If the GRUB ++ * eventually supports the htree feature (aka dir_index) ++ * it should support 3 level htrees and then move ++ * EXT4_FEATURE_INCOMPAT_LARGEDIR to ++ * EXT2_DRIVER_SUPPORTED_INCOMPAT. + */ + #define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER \ + | EXT4_FEATURE_INCOMPAT_MMP \ +- | EXT4_FEATURE_INCOMPAT_CSUM_SEED) ++ | EXT4_FEATURE_INCOMPAT_CSUM_SEED \ ++ | EXT4_FEATURE_INCOMPAT_LARGEDIR) + + #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U + +-- +cgit v1.1 + diff --git a/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch.orig b/buildroot-patches/0018-grub2-fix-incompat-ext2/buildroot/boot/grub2/0020-Ignore-the-large_dir-incompat-feature.patch.orig new file mode 100644 index 0000000000..e69de29bb2