1 #! /usr/bin/ksh
2 #
3 #
4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
7 # 1.0 of the CDDL.
8 #
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
12 #
13
14 # Copyright 2015, Richard Lowe.
15
16 # Verify that aslr messes things up, by comparing the mappings of 2 identical
17 # processes
18
19 LC_ALL=C # Collation is important
20
21 /usr/bin/psecflags -s aslr $$
22
23 tmpdir=/tmp/test.$$
24
25 mkdir $tmpdir
26 cd $tmpdir
27
28 cleanup() {
29 cd /
30 rm -fr $tmpdir
31 }
32
33 trap 'cleanup' EXIT
34
35 check() {
36 typeset name=$1
37 typeset command=$2
38
39 for (( i=0; i < 1000; i++ )); do
40 $command > out.$i
41 done
42
43 cat out.* | sort | uniq -c | sort -nk 1 | nawk '
44 BEGIN {
45 tot = 0
46 colls = 0
47 }
48
49 $2 != "text:" {
50 tot += $1
51 if ($1 > 1) {
52 colls += $1
53 }
54 }
55
56 END {
57 prc = (colls / tot) * 100
58 printf "'$name' Collisions: %d/%d (%g%%)\n", colls, tot, prc
59 exit prc
60 }
61 '
62 return $?
63 }
64
65 # Somewhat arbitrary
66 ACCEPTABLE=70
67
68 ret=0
69 check 32bit /opt/os-tests/tests/secflags/addrs-32
70 (( $? > $ACCEPTABLE )) && ret=1
71 check 64bit /opt/os-tests/tests/secflags/addrs-64
72 (( $? > $ACCEPTABLE )) && ret=1
73
74 exit $ret