Print this page
sync further changes from uts/aslr
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/test/os-tests/tests/secflags/secflags_dts.sh
+++ new/usr/src/test/os-tests/tests/secflags/secflags_dts.sh
1 1 #! /usr/bin/ksh
2 2 #
3 3 #
4 4 # This file and its contents are supplied under the terms of the
5 5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 6 # You may only use this file in accordance with the terms of version
7 7 # 1.0 of the CDDL.
8 8 #
9 9 # A full copy of the text of the CDDL should have accompanied this
10 10 # source. A copy of the CDDL is also available via the Internet at
11 11 # http://www.illumos.org/license/CDDL.
12 12 #
13 13
14 14 # Copyright 2015, Richard Lowe.
15 15
16 16 tmpdir=/tmp/test.$$
17 17 mkdir $tmpdir
18 18 cd $tmpdir
19 19
20 20 cleanup() {
21 21 cd /
22 22 rm -fr $tmpdir
23 23 }
24 24
25 25 trap 'cleanup' EXIT
26 26
27 27 cat > tester.c <<EOF
28 28 #include <stdio.h>
29 29 #include <unistd.h>
30 30
31 31 int
32 32 main(int argc, char **argv)
33 33 {
34 34 sleep(10000);
35 35 return (0);
36 36 }
37 37 EOF
38 38
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
39 39 gcc -o tester-aslr tester.c -Wl,-z,aslr=enabled
40 40 gcc -o tester-noaslr tester.c -Wl,-z,aslr=disabled
41 41
42 42 # This is the easiest way I've found to get many many DTs, but it's gross
43 43 gcc -o many-dts-aslr tester.c -Wl,-z,aslr=enabled $(for elt in /usr/lib/lib*.so; do echo -Wl,-N,$(basename $elt); done)
44 44 gcc -o many-dts-noaslr tester.c -Wl,-z,aslr=disabled $(for elt in /usr/lib/lib*.so; do echo -Wl,-N,$(basename $elt); done)
45 45
46 46 check() {
47 47 bin=$1
48 48 state=$2
49 + set=$3
49 50 ret=0
50 51
51 52 $bin &
52 53 pid=$!
53 - psecflags $pid | grep -q 'E:.*aslr'
54 + psecflags $pid | grep -q "${set}:.*aslr"
54 55 (( $? != $state )) && ret=1
55 56 kill -9 $pid
56 57 return $ret
57 58 }
58 59
59 60 fail() {
60 61 echo $@
61 62 exit 1
62 63 }
63 64
64 65 psecflags -s none $$
65 -check ./tester-aslr 0 || fail "DT_SUNW_ASLR 1 failed"
66 -check ./many-dts-aslr 0 || fail "DT_SUNW_ASLR 1 with many DTs failed"
66 +check ./tester-aslr 0 E || fail "DT_SUNW_ASLR 1 failed"
67 +check ./many-dts-aslr 0 E || fail "DT_SUNW_ASLR 1 with many DTs failed"
68 +check ./tester-aslr 1 I || fail "DT_SUNW_ASLR 1 incorrectly set the inheritable flag"
67 69
68 70 psecflags -s aslr $$
69 -check ./tester-noaslr 1 || fail "DT_SUNW_ASLR 0 failed"
70 -check ./many-dts-noaslr 1 || fail "DT_SUNW_ASLR 0 with many DTs failed"
71 +check ./tester-noaslr 1 E || fail "DT_SUNW_ASLR 0 failed"
72 +check ./many-dts-noaslr 1 E || fail "DT_SUNW_ASLR 0 with many DTs failed"
71 73
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX