comparison test/runtime/7107135/Test7107135.sh @ 8710:9058789475af

7107135: Stack guard pages are no more protected after loading a shared library with executable stack Summary: Detect the execstack attribute of the loaded library and attempt to fix the stack guard using Safepoint op. Reviewed-by: dholmes, zgu Contributed-by: ioi.lam@oracle.com
author iklam
date Tue, 05 Mar 2013 13:55:56 -0800
parents
children 04d6d4322c6a
comparison
equal deleted inserted replaced
8709:255c0a4cb4eb 8710:9058789475af
1 #!/bin/sh
2
3 #
4 # Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
5 # Copyright (c) 2011 SAP AG. All Rights Reserved.
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # This code is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License version 2 only, as
10 # published by the Free Software Foundation.
11 #
12 # This code is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # version 2 for more details (a copy is included in the LICENSE file that
16 # accompanied this code).
17 #
18 # You should have received a copy of the GNU General Public License version
19 # 2 along with this work; if not, write to the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 #
22 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23 # or visit www.oracle.com if you need additional information or have any
24 # questions.
25 #
26
27 ##
28 ## @test Test7107135.sh
29 ## @bug 7107135
30 ## @summary Stack guard pages lost after loading library with executable stack.
31 ## @run shell Test7107135.sh
32 ##
33
34 if [ "${TESTSRC}" = "" ]
35 then TESTSRC=.
36 fi
37
38 if [ "${TESTJAVA}" = "" ]
39 then
40 PARENT=`dirname \`which java\``
41 TESTJAVA=`dirname ${PARENT}`
42 echo "TESTJAVA not set, selecting " ${TESTJAVA}
43 echo "If this is incorrect, try setting the variable manually."
44 fi
45
46 BIT_FLAG=""
47
48 # set platform-dependent variables
49 OS=`uname -s`
50 case "$OS" in
51 Linux)
52 NULL=/dev/null
53 PS=":"
54 FS="/"
55 ;;
56 *)
57 NULL=NUL
58 PS=";"
59 FS="\\"
60 echo "Test passed; only valid for Linux"
61 exit 0;
62 ;;
63 esac
64
65 ARCH=`uname -m`
66
67 THIS_DIR=`pwd`
68
69 cp ${TESTSRC}${FS}*.java ${THIS_DIR}
70 ${TESTJAVA}${FS}bin${FS}javac *.java
71
72 gcc -fPIC -shared -c -o test.o -I${TESTJAVA}${FS}include -I${TESTJAVA}${FS}include${FS}linux ${TESTSRC}${FS}test.c
73 ld -shared -z execstack -o libtest-rwx.so test.o
74 ld -shared -z noexecstack -o libtest-rw.so test.o
75
76
77 LD_LIBRARY_PATH=${THIS_DIR}
78 echo LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
79 export LD_LIBRARY_PATH
80
81 # This should not fail.
82 echo Check testprogram. Expected to pass:
83 echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
84 ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
85
86 echo
87 echo Test changing of stack protection:
88 echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
89 ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rwx
90
91 if [ "$?" == "0" ]
92 then
93 echo
94 echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx
95 ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx
96 fi
97
98 exit $?