This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v4] Mips support for PT_GNU_STACK
- From: Dragan Mladjenovic <dmladjenovic at wavecomp dot com>
- To: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Cc: Dragan Mladjenovic <dmladjenovic at wavecomp dot com>, Joseph Myers <joseph at codesourcery dot com>, Carlos O'Donell <carlos at redhat dot com>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, "Maciej W . Rozycki" <macro at linux-mips dot org>, Faraz Shahbazker <fshahbazker at wavecomp dot com>
- Date: Tue, 20 Aug 2019 11:16:42 +0000
- Subject: [PATCH v4] Mips support for PT_GNU_STACK
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=wavecomp.com; dkim=pass header.d=wavecomp.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RL2jygBxhrdo1bVqk62wRWD6H2EkiSJPTqcC3VDh538=; b=nKB7S0N7KWRbY75AqqFwOv2B0ZjiZnOR5y4n8Wu5BAgiTjY/eJSzfNqZEuprzONL0C5nXLhb5aK66e9T0LNsq4Sd7zSfhyF/UZLMQ3CE6x2tHkm2VezUodTy+5S/pN5mmHOVZeUy6AFsUywlgDeLPBJzKUuknlAppA7eylixCYoSEKLp3/qvNGeyxIkriZ/n51EgzYn3eqY4MFtCCqR+47HHOhikI2C46tnmzJ6QaaVA6ZU6rozEq96aWxfTEGib6T1000OCtyr/JiGhXY5o1pJRZFsLOiySwDyvjD3uT7qDXb290W90GC1BbQHbEADjdwdjvLm60GW6D7hmO+W7jA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QwfKYnuqwcmf/3VRYZaZGOz7EupDWYABOsqKs+n/+I8jGqtsDO/VkpVKMREtYO9SZ5b2MyQDpQDmrFDWyhCsboKCeqp2wj5ajCaXqxUgf4J62Q43F7mmEtTzmBi3QC2VR7uu/8hmZgC3/UPFfN3BUe4bOrQwNbFMEq+VWmG3K18JLUTXygWXTlRAP+xIic6aIjZScLxBWT0yF/wyfK+ngRa6mSKV4RFkGvsf1Hu3tojdv4B7u7VLzPU2hCBygI171Grx3lLIz0xSaWPZQv8CN9aQlRPCaTWKpnWMZyO7XVaaDCrAKQMGoTwnExLEiKIRylgMPsqqOhkB2bssW22vLQ==
From: "Dragan Mladjenovic" <dmladjenovic@wavecomp.com>
Hello everyone,
This is fourth attempt to enable glibc to safely handle PT_GNU_STACK on Linux/Mips.
You can check out the previous discussion about this issue at [1], [2] and [3].
A brief summary of the issue this is trying to address:
Up until the Linux kernel version 4.8 [4] MIPS FPU emulator used a small trampoline,
created on user stack, to handle delay slots when emulating FPU branches.
Because of this non-executable stack could not be enabled by default on MIPS.
The compatibility issue is that these old kernels respect PT_GNU_STACK,
making the stack non-executable if requested, and could crash the user process if
there would be need to emulate an instruction in the delay slot of a FPU branch.
In order to allow for the glibc to be safely compiled with potential future gcc that
emits .note.GNU-stack, that is without silently producing RW PT_GNU_STACK libc that
might crash at runtime, this patch forces executable stack for all build objects if
configured to run against minimum kernel version less than 4.8.
The gcc side of the patch can be found at [5]. It allows gcc to emit .note.GNU-stack
by default on hard-float mips targets that are configured against the future release
of glibc.
Best regards,
Dragan
[1] https://sourceware.org/ml/libc-alpha/2019-06/msg00889.html
[2] https://sourceware.org/ml/libc-alpha/2019-07/msg00280.html
[3] https://sourceware.org/ml/libc-alpha/2019-08/msg00065.html
[4] https://github.com/torvalds/linux/commit/432c6bacbd0c16ec210c43da411ccc3855c4c010
[5] https://gcc.gnu.org/ml/gcc-patches/2019-08/msg00254.html
2019-08-20 Dragan Mladjenovic <dmladjenovic@wavecomp.com>
* sysdeps/mips/Makefile (CFLAGS-.o*, ASFLAGS-.o*): New rules.
Apply -Wa,-execstack if mips-force-execstack == yes.
* sysdeps/mips/configure: Regenerated.
* sysdeps/mips/configure.ac (mips-force-execstack): New var.
Set to yes for minimum_kernel < 4.8.0, hard-float, Linux builds.
(mips-has-gnustack): New var.
Use value of libc_cv_as_noexecstack if mips-force-execstack != yes,
otherwise set to no.
* sysdeps/unix/sysv/linux/mips/Makefile (test-xfail-check-execstack):
Move under mips-has-gnustack != yes.
---
sysdeps/mips/Makefile | 12 ++++++++++++
sysdeps/mips/configure.ac | 28 ++++++++++++++++++++++++++++
sysdeps/unix/sysv/linux/mips/Makefile | 9 ++++-----
3 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile
index 7ac6fa5..6a9ba90 100644
--- a/sysdeps/mips/Makefile
+++ b/sysdeps/mips/Makefile
@@ -82,3 +82,15 @@ $(objpfx)tst-mode-switch-2: $(shared-thread-library)
endif
endif
endif
+
+ifeq ($(mips-force-execstack),yes)
+CFLAGS-.o += -Wa,-execstack
+CFLAGS-.os += -Wa,-execstack
+CFLAGS-.op += -Wa,-execstack
+CFLAGS-.oS += -Wa,-execstack
+
+ASFLAGS-.o += -Wa,-execstack
+ASFLAGS-.os += -Wa,-execstack
+ASFLAGS-.op += -Wa,-execstack
+ASFLAGS-.oS += -Wa,-execstack
+endif
diff --git a/sysdeps/mips/configure.ac b/sysdeps/mips/configure.ac
index bcbdaff..f0f89ae 100644
--- a/sysdeps/mips/configure.ac
+++ b/sysdeps/mips/configure.ac
@@ -13,3 +13,31 @@ yes
if test x$libc_cv_mips_nan2008 = xyes; then
AC_DEFINE(HAVE_MIPS_NAN2008)
fi
+
+# Moved here to allow linux configure fragment to set minimum_kernel
+# beforehand.
+
+AC_CACHE_CHECK([checking whether the compiler must use executable stack],
+ libc_cv_mips_force_execstack, [dnl
+libc_cv_mips_force_execstack=no
+case $os in linux*)
+ if test x"$libc_mips_float" = xhard -a -n "$minimum_kernel"; then
+ changequote(,)
+ min_version=$((`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
+ changequote([,])
+ if test $min_version -lt 264192; then
+ libc_cv_mips_force_execstack=yes
+ fi
+ fi
+ ;;
+esac])
+
+libc_mips_has_gnustack=$libc_cv_as_noexecstack
+
+if test $libc_cv_mips_force_execstack = yes; then
+ libc_mips_has_gnustack=no
+ AC_MSG_WARN([forcing executable stack for pre-4.8.0 Linux kernels])
+fi
+
+LIBC_CONFIG_VAR([mips-force-execstack],[${libc_cv_mips_force_execstack}])
+LIBC_CONFIG_VAR([mips-has-gnustack],[${libc_mips_has_gnustack}])
diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile
index 8217f42..e9206fa 100644
--- a/sysdeps/unix/sysv/linux/mips/Makefile
+++ b/sysdeps/unix/sysv/linux/mips/Makefile
@@ -63,13 +63,12 @@ sysdep-dl-routines += dl-static
sysdep_routines += dl-vdso
endif
-
-# Supporting non-executable stacks on MIPS requires changes to both
-# the Linux kernel and glibc. See
-# <https://sourceware.org/ml/libc-alpha/2016-01/msg00567.html> and
-# <https://sourceware.org/ml/libc-alpha/2016-01/msg00719.html>.
+# If the compiler doesn't use GNU.stack note,
+# this test is expected to fail.
+ifneq ($(mips-has-gnustack),yes)
test-xfail-check-execstack = yes
endif
+endif
ifeq ($(subdir),stdlib)
gen-as-const-headers += ucontext_i.sym
--
1.9.1