1 Star 0 Fork 49

Zhao Hang / grub2

forked from src-anolis-os / grub2 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1001-bls-make-list.patch 3.36 KB
一键复制 编辑 原始数据 按行查看 历史
MerlinDust 提交于 2022-05-19 00:17 . Fix a bug in bls_make_list, blscfg
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zhongling He <zhonglingh@linux.alibaba.com>
Date: Tue, 29 Mar 2022 17:27:13 +0800
Subject: [PATCH] Fix a bug in bls_make_list, blscfg
We have encountered a bug while running LifseaOS aarch64 version without
initrd. This commit fixes this bug. It may have fixed some potential
bugs as well.
There are 4 partitions in a LifseaOS disk image:
- The 1st partition is for BIOS bootloader
- The 2nd partition is for UEFI booting, which contains grub binary
compiled from this source code, grubaa64.efi
- The 3rd partition contains grub.cfg files and
loader/entries/ostree-1-LifseaOS.conf
- The 4th partition contains rootfs
Since x86_64 supports both BIOS and UEFI booting and we employ BIOS
booting for x86_64 (w/o initrd) image, we don't put the grub2 binary
compiled into the 2nd partition. As a result, this bug was not observed.
However, aarch64 only supports UEFI booting. In other words, we are
using this grub2 to boot LifseaOS (w/o initrd).
grubaa64.efi from the 2nd partition will read `/grub2/grub.cfg` in the
3rd partition.
```
...
set ignition_firstboot="ignition.firstboot
${ignition_network_kcmdline}"
fi
blscfg
```
`blscfg` is a command to convert `loader/entries/ostree-1-LifseaOS.conf`
into a typical grub.cfg. However, here comes the bug. While booting, an
error message will appear.
```
error: ../../grub-core/loader/arm64/linux.c:292:filename expected.
Press any key to continue.
```
This is because the bug in `blscfg` unexpectedly add a line, `initrd`,
into the generated grub.cfg file. Grub2 will expect an initrd file path
after `initrd`. As a result, the error occurs.
In grub-core/command/blscfg.c:676, if `initrds` is a non-NULL pointer,
then `src` will contain a `initrd` line.
```
static void create_entry (struct bls_entry *entry){
...
initrds = bls_make_list (entry, "initrd", NULL); //
...
if (initrds){
...
tmp = grub_stpcpy(initrd, "initrd ");
...
}
...
src = grub_xasprintf ("load_video\n"
"set gfx_payload=keep\n"
"insmod gzio\n"
"linux %s%s%s%s\n"
"%s",
GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options
: "",
initrd ? initrd : "");
```
In grub-core/command/blscfg.c:562, `bls_make_list` will always return a
non-NULL pointer except for a `grub_malloc` error.
```
static char **bls_make_list (struct bls_entry *entry, const char *key,
int *num)
{
...
list = grub_malloc (sizeof (char *));
if (!list)
return NULL;
list[0] = NULL;
...
return list;
}
```
Therefore, `initrd` like will be appended into the auto-generated
grub.cfg if `grub_malloc` succeed, regardless of whether initrd is
stated in config file. Our bug fix, same as upstream, modifies the
behaviour of `bls_make_list`. `bls_make_list` will now return a non-NULL
pointer only if the required field actually exists.
---
grub-core/commands/blscfg.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index 795a9f9..bf18270 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -589,6 +589,12 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num)
list[nlist] = NULL;
}
+ if (!nlist)
+ {
+ grub_free (list);
+ return NULL;
+ }
+
if (num)
*num = nlist;
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhaohang_mskdxl/grub2.git
git@gitee.com:zhaohang_mskdxl/grub2.git
zhaohang_mskdxl
grub2
grub2
a8

搜索帮助

344bd9b3 5694891 D2dac590 5694891