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