1 Star 0 Fork 16

jackzhao166/grub2

forked from OpenCloudOS Stream/grub2 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
0167-Fix-the-size-calculation-for-the-synthesized-initrd.patch 2.89 KB
Copy Edit Raw Blame History
nilusyi authored 2024-04-07 16:45 . update patches
From 454d622ab4ff64d29f0699fc05bdb00b218e9e76 Mon Sep 17 00:00:00 2001
From: Gary Lin <glin@suse.com>
Date: Thu, 26 Oct 2023 13:18:24 +0800
Subject: [PATCH 167/272] Fix the size calculation for the synthesized initrd
When calculating the size of the synthesized initrd in
grub_initrd_component(), the ending "TRAILER!!!" is counted in for every
synthesized initrd. However, in grub_initrd_load(), only one "TRAILER!!!"
will be appended for one group of consecutive synthesized initrds. The
additional size calculation for the ending "TRAILER!!!" could make the
linux kernel to read uninitialized bytes and result in the error message
like this:
Initramfs unpacking failed: invalid magic at start of compressed archive
To fit into the original 'newc' design, the ending "TRAILER!!!" is
removed from grub_initrd_component(). Instead, in grub_initrd_init(),
the 'newc' flag is set when calculating size of the synthesized initrd
to append the ending "TRAILER!!!" later. As for grub_initrd_load(),
since the path to the unsealed key is specified in 'newc_name', it's
unnecessary to set the 'newc' flag while copying the unsealed key
because the flag is already set when parsing the path name.
Signed-off-by: Gary Lin <glin@suse.com>
---
grub-core/loader/linux.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
index 4e028f570..9ee8f3790 100644
--- a/grub-core/loader/linux.c
+++ b/grub-core/loader/linux.c
@@ -209,13 +209,6 @@ grub_initrd_component (const char *buf, int bufsz, const char *newc_name,
&initrd_ctx->size))
goto overflow;
- initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
- if (grub_add (initrd_ctx->size,
- ALIGN_UP (sizeof (struct newc_head)
- + sizeof ("TRAILER!!!") - 1, 4),
- &initrd_ctx->size))
- goto overflow;
-
free_dir (root);
root = 0;
return GRUB_ERR_NONE;
@@ -312,6 +305,13 @@ grub_initrd_init (int argc, char *argv[],
goto overflow;
}
+ FOR_LIST_ELEMENTS (pk, kpuber)
+ if (pk->key && pk->path)
+ {
+ grub_initrd_component (pk->key, pk->key_len, pk->path, initrd_ctx);
+ newc = 1;
+ }
+
if (newc)
{
initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
@@ -324,10 +324,6 @@ grub_initrd_init (int argc, char *argv[],
root = 0;
}
- FOR_LIST_ELEMENTS (pk, kpuber)
- if (pk->key && pk->path)
- grub_initrd_component (pk->key, pk->key_len, pk->path, initrd_ctx);
-
return GRUB_ERR_NONE;
overflow:
@@ -404,10 +400,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
cursize = initrd_ctx->components[i].size;
if (initrd_ctx->components[i].buf)
- {
- grub_memcpy (ptr, initrd_ctx->components[i].buf, cursize);
- newc = 1;
- }
+ grub_memcpy (ptr, initrd_ctx->components[i].buf, cursize);
else if (grub_file_read (initrd_ctx->components[i].file, ptr, cursize)
!= cursize)
{
--
2.41.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jackzhao166/grub2.git
git@gitee.com:jackzhao166/grub2.git
jackzhao166
grub2
grub2
master

Search