[LTP] [PATCH v2 1/4] KVM: Disable EBP register use in 32bit code

Martin Doucha mdoucha@suse.cz
Tue May 14 14:07:08 CEST 2024


The EBP register points to the stack segment by default but GCC uses
it to access data segment without the proper prefix. This works fine
on most systems because the stack and data segments are usually
identical. However, KVM environment intentionally enforces strict
limits on the stack segment and access to the data segment using
unprefixed EBP would trigger stack segment fault exception in 32bit
LTP builds (stack segment limits are ignored in 64bit mode).

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Changes since v1:
- Detect -ffixed-ebp support in configure script and disable EBP conditionally

 configure.ac                  | 2 ++
 include/mk/config.mk.in       | 1 +
 testcases/kernel/kvm/Makefile | 4 ++++
 3 files changed, 7 insertions(+)

diff --git a/configure.ac b/configure.ac
index 1f7aa70bd..6d7009763 100644
--- a/configure.ac
+++ b/configure.ac
@@ -393,7 +393,9 @@ LTP_CHECK_SYSCALL_FCNTL
 LTP_CHECK_FSVERITY
 
 AX_CHECK_COMPILE_FLAG([-no-pie], [LTP_CFLAGS_NOPIE=1])
+AX_CHECK_COMPILE_FLAG([-ffixed-ebp], [LTP_CFLAGS_FFIXED_EBP=1])
 AC_SUBST([LTP_CFLAGS_NOPIE])
+AC_SUBST([LTP_CFLAGS_FFIXED_EBP])
 
 if test "x$with_numa" = xyes; then
 	LTP_CHECK_SYSCALL_NUMA
diff --git a/include/mk/config.mk.in b/include/mk/config.mk.in
index 145b887fa..f6e02eaeb 100644
--- a/include/mk/config.mk.in
+++ b/include/mk/config.mk.in
@@ -86,6 +86,7 @@ LDFLAGS			+= $(WLDFLAGS)
 CFLAGS			+= $(DEBUG_CFLAGS) $(OPT_CFLAGS) $(WCFLAGS) $(STDCFLAGS)
 
 LTP_CFLAGS_NOPIE	:= @LTP_CFLAGS_NOPIE@
+LTP_CFLAGS_FFIXED_EBP	:= @LTP_CFLAGS_FFIXED_EBP@
 
 ifeq ($(strip $(HOST_CFLAGS)),)
 HOST_CFLAGS := $(CFLAGS)
diff --git a/testcases/kernel/kvm/Makefile b/testcases/kernel/kvm/Makefile
index ce4a5ede2..07bdd9705 100644
--- a/testcases/kernel/kvm/Makefile
+++ b/testcases/kernel/kvm/Makefile
@@ -24,6 +24,10 @@ endif
 ifeq ($(HOST_CPU),x86)
 	GUEST_CFLAGS += -m32
 	ASFLAGS += --32
+
+	ifdef LTP_CFLAGS_FFIXED_EBP
+		GUEST_CFLAGS += -ffixed-ebp
+	endif
 endif
 
 # Some distros enable -pie by default. That breaks KVM payload linking.
-- 
2.44.0



More information about the ltp mailing list