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, Richald Lowe. 15 16 # Verify that aslr musses things up, by comparing the mappings of 2 identical processes 17 18 LC_ALL=C # Collation is important 19 20 /usr/bin/psecflags -s aslr $$ 21 22 tmpdir=/tmp/test.$$ 23 24 mkdir $tmpdir 25 cd $tmpdir 26 27 cleanup() { 28 cd / 29 rm -fr $tmpdir 30 } 31 32 trap 'cleanup' EXIT 33 34 check() { 35 typeset name=$1 36 typeset command=$2 37 38 for (( i=0; i < 1000; i++ )); do 39 $command > out.$i 40 done 41 42 cat out.* | sort | uniq -c | sort -nk 1 | nawk ' 43 BEGIN { 44 tot = 0 45 colls = 0 46 } 47 48 $2 != "text:" { 49 tot += $1 50 if ($1 > 1) { 51 colls += $1 52 } 53 } 54 55 END { 56 prc = (colls / tot) * 100 57 printf "'$name' Collisions: %d/%d (%g%%)\n", colls, tot, prc 58 exit prc 59 } 60 ' 61 return $? 62 } 63 64 # Somewhat arbitrary 65 ACCEPTABLE=70 66 67 ret=0 68 check 32bit /opt/os-tests/tests/secflags/addrs-32 69 (( $? > $ACCEPTABLE )) && ret=1 70 check 64bit /opt/os-tests/tests/secflags/addrs-64 71 (( $? > $ACCEPTABLE )) && ret=1 72 73 exit $ret