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