The relocator stubs in .text section are patched at runtime to perform
boot with relocating. Since commit d72208423dca ("kern/dl: Use correct
segment in grub_dl_set_mem_attrs()"), `grub_dl_set_mem_attrs` applies
correct memory attributes according to ELF section flags. However, as
GNU Assembler always enforces "ax" on .text section, patching those
relocator stubs triggers #PF due to permission violation.

Fix by moving the stubs into a new .text.relocator section with "awx"
flags to ensure them writable and executable.

Assisted-by: github-copilot:claude-opus-4.7
Signed-off-by: Jiaqing Zhao <[email protected]>
---
 grub-core/lib/i386/relocator16.S     | 5 ++++-
 grub-core/lib/i386/relocator32.S     | 3 +++
 grub-core/lib/i386/relocator64.S     | 3 +++
 grub-core/lib/i386/relocator_asm.S   | 3 +++
 grub-core/lib/x86_64/relocator_asm.S | 3 +++
 5 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/grub-core/lib/i386/relocator16.S b/grub-core/lib/i386/relocator16.S
index e9238119b..68d51dd4b 100644
--- a/grub-core/lib/i386/relocator16.S
+++ b/grub-core/lib/i386/relocator16.S
@@ -29,7 +29,10 @@
 #include <grub/i386/relocator_private.h>
 
 #include "relocator_common.S"
-       
+
+       /* Symbols below will be patched at runtime; place stub in a writable 
section. */
+       .section .text.relocator, "awx", %progbits
+
        .p2align        4       /* force 16-byte alignment */
 
 VARIABLE(grub_relocator16_start)
diff --git a/grub-core/lib/i386/relocator32.S b/grub-core/lib/i386/relocator32.S
index 09ce56ad0..5c0efdf1e 100644
--- a/grub-core/lib/i386/relocator32.S
+++ b/grub-core/lib/i386/relocator32.S
@@ -24,6 +24,9 @@
 
 #include "relocator_common.S"
 
+       /* Symbols below will be patched at runtime; place stub in a writable 
section. */
+       .section .text.relocator, "awx", %progbits
+
        .p2align        4       /* force 16-byte alignment */
 
 VARIABLE(grub_relocator32_start)
diff --git a/grub-core/lib/i386/relocator64.S b/grub-core/lib/i386/relocator64.S
index c80538e7e..857cb6c63 100644
--- a/grub-core/lib/i386/relocator64.S
+++ b/grub-core/lib/i386/relocator64.S
@@ -24,6 +24,9 @@
 
 #include "relocator_common.S"
 
+       /* Symbols below will be patched at runtime; place stub in a writable 
section. */
+       .section .text.relocator, "awx", %progbits
+
        .p2align        4       /* force 16-byte alignment */
 
 VARIABLE(grub_relocator64_start)
diff --git a/grub-core/lib/i386/relocator_asm.S 
b/grub-core/lib/i386/relocator_asm.S
index f273586fe..3bf45c2a0 100644
--- a/grub-core/lib/i386/relocator_asm.S
+++ b/grub-core/lib/i386/relocator_asm.S
@@ -19,6 +19,9 @@
 #include <grub/symbol.h>
 #include <grub/i386/memory.h>
 
+       /* Symbols below will be patched at runtime; place stub in a writable 
section. */
+       .section .text.relocator, "awx", %progbits
+
        .p2align        2
 
 VARIABLE(grub_relocator_backward_start)
diff --git a/grub-core/lib/x86_64/relocator_asm.S 
b/grub-core/lib/x86_64/relocator_asm.S
index 12728d8e1..d8207509f 100644
--- a/grub-core/lib/x86_64/relocator_asm.S
+++ b/grub-core/lib/x86_64/relocator_asm.S
@@ -19,6 +19,9 @@
 #include <grub/symbol.h>
 #include <grub/i386/memory.h>
 
+       /* Symbols below will be patched at runtime; place stub in a writable 
section. */
+       .section .text.relocator, "awx", %progbits
+
        .p2align        2
 
 VARIABLE(grub_relocator_backward_start)
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to