[linux] 03/04: [x86] mmap: Add an exception to the stack gap for Hotspot JVM compatibility

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Sat Dec 2 15:26:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch jessie
in repository linux.

commit ee3ab00248d1b62709ec9b9e61b275866ab4d029
Author: Ben Hutchings <ben at decadent.org.uk>
Date:   Thu Nov 30 01:06:55 2017 +0000

    [x86] mmap: Add an exception to the stack gap for Hotspot JVM compatibility
    
    Closes: #865303
---
 debian/changelog                                   |  3 ++
 ...xception-to-the-stack-gap-for-hotspot-jvm.patch | 45 ++++++++++++++++++++++
 ...p-remember-the-map_fixed-flag-as-vm_fixed.patch | 32 +++++++++++++++
 debian/patches/series                              |  2 +
 4 files changed, 82 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 3eba2f3..1c703c9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -439,6 +439,9 @@ linux (3.16.51-1) UNRELEASED; urgency=medium
   * inet_frag: Limit ABI change in 3.16.51
   * [s390*] mm: Avoid ABI change in 3.16.51
   * mm/mmap.c: expand_downwards: don't require the gap if !vm_prev
+  * mmap: Remember the MAP_FIXED flag as VM_FIXED
+  * [x86] mmap: Add an exception to the stack gap for Hotspot JVM compatibility
+    (Closes: #865303)
 
  -- Salvatore Bonaccorso <carnil at debian.org>  Thu, 05 Oct 2017 21:54:27 +0200
 
diff --git a/debian/patches/bugfix/x86/mmap-add-an-exception-to-the-stack-gap-for-hotspot-jvm.patch b/debian/patches/bugfix/x86/mmap-add-an-exception-to-the-stack-gap-for-hotspot-jvm.patch
new file mode 100644
index 0000000..229b269
--- /dev/null
+++ b/debian/patches/bugfix/x86/mmap-add-an-exception-to-the-stack-gap-for-hotspot-jvm.patch
@@ -0,0 +1,45 @@
+From: Ben Hutchings <ben at decadent.org.uk>
+Date: Thu, 30 Nov 2017 00:29:18 +0000
+Subject: mmap: Add an exception to the stack gap for Hotspot JVM compatibility
+Bug-Debian: https://bugs.debian.org/865303
+
+The Hotspot JVM can easily exhaust the default stack, and has a
+SIGSEGV handler to cope with this by switching to a new stack segment.
+
+However, on i386 it creates a single writable and executable page just
+under the stack limit as a workaround for a bug in Exec Shield.  That
+together with the enlarged stack gap causes the SIGSEGV handler to be
+triggered when the stack pointer is further away from the stack limit,
+and it doesn't recognise this as being a stack overflow.
+
+This specifically affects programs that use JNI.  Hotspot doesn't
+normally run Java code on the initial thread.
+
+Reduce the effective stack guard gap on x86 if the previous vma is
+a single page allocated as MAP_FIXED.
+
+References: https://bugs.debian.org/865303
+Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
+---
+ mm/mmap.c | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+--- a/mm/mmap.c
++++ b/mm/mmap.c
+@@ -2233,6 +2233,16 @@ int expand_downwards(struct vm_area_stru
+ 	/* Check that both stack segments have the same anon_vma? */
+ 	if (prev && !(prev->vm_flags & VM_GROWSDOWN) &&
+ 			(prev->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
++		/*
++		 * bwh: Reduce the stack guard gap if this looks like
++		 * Hotspot JVM craziness - see Debian bug #865303
++		 */
++		if (IS_ENABLED(CONFIG_X86) && (prev->vm_flags & VM_FIXED) &&
++		    prev->vm_end - prev->vm_start == PAGE_SIZE) {
++			if (address - prev->vm_end <
++			    min(stack_guard_gap, 4UL << PAGE_SHIFT))
++				return -ENOMEM;
++		} else
+ 		if (address - prev->vm_end < stack_guard_gap)
+ 			return -ENOMEM;
+ 	}
diff --git a/debian/patches/bugfix/x86/mmap-remember-the-map_fixed-flag-as-vm_fixed.patch b/debian/patches/bugfix/x86/mmap-remember-the-map_fixed-flag-as-vm_fixed.patch
new file mode 100644
index 0000000..081d7c0
--- /dev/null
+++ b/debian/patches/bugfix/x86/mmap-remember-the-map_fixed-flag-as-vm_fixed.patch
@@ -0,0 +1,32 @@
+From: Ben Hutchings <ben at decadent.org.uk>
+Date: Wed, 5 Jul 2017 13:32:43 +0100
+Subject: mmap: Remember the MAP_FIXED flag as VM_FIXED
+
+Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
+---
+ include/linux/mm.h   | 1 +
+ include/linux/mman.h | 3 ++-
+ 2 files changed, 3 insertions(+), 1 deletion(-)
+
+--- a/include/linux/mm.h
++++ b/include/linux/mm.h
+@@ -127,6 +127,7 @@ extern unsigned int kobjsize(const void
+ #define VM_HUGETLB	0x00400000	/* Huge TLB Page VM */
+ #define VM_NONLINEAR	0x00800000	/* Is non-linear (remap_file_pages) */
+ #define VM_ARCH_1	0x01000000	/* Architecture-specific flag */
++#define VM_FIXED	0x02000000	/* Allocated at fixed address */
+ #define VM_DONTDUMP	0x04000000	/* Do not include in the core dump */
+ 
+ #ifdef CONFIG_MEM_SOFT_DIRTY
+--- a/include/linux/mman.h
++++ b/include/linux/mman.h
+@@ -86,7 +86,8 @@ calc_vm_flag_bits(unsigned long flags)
+ {
+ 	return _calc_vm_trans(flags, MAP_GROWSDOWN,  VM_GROWSDOWN ) |
+ 	       _calc_vm_trans(flags, MAP_DENYWRITE,  VM_DENYWRITE ) |
+-	       _calc_vm_trans(flags, MAP_LOCKED,     VM_LOCKED    );
++	       _calc_vm_trans(flags, MAP_LOCKED,     VM_LOCKED    ) |
++	       _calc_vm_trans(flags, MAP_FIXED,      VM_FIXED     );
+ }
+ 
+ unsigned long vm_commit_limit(void);
diff --git a/debian/patches/series b/debian/patches/series
index 59449cf..bde22bf 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -249,6 +249,8 @@ bugfix/all/ipv6-fix-a-refcnt-leak-with-peer-addr.patch
 bugfix/all/ipv6-use-addrconf_get_prefix_route-to-remove-peer-ad.patch
 bugfix/all/vfs-avoid-creation-of-inode-number-0-in-get_next_ino.patch
 bugfix/all/mm-mmap.c-expand_downwards-don-t-require-the-gap-if-.patch
+bugfix/x86/mmap-remember-the-map_fixed-flag-as-vm_fixed.patch
+bugfix/x86/mmap-add-an-exception-to-the-stack-gap-for-hotspot-jvm.patch
 
 # memfd_create() & kdbus backport
 features/all/kdbus/mm-allow-drivers-to-prevent-new-writable-mappings.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/linux.git



More information about the Kernel-svn-changes mailing list