OSDN Git Service

Enable the NX (No Execute) security feature for all NDK-generated machine code on...
authorDavid 'Digit' Turner <digit@google.com>
Mon, 3 May 2010 22:19:47 +0000 (15:19 -0700)
committerDavid 'Digit' Turner <digit@google.com>
Mon, 3 May 2010 22:55:20 +0000 (15:55 -0700)
Change-Id: Ic25be4e8a83e741040c7944251688dcdcc97838b
Question: shall we enable it for x86 too?

build/core/build-binary.mk
build/core/clear-vars.mk
build/toolchains/arm-eabi-4.2.1/setup.mk
build/toolchains/arm-eabi-4.4.0/setup.mk
docs/ANDROID-MK.TXT
docs/CHANGES.TXT

index 893dd97..24747e6 100644 (file)
@@ -63,7 +63,15 @@ endif
 # of a binary that uses undefined symbols.
 #
 ifneq ($(LOCAL_ALLOW_UNDEFINED_SYMBOLS),true)
-  LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my)NO_UNDEFINED_LDFLAGS)
+  LOCAL_LDFLAGS += $(LOCAL_LDFLAGS) $($(my)NO_UNDEFINED_LDFLAGS)
+endif
+
+# If LOCAL_DISABLE_NO_EXECUTE is not true, we disable generated code from running from
+# the heap and stack by default.
+#
+ifndef ($(LOCAL_DISABLE_NO_EXECUTE),true)
+  LOCAL_CFLAGS += $($(my)NO_EXECUTE_CFLAGS)
+  LOCAL_LDFLAGS += $($(my)NO_EXECUTE_LDFLAGS)
 endif
 
 #
index c793cfb..d093a13 100644 (file)
@@ -34,6 +34,7 @@ NDK_LOCAL_VARS := \
   LOCAL_ALLOW_UNDEFINED_SYMBOLS \
   LOCAL_ARM_MODE \
   LOCAL_ARM_NEON \
+  LOCAL_DISABLE_NO_EXECUTE \
 
 $(call clear-src-tags)
 $(call clear-vars, $(NDK_LOCAL_VARS))
index b92299b..82be6f7 100644 (file)
@@ -108,6 +108,13 @@ TARGET_LDLIBS := -Wl,-rpath-link=$(SYSROOT)/usr/lib
 # flags.
 TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
 
+# These flags are used to enfore the NX (no execute) security feature in the
+# generated machine code. This adds a special section to the generated shared
+# libraries that instruct the Linux kernel to disable code execution from
+# the stack and the heap.
+TARGET_NO_EXECUTE_CFLAGS  := -Wa,--noexecstack
+TARGET_NO_EXECUTE_LDFLAGS := -Wl,-z,noexecstack
+
 # The ABI-specific sub-directory that the SDK tools recognize for
 # this toolchain's generated binaries
 TARGET_ABI_SUBDIR := armeabi
index fc3c86e..585f73d 100644 (file)
@@ -132,6 +132,13 @@ TARGET_LDLIBS := -Wl,-rpath-link=$(SYSROOT)/usr/lib
 # flags.
 TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
 
+# These flags are used to enfore the NX (no execute) security feature in the
+# generated machine code. This adds a special section to the generated shared
+# libraries that instruct the Linux kernel to disable code execution from
+# the stack and the heap.
+TARGET_NO_EXECUTE_CFLAGS  := -Wa,--noexecstack
+TARGET_NO_EXECUTE_LDFLAGS := -Wl,-z,noexecstack
+
 # NOTE: Ensure that TARGET_LIBGCC is placed after all private objects
 #       and static libraries, but before any other library in the link
 #       command line when generating shared libraries and executables.
index 7c0a7e9..03c34c7 100644 (file)
@@ -466,3 +466,18 @@ LOCAL_ARM_NEON
 
     Note that the '.neon' suffix must appear after the '.arm' suffix
     if you use both (i.e. foo.c.arm.neon works, but not foo.c.neon.arm !)
+
+LOCAL_DISABLE_NO_EXECUTE
+    Android NDK r4 added support for the "NX bit" security feature.
+    It is enabled by default, but you can disable it if you *really*
+    need to by setting this variable to 'true'.
+
+    NOTE: This feature does not modify the ABI and is only enabled on
+          kernels targetting ARMv6+ CPU devices. Machine code generated
+          with this feature enabled will run unmodified on devices
+          running earlier CPU architectures.
+
+    For more information, see:
+
+        http://en.wikipedia.org/wiki/NX_bit
+        http://www.gentoo.org/proj/en/hardened/gnu-stack.xml
index f3cf415..b034cc3 100644 (file)
@@ -63,6 +63,13 @@ IMPORTANT CHANGES:
   and the new samble program under 'samples/bitmap-plasma' for details
   and usage example.
 
+- Support the NX (No Execute) security feature, where special sections
+  are added to the generated shared libraries to instruct the kernel
+  that code shall not be executed from the heap and stack by default.
+
+  See docs/ANDROID-MK.TXT to see how to disable this, plus reference
+  links for more information.
+
 OTHER FIXES & CHANGES:
 
 - support the .s extension for raw assembly sources (.S is already supported