This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v3] Mips support for PT_GNU_STACK


From: "Dragan Mladjenovic" <dmladjenovic@wavecomp.com>

Hello everyone,

This is a third 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] and [2].

A brief summary of the issue this is trying to address:

Up until the Linux kernel version 4.8 [3] 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 an FPU branch.

In order to allow for the tool-chain to safely use PT_GNU_STACK by default, this patch
bumps the minimum kernel version to 4.8 for the hard-float builds done with GNU.stack
enabled tool-chain.

It would be nice if this could be back-ported as far back as glibc's policy allows.

Will be posting gcc side of the patch soon.

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://github.com/torvalds/linux/commit/432c6bacbd0c16ec210c43da411ccc3855c4c010

2019-08-04  Dragan Mladjenovic  <dmladjenovic@wavecomp.com>

	* sysdeps/unix/sysv/linux/mips/Makefile (test-xfail-check-execstack):
	Move under mips-has-gnustack != yes.
	* sysdeps/unix/sysv/linux/mips/configure.ac (mips-has-gnustack): New var.
	Use value of libc_cv_as_noexecstack.
	Set arch_minimum_kernel=4.8.0 for hard-float, noexecstack builds.
	* sysdeps/unix/sysv/linux/mips/configure: Regenerated.
---
 sysdeps/unix/sysv/linux/mips/Makefile     | 9 ++++-----
 sysdeps/unix/sysv/linux/mips/configure.ac | 5 +++++
 2 files changed, 9 insertions(+), 5 deletions(-)

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
diff --git a/sysdeps/unix/sysv/linux/mips/configure.ac b/sysdeps/unix/sysv/linux/mips/configure.ac
index 9147aa4..b195137 100644
--- a/sysdeps/unix/sysv/linux/mips/configure.ac
+++ b/sysdeps/unix/sysv/linux/mips/configure.ac
@@ -118,6 +118,8 @@ fi
 LIBC_CONFIG_VAR([default-abi],
   [${libc_mips_abi}_${libc_mips_float}${libc_mips_nan}])
 
+LIBC_CONFIG_VAR([mips-has-gnustack],[${libc_cv_as_noexecstack}])
+
 case $machine in
 mips/mips64/n64/*)
   LIBC_SLIBDIR_RTLDDIR([lib64], [lib64])
@@ -133,4 +135,7 @@ if test -z "$arch_minimum_kernel"; then
   if test x$libc_cv_mips_nan2008 = xyes; then
     arch_minimum_kernel=4.5.0
   fi
+  if test x"$libc_cv_as_noexecstack" = xyes -a x"$libc_mips_float" = xhard; then
+    arch_minimum_kernel=4.8.0
+  fi
 fi
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]