Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grub2: update grub to sbat level 4 #8795

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Summary: Signed GRand Unified Bootloader for %{buildarch} systems
Name: grub2-efi-binary-signed-%{buildarch}
Version: 2.06
Release: 17%{?dist}
Release: 18%{?dist}
License: GPLv3+
Vendor: Microsoft Corporation
Distribution: Azure Linux
Expand Down Expand Up @@ -79,6 +79,9 @@ cp %{SOURCE3} %{buildroot}/boot/efi/EFI/BOOT/%{grubpxeefiname}
/boot/efi/EFI/BOOT/%{grubpxeefiname}

%changelog
* Mon Apr 15 2024 Dan Streetman <[email protected]> - 2.06-18
- update grub to sbat 4

* Wed Mar 20 2024 Cameron Baird <[email protected]> - 2.06-17
- Bump release number to match grub release number

Expand Down
2 changes: 1 addition & 1 deletion SPECS/grub2/grub2.signatures.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"gnulib-d271f868a8df9bbec29049d01e056481b7a1a263.tar.gz": "4e23415ae2977ffca15e07419ceff3e9334d0369eafc9e7ae2578f8dd9a4839c",
"grub-2.06.tar.gz": "660eaa2355a4045d8d0cdb5765169d1cad9912ec07873b86c9c6d55dbaa9dfca",
"macros.grub2": "b03f6f713601214406971de53538dfc25136bf836f09a663eaffc4332a72c38b",
"sbat.csv.in": "0d06d0ae6064e0e01410281aa88050bf671dc23f7c490fbf1b56619c4d122e87"
"sbat.csv.in": "040bcd900845b53ef9124f70f8b40fbd169740681fdd519a688663a59a958cf1"
}
}
23 changes: 22 additions & 1 deletion SPECS/grub2/grub2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Summary: GRand Unified Bootloader
Name: grub2
Version: 2.06
Release: 17%{?dist}
Release: 18%{?dist}
License: GPLv3+
Vendor: Microsoft Corporation
Distribution: Azure Linux
Expand Down Expand Up @@ -85,6 +85,24 @@ Patch0199: 0199-fs-f2fs-Do-not-copy-file-names-that-are-too-long.patch
Patch0200: 0200-fs-btrfs-Fix-several-fuzz-issues-with-invalid-dir-it.patch
Patch0201: 0201-fs-btrfs-Fix-more-ASAN-and-SEGV-issues-found-with-fu.patch
Patch0202: 0202-fs-btrfs-Fix-more-fuzz-issues-related-to-chunks.patch
# Required to reach SBAT 3
Patch: sbat-3-0001-font-Reject-glyphs-exceeds-font-max_glyph_width-or-f.patch
Patch: sbat-3-0004-font-Remove-grub_font_dup_glyph.patch
Patch: sbat-3-0005-font-Fix-integer-overflow-in-ensure_comb_space.patch
Patch: sbat-3-0006-font-Fix-integer-overflow-in-BMP-index.patch
Patch: sbat-3-0007-font-Fix-integer-underflow-in-binary-search-of-char-.patch
Patch: sbat-3-0008-kern-efi-sb-Enforce-verification-of-font-files.patch
Patch: sbat-3-0009-fbutil-Fix-integer-overflow.patch
Patch: sbat-3-0011-font-Harden-grub_font_blit_glyph-and-grub_font_blit_.patch
Patch: sbat-3-0012-font-Assign-null_font-to-glyphs-in-ascii_font_glyph.patch
Patch: sbat-3-0013-normal-charset-Fix-an-integer-overflow-in-grub_unico.patch
# Required to reach SBAT 4
Patch: sbat-4-0001-fs-ntfs-Fix-an-OOB-write-when-parsing-the-ATTRIBUTE_.patch
Patch: sbat-4-0002-fs-ntfs-Fix-an-OOB-read-when-reading-data-from-the-r.patch
Patch: sbat-4-0003-fs-ntfs-Fix-an-OOB-read-when-parsing-directory-entri.patch
Patch: sbat-4-0004-fs-ntfs-Fix-an-OOB-read-when-parsing-bitmaps-for-ind.patch
Patch: sbat-4-0005-fs-ntfs-Fix-an-OOB-read-when-parsing-a-volume-label.patch
Patch: sbat-4-0006-fs-ntfs-Make-code-more-readable.patch
BuildRequires: autoconf
BuildRequires: device-mapper-devel
BuildRequires: python3
Expand Down Expand Up @@ -422,6 +440,9 @@ cp $GRUB_PXE_MODULE_SOURCE $EFI_BOOT_DIR/$GRUB_PXE_MODULE_NAME
%config(noreplace) %{_sysconfdir}/grub.d/41_custom

%changelog
* Mon Apr 15 2024 Dan Streetman <[email protected]> - 2.06-18
- update grub to sbat 4

* Tue Mar 19 2024 Cameron Baird <[email protected]> - 2.06-17
- Introduce grub2-tools-minimal subpackage

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From f6b6236077f059e64ee315f2d7acb8fa4eda87c5 Mon Sep 17 00:00:00 2001
From: Zhang Boyang <[email protected]>
Date: Wed, 3 Aug 2022 19:45:33 +0800
Subject: [PATCH 01/13] font: Reject glyphs exceeds font->max_glyph_width or
font->max_glyph_height

Check glyph's width and height against limits specified in font's
metadata. Reject the glyph (and font) if such limits are exceeded.

Signed-off-by: Zhang Boyang <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
---
grub-core/font/font.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index 42189c325..756ca0abf 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -760,7 +760,9 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
|| read_be_uint16 (font->file, &height) != 0
|| read_be_int16 (font->file, &xoff) != 0
|| read_be_int16 (font->file, &yoff) != 0
- || read_be_int16 (font->file, &dwidth) != 0)
+ || read_be_int16 (font->file, &dwidth) != 0
+ || width > font->max_char_width
+ || height > font->max_char_height)
{
remove_font (font);
return 0;
--
2.34.1

42 changes: 42 additions & 0 deletions SPECS/grub2/sbat-3-0004-font-Remove-grub_font_dup_glyph.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From c51292274ded3259eb04c2f1c8d253ffbdb5216a Mon Sep 17 00:00:00 2001
From: Zhang Boyang <[email protected]>
Date: Fri, 5 Aug 2022 02:13:29 +0800
Subject: [PATCH 04/13] font: Remove grub_font_dup_glyph()

Remove grub_font_dup_glyph() since nobody is using it since 2013, and
I'm too lazy to fix the integer overflow problem in it.

Signed-off-by: Zhang Boyang <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
---
grub-core/font/font.c | 14 --------------
1 file changed, 14 deletions(-)

diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index e6548892f..a8576ffec 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -1055,20 +1055,6 @@ grub_font_get_glyph_with_fallback (grub_font_t font, grub_uint32_t code)
return best_glyph;
}

-#if 0
-static struct grub_font_glyph *
-grub_font_dup_glyph (struct grub_font_glyph *glyph)
-{
- static struct grub_font_glyph *ret;
- ret = grub_malloc (sizeof (*ret) + (glyph->width * glyph->height + 7) / 8);
- if (!ret)
- return NULL;
- grub_memcpy (ret, glyph, sizeof (*ret)
- + (glyph->width * glyph->height + 7) / 8);
- return ret;
-}
-#endif
-
/* FIXME: suboptimal. */
static void
grub_font_blit_glyph (struct grub_font_glyph *target,
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
From 23843fe8947e4da955a05ad3d1858725bfcb56c8 Mon Sep 17 00:00:00 2001
From: Zhang Boyang <[email protected]>
Date: Fri, 5 Aug 2022 02:27:05 +0800
Subject: [PATCH 05/13] font: Fix integer overflow in ensure_comb_space()

In fact it can't overflow at all because glyph_id->ncomb is only 8-bit
wide. But let's keep safe if somebody changes the width of glyph_id->ncomb
in the future. This patch also fixes the inconsistency between
render_max_comb_glyphs and render_combining_glyphs when grub_malloc()
returns NULL.

Signed-off-by: Zhang Boyang <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
---
grub-core/font/font.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index a8576ffec..9e3e0a94e 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -1468,14 +1468,18 @@ ensure_comb_space (const struct grub_unicode_glyph *glyph_id)
if (glyph_id->ncomb <= render_max_comb_glyphs)
return;

- render_max_comb_glyphs = 2 * glyph_id->ncomb;
- if (render_max_comb_glyphs < 8)
+ if (grub_mul (glyph_id->ncomb, 2, &render_max_comb_glyphs))
+ render_max_comb_glyphs = 0;
+ if (render_max_comb_glyphs > 0 && render_max_comb_glyphs < 8)
render_max_comb_glyphs = 8;
grub_free (render_combining_glyphs);
- render_combining_glyphs = grub_malloc (render_max_comb_glyphs
- * sizeof (render_combining_glyphs[0]));
+ render_combining_glyphs = (render_max_comb_glyphs > 0) ?
+ grub_calloc (render_max_comb_glyphs, sizeof (render_combining_glyphs[0])) : NULL;
if (!render_combining_glyphs)
- grub_errno = 0;
+ {
+ render_max_comb_glyphs = 0;
+ grub_errno = GRUB_ERR_NONE;
+ }
}

int
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
From b9396daf1c2e3cdc0a1e69b056852e0769fb24de Mon Sep 17 00:00:00 2001
From: Zhang Boyang <[email protected]>
Date: Mon, 15 Aug 2022 02:04:58 +0800
Subject: [PATCH 06/13] font: Fix integer overflow in BMP index

The BMP index (font->bmp_idx) is designed as a reverse lookup table of
char entries (font->char_index), in order to speed up lookups for BMP
chars (i.e. code < 0x10000). The values in BMP index are the subscripts
of the corresponding char entries, stored in grub_uint16_t, while 0xffff
means not found.

This patch fixes the problem of large subscript truncated to grub_uint16_t,
leading BMP index to return wrong char entry or report false miss. The
code now checks for bounds and uses BMP index as a hint, and fallbacks
to binary-search if necessary.

On the occasion add a comment about BMP index is initialized to 0xffff.

Signed-off-by: Zhang Boyang <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
---
grub-core/font/font.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index 9e3e0a94e..e4cb0d867 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -300,6 +300,8 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
if (!font->bmp_idx)
return 1;
+
+ /* Init the BMP index array to 0xffff. */
grub_memset (font->bmp_idx, 0xff, 0x10000 * sizeof (grub_uint16_t));


@@ -328,7 +330,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
return 1;
}

- if (entry->code < 0x10000)
+ if (entry->code < 0x10000 && i < 0xffff)
font->bmp_idx[entry->code] = i;

last_code = entry->code;
@@ -696,9 +698,12 @@ find_glyph (const grub_font_t font, grub_uint32_t code)
/* Use BMP index if possible. */
if (code < 0x10000 && font->bmp_idx)
{
- if (font->bmp_idx[code] == 0xffff)
- return 0;
- return &table[font->bmp_idx[code]];
+ if (font->bmp_idx[code] < 0xffff)
+ return &table[font->bmp_idx[code]];
+ /*
+ * When we are here then lookup in BMP index result in miss,
+ * fallthough to binary-search.
+ */
}

/* Do a binary search in `char_index', which is ordered by code point. */
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
From 1d2015598cc7a9fca4b39186273e3519a88e80c7 Mon Sep 17 00:00:00 2001
From: Zhang Boyang <[email protected]>
Date: Sun, 14 Aug 2022 18:09:38 +0800
Subject: [PATCH 07/13] font: Fix integer underflow in binary search of char
index

If search target is less than all entries in font->index then "hi"
variable is set to -1, which translates to SIZE_MAX and leads to errors.

This patch fixes the problem by replacing the entire binary search code
with the libstdc++'s std::lower_bound() implementation.

Signed-off-by: Zhang Boyang <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
---
grub-core/font/font.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index e4cb0d867..abd412a5e 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -688,12 +688,12 @@ read_be_int16 (grub_file_t file, grub_int16_t * value)
static inline struct char_index_entry *
find_glyph (const grub_font_t font, grub_uint32_t code)
{
- struct char_index_entry *table;
- grub_size_t lo;
- grub_size_t hi;
- grub_size_t mid;
+ struct char_index_entry *table, *first, *end;
+ grub_size_t len;

table = font->char_index;
+ if (table == NULL)
+ return NULL;

/* Use BMP index if possible. */
if (code < 0x10000 && font->bmp_idx)
@@ -706,25 +706,29 @@ find_glyph (const grub_font_t font, grub_uint32_t code)
*/
}

- /* Do a binary search in `char_index', which is ordered by code point. */
- lo = 0;
- hi = font->num_chars - 1;
-
- if (!table)
- return 0;
+ /*
+ * Do a binary search in char_index which is ordered by code point.
+ * The code below is the same as libstdc++'s std::lower_bound().
+ */
+ first = table;
+ len = font->num_chars;
+ end = first + len;

- while (lo <= hi)
+ while (len > 0)
{
- mid = lo + (hi - lo) / 2;
- if (code < table[mid].code)
- hi = mid - 1;
- else if (code > table[mid].code)
- lo = mid + 1;
+ grub_size_t half = len >> 1;
+ struct char_index_entry *middle = first + half;
+
+ if (middle->code < code)
+ {
+ first = middle + 1;
+ len = len - half - 1;
+ }
else
- return &table[mid];
+ len = half;
}

- return 0;
+ return (first < end && first->code == code) ? first : NULL;
}

/* Get a glyph for the Unicode character CODE in FONT. The glyph is loaded
--
2.34.1

Loading
Loading