1 Star 0 Fork 98

余诗/grub2

forked from src-openEuler/grub2 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Fix-the-size-calculation-for-the-synthesized-initrd.patch 2.88 KB
一键复制 编辑 原始数据 按行查看 历史
zhangqiumiao 提交于 2024-03-04 03:17 . update to 2.12
From d441356c924102b43b303520cc1c62a624b014d6 Mon Sep 17 00:00:00 2001
From: Gary Lin <glin@suse.com>
Date: Thu, 26 Oct 2023 13:18:24 +0800
Subject: [PATCH] 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 4e028f5..9ee8f37 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.35.3
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yushi-Icy/grub2.git
git@gitee.com:yushi-Icy/grub2.git
yushi-Icy
grub2
grub2
master

搜索帮助