From patchwork Tue Aug 20 11:16:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Mladjenovic X-Patchwork-Id: 34182 Received: (qmail 82058 invoked by alias); 20 Aug 2019 11:17:02 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 81898 invoked by uid 89); 20 Aug 2019 11:17:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=os, silently X-HELO: NAM01-BN3-obe.outbound.protection.outlook.com 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== 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-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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RL2jygBxhrdo1bVqk62wRWD6H2EkiSJPTqcC3VDh538=; b=baJzHd234fKElV+4v7CpCk48H0Eg6Fd5npcMMQhC1FAuVQEO5etsFua7VvZNFFQa54wF84kvZYAzTSGKN5rmSQUl1QmjWXoYUhKl4geoQlc37Alk8Tq6yTcXPRhfdESMVngO0jFu2T29QqTbcML5IVO4WK0IOzNbb4jnnFxONQg= From: Dragan Mladjenovic To: "libc-alpha@sourceware.org" CC: Dragan Mladjenovic , Joseph Myers , Carlos O'Donell , Adhemerval Zanella , "Maciej W . Rozycki" , Faraz Shahbazker Subject: [PATCH v4] Mips support for PT_GNU_STACK Date: Tue, 20 Aug 2019 11:16:42 +0000 Message-ID: <1566299534-11595-1-git-send-email-dmladjenovic@wavecomp.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=dmladjenovic@wavecomp.com; x-ms-exchange-purlcount: 7 x-ms-exchange-transport-forked: True x-ms-oob-tlc-oobclassifiers: OLM:9508; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ce0xcy7/QY78PrwCjDgj3vRR9jQVEYUZ5mSxzNML46tCZF3FzUOp21n2umojhgTdOeM0WY0JhICeVUhTSOprPhot+yvua21taWf20+VpEvk= From: "Dragan Mladjenovic" 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 * 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 -# and -# . +# 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