diff --git a/1000-modules-load-module-sections-at-page-aligned-address.patch b/1000-modules-load-module-sections-at-page-aligned-address.patch index b4e2fdcacf9da21115c49430d19ee2a58e03c6f5..89399bccfc59b757b7697f5c58a5e1b1f098ab6b 100644 --- a/1000-modules-load-module-sections-at-page-aligned-address.patch +++ b/1000-modules-load-module-sections-at-page-aligned-address.patch @@ -1,23 +1,24 @@ -From b463d5e937e6039c56cc63a79f229f9f70b4b76a Mon Sep 17 00:00:00 2001 +From 4fe21f124c468d07821e306a1beb52f9e70f8fcc Mon Sep 17 00:00:00 2001 From: Liwei Ge Date: Mon, 8 Apr 2024 21:11:45 +0800 Subject: [PATCH] modules: load module sections at page-aligned addresses +Cherry-picked updated version from https://lists.gnu.org/archive/html/grub-devel/2024-06/msg00085.html --- - docs/grub-dev.texi | 6 +++--- - grub-core/kern/arm/dl.c | 13 +++++++++++++ - grub-core/kern/arm64/dl.c | 13 +++++++++++++ - grub-core/kern/dl.c | 29 +++++++++++++++++++++-------- - grub-core/kern/emu/full.c | 13 +++++++++++++ - grub-core/kern/i386/dl.c | 13 +++++++++++++ - grub-core/kern/ia64/dl.c | 9 +++++++++ - grub-core/kern/mips/dl.c | 8 ++++++++ - grub-core/kern/powerpc/dl.c | 9 +++++++++ - grub-core/kern/riscv/dl.c | 13 +++++++++++++ - grub-core/kern/sparc64/dl.c | 9 +++++++++ - grub-core/kern/x86_64/dl.c | 13 +++++++++++++ + docs/grub-dev.texi | 6 ++--- + grub-core/kern/arm/dl.c | 13 +++++++++ + grub-core/kern/arm64/dl.c | 13 +++++++++ + grub-core/kern/dl.c | 53 ++++++++++++++++++++++++++----------- + grub-core/kern/emu/full.c | 13 +++++++++ + grub-core/kern/i386/dl.c | 13 +++++++++ + grub-core/kern/ia64/dl.c | 9 +++++++ + grub-core/kern/mips/dl.c | 8 ++++++ + grub-core/kern/powerpc/dl.c | 9 +++++++ + grub-core/kern/riscv/dl.c | 13 +++++++++ + grub-core/kern/sparc64/dl.c | 9 +++++++ + grub-core/kern/x86_64/dl.c | 13 +++++++++ include/grub/dl.h | 2 ++ - 13 files changed, 139 insertions(+), 11 deletions(-) + 13 files changed, 155 insertions(+), 19 deletions(-) diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi index 04c6678..8ad5494 100644 @@ -79,10 +80,10 @@ index a2b5789..95c6d5b 100644 +#endif +} diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index a4d6748..ec8ee98 100644 +index a4d6748..c6281f7 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c -@@ -277,7 +277,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) +@@ -277,25 +277,35 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) { unsigned i; const Elf_Shdr *s; @@ -91,7 +92,10 @@ index a4d6748..ec8ee98 100644 #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \ !defined (__loongarch__) grub_size_t tramp; -@@ -286,16 +286,24 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) ++ grub_size_t tramp_align; + grub_size_t got; ++ grub_size_t got_align; + grub_err_t err; #endif char *ptr; @@ -119,7 +123,32 @@ index a4d6748..ec8ee98 100644 } #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \ -@@ -325,6 +333,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) +@@ -303,12 +313,18 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + err = grub_arch_dl_get_tramp_got_size (e, &tramp, &got); + if (err) + return err; +- tsize += ALIGN_UP (tramp, GRUB_ARCH_DL_TRAMP_ALIGN); +- if (talign < GRUB_ARCH_DL_TRAMP_ALIGN) +- talign = GRUB_ARCH_DL_TRAMP_ALIGN; +- tsize += ALIGN_UP (got, GRUB_ARCH_DL_GOT_ALIGN); +- if (talign < GRUB_ARCH_DL_GOT_ALIGN) +- talign = GRUB_ARCH_DL_GOT_ALIGN; ++ tramp_align = GRUB_ARCH_DL_TRAMP_ALIGN; ++ if (tramp_align < arch_addralign) ++ tramp_align = arch_addralign; ++ tsize += ALIGN_UP (tramp, tramp_align); ++ if (talign < tramp_align) ++ talign = tramp_align; ++ got_align = GRUB_ARCH_DL_GOT_ALIGN; ++ if (got_align < arch_addralign) ++ got_align = arch_addralign; ++ tsize += ALIGN_UP (got, got_align); ++ if (talign < got_align) ++ talign = got_align; + #endif + + #ifdef GRUB_MACHINE_EMU +@@ -325,6 +341,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) i < e->e_shnum; i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize)) { @@ -129,7 +158,7 @@ index a4d6748..ec8ee98 100644 if (s->sh_flags & SHF_ALLOC) { grub_dl_segment_t seg; -@@ -337,17 +348,19 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) +@@ -337,17 +356,19 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) { void *addr; @@ -152,7 +181,7 @@ index a4d6748..ec8ee98 100644 break; } -@@ -356,7 +369,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) +@@ -356,7 +377,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) else seg->addr = 0; @@ -161,6 +190,20 @@ index a4d6748..ec8ee98 100644 seg->section = i; seg->next = mod->segment; mod->segment = seg; +@@ -364,11 +385,11 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + } + #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \ + !defined (__loongarch__) +- ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN); ++ ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, tramp_align); + mod->tramp = ptr; + mod->trampptr = ptr; + ptr += tramp; +- ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_GOT_ALIGN); ++ ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, got_align); + mod->got = ptr; + mod->gotptr = ptr; + ptr += got; diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c index e8d63b1..1de1c28 100644 --- a/grub-core/kern/emu/full.c @@ -326,5 +369,5 @@ index 216f8b9..9f86765 100644 #if defined (_mips) -- -2.43.0 +2.41.0 diff --git a/1000-nx-set-page-permissions-for-loaded-modules.patch b/1000-nx-set-page-permissions-for-loaded-modules.patch index 2d187428eb637ea98fdbecae27ca53c640da94ac..668282821854e80ea63045c837be336eef8f37c3 100644 --- a/1000-nx-set-page-permissions-for-loaded-modules.patch +++ b/1000-nx-set-page-permissions-for-loaded-modules.patch @@ -1,18 +1,19 @@ -From 9b730c810a4b918f19538e4dc518258bb6ae1c1f Mon Sep 17 00:00:00 2001 +From e123a66eaec406191bff7f5cc33bae62fcad38eb Mon Sep 17 00:00:00 2001 From: Liwei Ge Date: Mon, 8 Apr 2024 21:24:52 +0800 Subject: [PATCH] nx: set page permissions for loaded modules. +Cherry-picked updated version from https://lists.gnu.org/archive/html/grub-devel/2024-06/msg00079.html --- - grub-core/kern/dl.c | 120 +++++++++++++++++++++++++++++++++----------- + grub-core/kern/dl.c | 125 +++++++++++++++++++++++++++++++++----------- include/grub/dl.h | 44 ++++++++++++++++ - 2 files changed, 134 insertions(+), 30 deletions(-) + 2 files changed, 139 insertions(+), 30 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index ec8ee98..896dba6 100644 +index c6281f7..ce6165f 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c -@@ -286,6 +286,8 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) +@@ -288,6 +288,8 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) #endif char *ptr; @@ -21,7 +22,7 @@ index ec8ee98..896dba6 100644 arch_addralign = grub_arch_dl_min_alignment (); for (i = 0, s = (const Elf_Shdr *)((const char *) e + e->e_shoff); -@@ -387,6 +389,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) +@@ -395,6 +397,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) ptr += got; #endif @@ -29,7 +30,7 @@ index ec8ee98..896dba6 100644 return GRUB_ERR_NONE; } -@@ -520,23 +523,6 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name) +@@ -528,23 +531,6 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name) return s; return NULL; } @@ -53,7 +54,7 @@ index ec8ee98..896dba6 100644 /* Me, Vladimir Serbinenko, hereby I add this module check as per new GNU module policy. Note that this license check is informative only. -@@ -671,6 +657,7 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) +@@ -679,6 +665,7 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) Elf_Shdr *s; unsigned i; @@ -61,7 +62,7 @@ index ec8ee98..896dba6 100644 for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); i < e->e_shnum; i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) -@@ -679,24 +666,95 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) +@@ -687,24 +674,96 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) grub_dl_segment_t seg; grub_err_t err; @@ -90,23 +91,24 @@ index ec8ee98..896dba6 100644 } + grub_dprintf ("modules", "done relocating symbols for \"%s\"\n", mod->name); - return GRUB_ERR_NONE; - } ++ return GRUB_ERR_NONE; ++} + ++/* Only define this on EFI to save space in core */ ++#ifdef GRUB_MACHINE_EFI +static grub_err_t +grub_dl_set_mem_attrs (grub_dl_t mod, void *ehdr) +{ + unsigned i; + const Elf_Shdr *s; + const Elf_Ehdr *e = ehdr; ++ grub_err_t err; +#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) + grub_size_t arch_addralign = grub_arch_dl_min_alignment (); + grub_addr_t tgaddr; -+ grub_uint64_t tgsz; ++ grub_size_t tgsz; +#endif + -+ grub_dprintf ("modules", "updating memory attributes for \"%s\"\n", -+ mod->name); + for (i = 0, s = (const Elf_Shdr *)((const char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (const Elf_Shdr *)((const char *) s + e->e_shentsize)) @@ -133,16 +135,10 @@ index ec8ee98..896dba6 100644 + set_attrs |= GRUB_MEM_ATTR_X; + clear_attrs &= ~GRUB_MEM_ATTR_X; + } -+ -+ grub_dprintf ("modules", "setting memory attrs for section \"%s\" to -%s%s%s+%s%s%s\n", -+ grub_dl_get_section_name(e, s), -+ (clear_attrs & GRUB_MEM_ATTR_R) ? "r" : "", -+ (clear_attrs & GRUB_MEM_ATTR_W) ? "w" : "", -+ (clear_attrs & GRUB_MEM_ATTR_X) ? "x" : "", -+ (set_attrs & GRUB_MEM_ATTR_R) ? "r" : "", -+ (set_attrs & GRUB_MEM_ATTR_W) ? "w" : "", -+ (set_attrs & GRUB_MEM_ATTR_X) ? "x" : ""); -+ grub_update_mem_attrs ((grub_addr_t)(seg->addr), seg->size, set_attrs, clear_attrs); ++ err = grub_update_mem_attrs ((grub_addr_t)(seg->addr), seg->size, ++ set_attrs, clear_attrs); ++ if (err != GRUB_ERR_NONE) ++ return err; + } + +#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) @@ -152,24 +148,30 @@ index ec8ee98..896dba6 100644 + if (tgsz) + { + tgsz = ALIGN_UP(tgsz, arch_addralign); -+ -+ grub_dprintf ("modules", "updating attributes for GOT and trampolines\n", -+ mod->name); -+ grub_update_mem_attrs (tgaddr, tgsz, GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_X, ++ if (tgaddr < (grub_addr_t)mod->base || ++ tgsz > (grub_addr_t)-1 - tgaddr || ++ tgaddr + tgsz > (grub_addr_t)mod->base + mod->sz) ++ return grub_error (GRUB_ERR_BUG, ++ "BUG: trying to protect pages outside of module " ++ "allocation (\"%s\"): module base %p, size 0x%" ++ PRIxGRUB_SIZE "; tramp/GOT base 0x%" PRIxGRUB_ADDR ++ ", size 0x%" PRIxGRUB_SIZE, ++ mod->name, mod->base, mod->sz, tgaddr, tgsz); ++ err = grub_update_mem_attrs (tgaddr, tgsz, GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_X, + GRUB_MEM_ATTR_W); ++ if (err != GRUB_ERR_NONE) ++ return err; + } +#endif + -+ grub_dprintf ("modules", "done updating module memory attributes for \"%s\"\n", -+ mod->name); -+ -+ return GRUB_ERR_NONE; -+} + return GRUB_ERR_NONE; + } ++#endif + static void grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e) { -@@ -762,6 +820,7 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) +@@ -770,6 +829,7 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) mod->ref_count = 1; grub_dprintf ("modules", "relocating to %p\n", mod); @@ -177,13 +179,17 @@ index ec8ee98..896dba6 100644 /* Me, Vladimir Serbinenko, hereby I add this module check as per new GNU module policy. Note that this license check is informative only. Modules have to be licensed under GPLv3 or GPLv3+ (optionally -@@ -775,7 +834,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) +@@ -783,7 +843,12 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) || grub_dl_resolve_dependencies (mod, e) || grub_dl_load_segments (mod, e) || grub_dl_resolve_symbols (mod, e) - || grub_dl_relocate_symbols (mod, e)) + || grub_dl_relocate_symbols (mod, e) ++#ifdef GRUB_MACHINE_EFI + || grub_dl_set_mem_attrs (mod, e)) ++#else ++ ) ++#endif { mod->fini = 0; grub_dl_unload (mod); @@ -250,5 +256,5 @@ index 9f86765..1e1262a 100644 void * EXPORT_FUNC(grub_resolve_symbol) (const char *name); -- -2.43.0 +2.41.0 diff --git a/1010-Clear-buffer-to-zero-for-screen-information.patch b/1010-Clear-buffer-to-zero-for-screen-information.patch new file mode 100644 index 0000000000000000000000000000000000000000..b2604e8be367fb437596fbd88018fca97495a56e --- /dev/null +++ b/1010-Clear-buffer-to-zero-for-screen-information.patch @@ -0,0 +1,40 @@ +From 50a6f8e80cec46932e53a73563d02e7739d69400 Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Wed, 23 Oct 2024 15:37:20 +0800 +Subject: [PATCH] Clear buffer to zero for screen information. Modify + introduced old code. + +--- + grub-core/kern/efi/mm.c | 2 +- + grub-core/loader/loongarch64/linux-elf.c | 2 ++ + 2 files changed, 3 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index 6f8810e..4281feb 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -469,7 +469,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, + #ifdef GRUB_CPU_LOONGARCH64 + && desc->physical_start <= grub_efi_max_usable_address() + #else +- && desc->physical_start <= GRUB_EFI_MAX_USABLE_ADDRESS ++ && desc->physical_start <= GRUB_EFI_MAX_ALLOCATION_ADDRESS + #endif + && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000 + && desc->num_pages != 0) +diff --git a/grub-core/loader/loongarch64/linux-elf.c b/grub-core/loader/loongarch64/linux-elf.c +index bf3bfa4..34bfad7 100644 +--- a/grub-core/loader/loongarch64/linux-elf.c ++++ b/grub-core/loader/loongarch64/linux-elf.c +@@ -167,6 +167,8 @@ alloc_screen_info (void) + if (status != GRUB_EFI_SUCCESS) + return NULL; + ++ grub_memset((void *)si, 0, sizeof(struct screen_info)); ++ + status = b->install_configuration_table (&compat_screen_info_guid, si); + if (status != GRUB_EFI_SUCCESS) + goto free_mem; +-- +2.41.0 + diff --git a/grub.macros b/grub.macros index 40d7fd74923dbe7e5984be83f94b765fc1335b3a..72d68791a0e50b60a647e5c877883c547992dbf2 100644 --- a/grub.macros +++ b/grub.macros @@ -342,7 +342,7 @@ git add . \ git commit -a -q -m "%{tarversion} baseline." \ git am --whitespace=nowarn %%{patches} - 2.12-11 +- Revert avoiding loongson-specified patches on other arches + +* Wed Oct 23 2024 Xue Liu - 2.12-10 +- Clear buffer for screen information +- Modify introduced old code + +* Wed Jul 24 2024 Jun He - 2.12-9 +- Updated cherry-picked NX patche series to fix setting memory attr failure + * Thu May 30 2024 Chang Gao - 2.12-8 - Avoid loongarch specifed patches patched on other arches