Print this page
11838 secflag tests are racy
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
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
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 +# Copyright 2019 Joyent, Inc.
15 16
16 17 tmpdir=/tmp/test.$$
17 18 mkdir $tmpdir
18 19 cd $tmpdir
19 20
20 21 cleanup() {
21 22 cd /
22 23 rm -fr $tmpdir
23 24 }
24 25
25 26 trap 'cleanup' EXIT
26 27
27 28 cat > tester.c <<EOF
28 29 #include <stdio.h>
29 30 #include <unistd.h>
30 31
31 32 int
32 33 main(int argc, char **argv)
33 34 {
34 35 sleep(10000);
35 36 return (0);
36 37 }
37 38 EOF
38 39
39 40 gcc -o tester-aslr tester.c -Wl,-z,aslr=enabled
40 41 gcc -o tester-noaslr tester.c -Wl,-z,aslr=disabled
41 42
42 43 # This is the easiest way I've found to get many many DTs, but it's gross
43 44 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)
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
44 45 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 46
46 47 check() {
47 48 bin=$1
48 49 state=$2
49 50 set=$3
50 51 ret=0
51 52
52 53 $bin &
53 54 pid=$!
55 + sleep 1
54 56 psecflags $pid | grep -q "${set}:.*aslr"
55 57 (( $? != $state )) && ret=1
56 58 kill -9 $pid
57 59 return $ret
58 60 }
59 61
60 62 fail() {
61 63 echo $@
62 64 exit 1
63 65 }
64 66
65 67 psecflags -s none $$
66 68 check ./tester-aslr 0 E || fail "DT_SUNW_ASLR 1 failed"
67 69 check ./many-dts-aslr 0 E || fail "DT_SUNW_ASLR 1 with many DTs failed"
68 70 check ./tester-aslr 1 I || fail "DT_SUNW_ASLR 1 incorrectly set the inheritable flag"
69 71
70 72 psecflags -s aslr $$
71 73 check ./tester-noaslr 1 E || fail "DT_SUNW_ASLR 0 failed"
72 74 check ./many-dts-noaslr 1 E || fail "DT_SUNW_ASLR 0 with many DTs failed"
73 75
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX