diff --git a/1001-bls-make-list.patch b/1001-bls-make-list.patch new file mode 100644 index 0000000000000000000000000000000000000000..ac39162dd8915891d86326382395ab52df551081 --- /dev/null +++ b/1001-bls-make-list.patch @@ -0,0 +1,119 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Zhongling He +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 + diff --git a/grub.patches b/grub.patches index 2254748d1a9d868f0b180edf10d6fdca827016de..4359e3c4a202bae329b8b4738aaa4112f9fa39d9 100644 --- a/grub.patches +++ b/grub.patches @@ -488,3 +488,4 @@ Patch0487: 0487-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch Patch0488: 0488-powerpc-fix-prefix-signed-grub-special-case-for-Powe.patch # Support loongarch64 Patch1000: 0481-loongarch64-add-support.patch +Patch1001: 1001-bls-make-list.patch diff --git a/grub2.spec b/grub2.spec index 7f1e6a81b8407075383531c489235b2bb83be0ce..1c895cc27b9229877045dcc13eeb0049b8fb2659 100644 --- a/grub2.spec +++ b/grub2.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.2 +%define anolis_release .0.3 %undefine _hardened_build @@ -537,6 +537,9 @@ fi %endif %changelog +* Tue Mar 29 2022 Zhongling He 2.02-106.0.3 +- Fix a bug in bls_make_list, blscfg. + * Tue Jan 25 2022 Wenlong Zhang - 2.02-106.0.2 - Add loongarch64 base support (zhangwenlong@loongson.cn)(chenguoqi@loongson.cn)