SHA256
1
0
forked from pool/grub2

Accepting request 1141134 from home:michael-chang:bsc:1218864

- Reinstate the verification for a non-zero total entry count to skip unmapped
  data blocks (bsc#1218864)
  * 0001-fs-xfs-always-verify-the-total-number-of-entries-is-.patch
- Removed temporary fix as reverting it will cause a different XFS parser bug
  * 0001-Revert-fs-xfs-Fix-XFS-directory-extent-parsing.patch

OBS-URL: https://build.opensuse.org/request/show/1141134
OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=483
This commit is contained in:
Michael Chang 2024-01-24 08:25:10 +00:00 committed by Git OBS Bridge
parent 8d02eb8f36
commit d203d36f81
4 changed files with 58 additions and 108 deletions

View File

@ -1,107 +0,0 @@
From 664a8569c5c8c101879b384dbdaa81dc38cf2f68 Mon Sep 17 00:00:00 2001
From: Michael Chang <mchang@suse.com>
Date: Wed, 17 Jan 2024 11:23:35 +0800
Subject: [PATCH] Revert "fs/xfs: Fix XFS directory extent parsing"
This reverts commit 07318ee7e11a00b9c1dea4c6b4edf62af35a511a.
---
grub-core/fs/xfs.c | 52 +++++++++++++---------------------------------
1 file changed, 14 insertions(+), 38 deletions(-)
diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
index bc2224dbb..9dfe3a2fa 100644
--- a/grub-core/fs/xfs.c
+++ b/grub-core/fs/xfs.c
@@ -228,12 +228,6 @@ struct grub_xfs_inode
/* Size of struct grub_xfs_inode v2, up to unused4 member included. */
#define XFS_V2_INODE_SIZE (XFS_V3_INODE_SIZE - 76)
-struct grub_xfs_dir_leaf_entry
-{
- grub_uint32_t hashval;
- grub_uint32_t address;
-} GRUB_PACKED;
-
struct grub_xfs_dirblock_tail
{
grub_uint32_t leaf_count;
@@ -900,8 +894,9 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
{
struct grub_xfs_dir2_entry *direntry =
grub_xfs_first_de(dir->data, dirblock);
- int entries = -1;
- char *end = dirblock + dirblk_size;
+ int entries;
+ struct grub_xfs_dirblock_tail *tail =
+ grub_xfs_dir_tail(dir->data, dirblock);
numread = grub_xfs_read_file (dir, 0, 0,
blk << dirblk_log2,
@@ -912,27 +907,14 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
return 0;
}
- /*
- * Leaf and tail information are only in the data block if the number
- * of extents is 1.
- */
- if (dir->inode.nextents == grub_cpu_to_be32_compile_time (1))
- {
- struct grub_xfs_dirblock_tail *tail = grub_xfs_dir_tail (dir->data, dirblock);
-
- end = (char *) tail;
-
- /* Subtract the space used by leaf nodes. */
- end -= grub_be_to_cpu32 (tail->leaf_count) * sizeof (struct grub_xfs_dir_leaf_entry);
+ entries = (grub_be_to_cpu32 (tail->leaf_count)
+ - grub_be_to_cpu32 (tail->leaf_stale));
- entries = grub_be_to_cpu32 (tail->leaf_count) - grub_be_to_cpu32 (tail->leaf_stale);
-
- if (!entries)
- continue;
- }
+ if (!entries)
+ continue;
/* Iterate over all entries within this block. */
- while ((char *) direntry < (char *) end)
+ while ((char *)direntry < (char *)tail)
{
grub_uint8_t *freetag;
char *filename;
@@ -952,7 +934,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
}
filename = (char *)(direntry + 1);
- if (filename + direntry->len + 1 > (char *) end)
+ if (filename + direntry->len - 1 > (char *) tail)
return grub_error (GRUB_ERR_BAD_FS, "invalid XFS directory entry");
/* The byte after the filename is for the filetype, padding, or
@@ -966,17 +948,11 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
return 1;
}
- /*
- * The expected number of directory entries is only tracked for the
- * single extent case.
- */
- if (dir->inode.nextents == grub_cpu_to_be32_compile_time (1))
- {
- /* Check if last direntry in this block is reached. */
- entries--;
- if (!entries)
- break;
- }
+ /* Check if last direntry in this block is
+ reached. */
+ entries--;
+ if (!entries)
+ break;
/* Select the next directory entry. */
direntry = grub_xfs_next_de(dir->data, direntry);
--
2.43.0

View File

@ -0,0 +1,48 @@
From 045aae8fe7238aabc217700df4d17d83b7d891f3 Mon Sep 17 00:00:00 2001
From: Michael Chang <mchang@suse.com>
Date: Tue, 23 Jan 2024 12:46:16 +0800
Subject: [PATCH] fs/xfs: always verify the total number of entries is not zero
---
grub-core/fs/xfs.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
index bc2224dbb..1ce5fa4fc 100644
--- a/grub-core/fs/xfs.c
+++ b/grub-core/fs/xfs.c
@@ -900,6 +900,8 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
{
struct grub_xfs_dir2_entry *direntry =
grub_xfs_first_de(dir->data, dirblock);
+ struct grub_xfs_dirblock_tail *tail = grub_xfs_dir_tail (dir->data, dirblock);
+
int entries = -1;
char *end = dirblock + dirblk_size;
@@ -918,18 +920,16 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
*/
if (dir->inode.nextents == grub_cpu_to_be32_compile_time (1))
{
- struct grub_xfs_dirblock_tail *tail = grub_xfs_dir_tail (dir->data, dirblock);
-
end = (char *) tail;
/* Subtract the space used by leaf nodes. */
end -= grub_be_to_cpu32 (tail->leaf_count) * sizeof (struct grub_xfs_dir_leaf_entry);
+ }
- entries = grub_be_to_cpu32 (tail->leaf_count) - grub_be_to_cpu32 (tail->leaf_stale);
+ entries = grub_be_to_cpu32 (tail->leaf_count) - grub_be_to_cpu32 (tail->leaf_stale);
- if (!entries)
- continue;
- }
+ if (!entries)
+ continue;
/* Iterate over all entries within this block. */
while ((char *) direntry < (char *) end)
--
2.43.0

View File

@ -1,3 +1,12 @@
-------------------------------------------------------------------
Tue Jan 23 04:56:58 UTC 2024 - Michael Chang <mchang@suse.com>
- Reinstate the verification for a non-zero total entry count to skip unmapped
data blocks (bsc#1218864)
* 0001-fs-xfs-always-verify-the-total-number-of-entries-is-.patch
- Removed temporary fix as reverting it will cause a different XFS parser bug
* 0001-Revert-fs-xfs-Fix-XFS-directory-extent-parsing.patch
-------------------------------------------------------------------
Sat Jan 20 20:08:34 UTC 2024 - Giacomo Comes <gcomes.obs@gmail.com>

View File

@ -387,7 +387,7 @@ Patch194: 0003-Restrict-ls-and-auto-file-completion-on-cryptodisk-p.patch
Patch195: 0004-Key-revocation-on-out-of-bound-file-access.patch
# Workaround for 2.12 tarball
Patch196: fix_no_extra_deps_in_release_tarball.patch
Patch197: 0001-Revert-fs-xfs-Fix-XFS-directory-extent-parsing.patch
Patch197: 0001-fs-xfs-always-verify-the-total-number-of-entries-is-.patch
Requires: gettext-runtime
%if 0%{?suse_version} >= 1140