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 #
  15 # Copyright 2015, Richard Lowe.
  16 # Copyright 2019 Joyent, Inc.
  17 #
  18 
  19 mkdir /tmp/secflags-test.$$
  20 cd /tmp/secflags-test.$$
  21 
  22 /usr/bin/psecflags -s aslr -e sleep 100000 &
  23 pid=$!
  24 coreadm -p core $pid # We need to be able to reliably find the core
  25 
  26 cleanup() {
  27     kill $pid >/dev/null 2>&1
  28     cd /
  29     rm -fr /tmp/secflags-test.$$
  30 }
  31 
  32 trap cleanup EXIT
  33 
  34 # We need to wait for sleep to get exec()ed
  35 sleep 1
  36 
  37 ## gcore-produced core
  38 gcore $pid >/dev/null
  39 
  40 cat > gcore-expected.$$ <<EOF
  41     namesz: 0x5
  42     descsz: 0x28
  43     type:   [ NT_SECFLAGS ]
  44     name:
  45         CORE\0
  46     desc: (prsecflags_t)
  47         pr_version:    1
  48         pr_effective:  [ ASLR ]
  49         pr_inherit:    [ ASLR ]
  50         pr_lower:      0
  51         pr_upper:      [ ASLR FORBIDNULLMAP NOEXECSTACK ]
  52 EOF
  53 
  54 /usr/bin/elfdump -n core.${pid} | grep -B5 -A5 prsecflags_t > gcore-output.$$
  55 
  56 if ! diff -u gcore-expected.$$ gcore-output.$$; then
  57     exit 1;
  58 fi
  59 
  60 ## kernel-produced core
  61 kill -SEGV $pid
  62 wait $pid >/dev/null 2>&1
  63 
  64 cat > core-expected.$$ <<EOF
  65     namesz: 0x5
  66     descsz: 0x28
  67     type:   [ NT_SECFLAGS ]
  68     name:
  69         CORE\0
  70     desc: (prsecflags_t)
  71         pr_version:    1
  72         pr_effective:  [ ASLR ]
  73         pr_inherit:    [ ASLR ]
  74         pr_lower:      0
  75         pr_upper:      [ ASLR FORBIDNULLMAP NOEXECSTACK ]
  76 EOF
  77 
  78 /usr/bin/elfdump -n core | grep -B5 -A5 prsecflags_t > core-output.$$
  79 
  80 if ! diff -u core-expected.$$ core-output.$$; then
  81     exit 1;
  82 fi
  83 
  84 exit 0