Skip to contentSkip to conversation

KVM: Fix ELF segment with RWX permissions warnings

PATCH In review Martin Doucha 2 participants 2 messages Mar 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: Fix ELF segment with RWX permissions warnings

Linker complains that some ASM bootstrap segments have both write and execute permissions. Rename .data.gdt32 section because the ASM compiler seems to make it writable regardless of section flags. Also define new ELF segment for writable data sections.

---
 testcases/kernel/kvm/Makefile           | 2 +-
 testcases/kernel/kvm/bootstrap_x86.S    | 2 +-
 testcases/kernel/kvm/bootstrap_x86_64.S | 2 +-
 testcases/kernel/kvm/linker/x86.lds     | 5 +++--
 testcases/kernel/kvm/linker/x86_64.lds  | 5 +++--
 5 files changed, 9 insertions(+), 7 deletions(-)
testcases/kernel/kvm/Makefile +1 -1
index 6986844be..e12cb4e98 100644
@@ -9,7 +9,7 @@ ASFLAGS =
 CPPFLAGS += -I$(abs_srcdir)/include
 GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
 GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
-GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fno-stack-protector
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fno-stack-protector -z noexecstack
 GUEST_LDLIBS =
 KVM_LD ?= $(LD)
 
testcases/kernel/kvm/bootstrap_x86.S +1 -1
index 5ec4c0b7e..1aaf0a4d1 100644
@@ -31,7 +31,7 @@ protected_mode_entry:
 	mov %eax, %es
 	jmp init_memlayout
 
-.section .data.gdt32, "a", @progbits
+.section .init.gdt32, "a", @progbits
 
 .macro gdt32_entry type:req l=0 d=0 dpl=0 limit=0xfffff g=1 p=1
 	.4byte \limit & 0xffff
testcases/kernel/kvm/bootstrap_x86_64.S +1 -1
index 9ddbd17ed..0cffd5a12 100644
@@ -32,7 +32,7 @@ protected_mode_entry:
 	mov %eax, %es
 	jmp init_memlayout
 
-.section .data.gdt32, "a", @progbits
+.section .init.gdt32, "a", @progbits
 
 .macro gdt32_entry type:req l=0 d=0 dpl=0 limit=0xfffff g=1 p=1
 	.4byte \limit & 0xffff
testcases/kernel/kvm/linker/x86.lds +3 -2
index 95edb0be0..6e69c4d0f 100644
@@ -4,6 +4,7 @@ PHDRS
 {
 	headers PT_PHDR PHDRS ;
 	text PT_LOAD FILEHDR PHDRS ;
+	data PT_LOAD ;
 	bss PT_LOAD ;
 }
 
@@ -18,7 +19,7 @@ SECTIONS
 	.init.boot :
 	{
 		*(.init.protected_mode)
-		*(.data.gdt32)
+		*(.init.gdt32)
 		*(.init.memlayout)
 	} :text
 
@@ -40,7 +41,7 @@ SECTIONS
 	{
 		*(.data.strings)
 		*(.data)
-	}
+	} :data
 
 	.preinit_array :
 	{
testcases/kernel/kvm/linker/x86_64.lds +3 -2
index ac372f863..9e62aa5ad 100644
@@ -4,6 +4,7 @@ PHDRS
 {
 	headers PT_PHDR PHDRS ;
 	text PT_LOAD FILEHDR PHDRS ;
+	data PT_LOAD ;
 	bss PT_LOAD ;
 }
 
@@ -18,7 +19,7 @@ SECTIONS
 	.init.boot :
 	{
 		*(.init.protected_mode)
-		*(.data.gdt32)
+		*(.init.gdt32)
 		*(.init.memlayout)
 	} :text
 
@@ -40,7 +41,7 @@ SECTIONS
 	{
 		*(.data.strings)
 		*(.data)
-	}
+	} :data
 
 	.preinit_array :
 	{
Signature · 5 lines
2.39.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Martin,

thank you, merged!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp