olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1161666.patch

51f0aa
commit 533bb7c2ae156ff2d49b2e0b20b33810ba5e2721
51f0aa
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
51f0aa
Date:   Wed Nov 12 19:30:24 2014 +0530
51f0aa
51f0aa
    Fix stack alignment when loader is invoked directly
51f0aa
    
51f0aa
    The s390 ABI requires the stack pointer to be aligned at 8-bytes.
51f0aa
    When a program is invoked as an argument to the dynamic linker,
51f0aa
    _dl_start_user adjusts the stack to remove the dynamic linker
51f0aa
    arguments so that the program sees only its name and arguments.  This
51f0aa
    may result in the stack being misaligned since each argument shift is
51f0aa
    only a word and not a double-word.
51f0aa
    
51f0aa
    This is now fixed shifting argv and envp down instead of shifting argc
51f0aa
    up and reclaiming the stack.  This requires _dl_argv to be adjusted
51f0aa
    and hence, is no longer relro.
51f0aa
ce426f
diff --git glibc-2.17-c758a686/sysdeps/s390/s390-32/dl-machine.h glibc-2.17-c758a686/sysdeps/s390/s390-32/dl-machine.h
ce426f
index c56185c..79f8ef9 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/s390/s390-32/dl-machine.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/s390/s390-32/dl-machine.h
ce426f
@@ -166,18 +166,49 @@ _dl_start_user:\n\
ce426f
 	# See if we were run as a command with the executable file\n\
ce426f
 	# name as an extra leading argument.\n\
ce426f
 	l     %r1,_dl_skip_args@GOT12(0,%r12)\n\
ce426f
-	l     %r1,0(%r1)          # load _dl_skip_args\n\
ce426f
+	l     %r1,0(%r1)	# load _dl_skip_args\n\
ce426f
+	ltr   %r1,%r1\n\
ce426f
+	je    .L4		# Skip the arg adjustment if there were none.\n\
ce426f
 	# Get the original argument count.\n\
ce426f
 	l     %r0,96(%r15)\n\
ce426f
 	# Subtract _dl_skip_args from it.\n\
ce426f
 	sr    %r0,%r1\n\
ce426f
-	# Adjust the stack pointer to skip _dl_skip_args words.\n\
ce426f
-	sll   %r1,2\n\
ce426f
-	ar    %r15,%r1\n\
ce426f
-	# Set the back chain to zero again\n\
ce426f
-	xc    0(4,%r15),0(%r15)\n\
ce426f
 	# Store back the modified argument count.\n\
ce426f
 	st    %r0,96(%r15)\n\
ce426f
+	# Copy argv and envp forward to account for skipped argv entries.\n\
ce426f
+	# We skipped at least one argument or we would not get here.\n\
ce426f
+	la    %r6,100(%r15)	# Destination pointer i.e. &argv[0]\n\
ce426f
+	lr    %r5,%r6\n\
ce426f
+	lr    %r0,%r1\n\
ce426f
+	sll   %r0,2\n		# Number of skipped bytes.\n\
ce426f
+	ar    %r5,%r0		# Source pointer = Dest + Skipped args.\n\
ce426f
+	# argv copy loop:\n\
ce426f
+.L1:	l     %r7,0(%r5)	# Load a word from the source.\n\
ce426f
+	st    %r7,0(%r6)	# Store the word in the destination.\n\
ce426f
+	ahi   %r5,4\n\
ce426f
+	ahi   %r6,4\n\
ce426f
+	ltr   %r7,%r7\n\
ce426f
+	jne   .L1		# Stop after copying the NULL.\n\
ce426f
+	# envp copy loop:\n\
ce426f
+.L2:	l     %r7,0(%r5)	# Load a word from the source.\n\
ce426f
+	st    %r7,0(%r6)	# Store the word in the destination.\n\
ce426f
+	ahi   %r5,4\n\
ce426f
+	ahi   %r6,4\n\
ce426f
+	ltr   %r7,%r7\n\
ce426f
+	jne   .L2		# Stop after copying the NULL.\n\
ce426f
+	# Now we have to zero out the envp entries after NULL to allow\n\
ce426f
+	# start.S to properly find auxv by skipping zeroes.\n\
ce426f
+	# zero out loop:\n\
ce426f
+	lhi   %r7,0\n\
ce426f
+.L3:	st    %r7,0(%r6)	# Store zero.\n\
ce426f
+	ahi   %r6,4		# Advance dest pointer.\n\
ce426f
+	ahi   %r1,-1		# Subtract one from the word count.\n\
ce426f
+	ltr   %r1,%r1\n\
ce426f
+	jne    .L3		# Keep copying if the word count is non-zero.\n\
ce426f
+	# Adjust _dl_argv\n\
ce426f
+	la    %r6,100(%r15)\n\
ce426f
+	l     %r1,_dl_argv@GOT12(0,%r12)\n\
ce426f
+	st    %r6,0(%r1)\n\
ce426f
 	# The special initializer gets called with the stack just\n\
ce426f
 	# as the application's entry point will see it; it can\n\
ce426f
 	# switch stacks if it moves these contents over.\n\
ce426f
@@ -185,7 +216,7 @@ _dl_start_user:\n\
ce426f
 	# Call the function to run the initializers.\n\
ce426f
 	# Load the parameters:\n\
ce426f
 	# (%r2, %r3, %r4, %r5) = (_dl_loaded, argc, argv, envp)\n\
ce426f
-	l     %r2,_rtld_local@GOT(%r12)\n\
ce426f
+.L4:	l     %r2,_rtld_local@GOT(%r12)\n\
ce426f
 	l     %r2,0(%r2)\n\
ce426f
 	l     %r3,96(%r15)\n\
ce426f
 	la    %r4,100(%r15)\n\
ce426f
@@ -198,6 +229,9 @@ _dl_start_user:\n\
ce426f
 	l     %r14,_dl_fini@GOT(%r12)\n\
ce426f
 	# Free stack frame\n\
ce426f
 	ahi   %r15,96\n\
ce426f
+	# Reload argc and argv for the user's entry point.\n\
ce426f
+	# l     %r2,0(%r15)\n\
ce426f
+	# la    %r3,4(%r15)\n\
ce426f
 	# Jump to the user's entry point (saved in %r8).\n\
ce426f
 	br    %r8\n\
ce426f
 .Llit:\n\
ce426f
diff --git glibc-2.17-c758a686/sysdeps/s390/s390-32/dl-sysdep.h glibc-2.17-c758a686/sysdeps/s390/s390-32/dl-sysdep.h
ce426f
new file mode 100644
ce426f
index 0000000..b992778
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/s390/s390-32/dl-sysdep.h
ce426f
@@ -0,0 +1,23 @@
ce426f
+/* System-specific settings for dynamic linker code.  S/390 version.
ce426f
+   Copyright (C) 2014 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library.  If not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include_next <dl-sysdep.h>
ce426f
+
ce426f
+/* _dl_argv cannot be attribute_relro, because _dl_start_user
ce426f
+   might write into it after _dl_start returns.  */
ce426f
+#define DL_ARGV_NOT_RELRO 1