[LTP] [PATCH] KVM: Fix ELF segment with RWX permissions warnings

Martin Doucha mdoucha@suse.cz
Mon Mar 13 18:15:07 CET 2023


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.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 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(-)

diff --git a/testcases/kernel/kvm/Makefile b/testcases/kernel/kvm/Makefile
index 6986844be..e12cb4e98 100644
--- a/testcases/kernel/kvm/Makefile
+++ b/testcases/kernel/kvm/Makefile
@@ -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)
 
diff --git a/testcases/kernel/kvm/bootstrap_x86.S b/testcases/kernel/kvm/bootstrap_x86.S
index 5ec4c0b7e..1aaf0a4d1 100644
--- a/testcases/kernel/kvm/bootstrap_x86.S
+++ b/testcases/kernel/kvm/bootstrap_x86.S
@@ -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
diff --git a/testcases/kernel/kvm/bootstrap_x86_64.S b/testcases/kernel/kvm/bootstrap_x86_64.S
index 9ddbd17ed..0cffd5a12 100644
--- a/testcases/kernel/kvm/bootstrap_x86_64.S
+++ b/testcases/kernel/kvm/bootstrap_x86_64.S
@@ -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
diff --git a/testcases/kernel/kvm/linker/x86.lds b/testcases/kernel/kvm/linker/x86.lds
index 95edb0be0..6e69c4d0f 100644
--- a/testcases/kernel/kvm/linker/x86.lds
+++ b/testcases/kernel/kvm/linker/x86.lds
@@ -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 :
 	{
diff --git a/testcases/kernel/kvm/linker/x86_64.lds b/testcases/kernel/kvm/linker/x86_64.lds
index ac372f863..9e62aa5ad 100644
--- a/testcases/kernel/kvm/linker/x86_64.lds
+++ b/testcases/kernel/kvm/linker/x86_64.lds
@@ -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 :
 	{
-- 
2.39.2



More information about the ltp mailing list