Print this page
sync further changes from uts/aslr


  29 #include <unistd.h>
  30 
  31 int
  32 main(int argc, char **argv)
  33 {
  34         sleep(10000);
  35         return (0);
  36 }
  37 EOF
  38 
  39 gcc -o tester-aslr tester.c -Wl,-z,aslr=enabled
  40 gcc -o tester-noaslr tester.c -Wl,-z,aslr=disabled
  41 
  42 # This is the easiest way I've found to get many many DTs, but it's gross
  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 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 check() {
  47     bin=$1
  48     state=$2

  49     ret=0
  50 
  51     $bin &
  52     pid=$!
  53     psecflags $pid | grep -q 'E:.*aslr'
  54     (( $? != $state )) && ret=1
  55     kill -9 $pid
  56     return $ret
  57 }
  58 
  59 fail() {
  60     echo $@
  61     exit 1
  62 }
  63 
  64 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"

  67 
  68 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 


  29 #include <unistd.h>
  30 
  31 int
  32 main(int argc, char **argv)
  33 {
  34         sleep(10000);
  35         return (0);
  36 }
  37 EOF
  38 
  39 gcc -o tester-aslr tester.c -Wl,-z,aslr=enabled
  40 gcc -o tester-noaslr tester.c -Wl,-z,aslr=disabled
  41 
  42 # This is the easiest way I've found to get many many DTs, but it's gross
  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 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 check() {
  47     bin=$1
  48     state=$2
  49     set=$3
  50     ret=0
  51 
  52     $bin &
  53     pid=$!
  54     psecflags $pid | grep -q "${set}:.*aslr"
  55     (( $? != $state )) && ret=1
  56     kill -9 $pid
  57     return $ret
  58 }
  59 
  60 fail() {
  61     echo $@
  62     exit 1
  63 }
  64 
  65 psecflags -s none $$
  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"
  69 
  70 psecflags -s aslr $$
  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"
  73