xref: /illumos-gate/usr/src/test/os-tests/tests/secflags/secflags_elfdump.sh (revision 5328fc53d11d7151861fa272e4fb0248b8f0e145)
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
19mkdir /tmp/secflags-test.$$
20cd /tmp/secflags-test.$$
21
22/usr/bin/psecflags -s aslr -e sleep 100000 &
23pid=$!
24# Make sure we generate a kernel core we can find
25coreadm -p core $pid
26enabled=$(/usr/bin/svcprop -p config_params/process_enabled coreadm)
27coreadm_restore=""
28if [[ "$enabled" = "false" ]]; then
29    coreadm_restore="/usr/bin/coreadm -d process"
30    coreadm -e process
31fi
32
33cleanup() {
34    kill $pid >/dev/null 2>&1
35    cd /
36    rm -fr /tmp/secflags-test.$$
37
38    $coreadm_restore
39}
40
41trap cleanup EXIT
42
43# We need to wait for sleep to get exec()ed
44sleep 1
45
46## gcore-produced core
47gcore $pid >/dev/null
48
49cat > gcore-expected.$$ <<EOF
50    namesz: 0x5
51    descsz: 0x28
52    type:   [ NT_SECFLAGS ]
53    name:
54        CORE\0
55    desc: (prsecflags_t)
56        pr_version:    1
57        pr_effective:  [ ASLR ]
58        pr_inherit:    [ ASLR ]
59        pr_lower:      0
60        pr_upper:      [ ASLR FORBIDNULLMAP NOEXECSTACK ]
61EOF
62
63/usr/bin/elfdump -n core.${pid} | grep -B5 -A5 prsecflags_t > gcore-output.$$
64
65if ! diff -u gcore-expected.$$ gcore-output.$$; then
66    $coreadm_restore
67    exit 1;
68fi
69
70## kernel-produced core
71kill -SEGV $pid
72wait $pid >/dev/null 2>&1
73$coreadm_restore
74
75cat > core-expected.$$ <<EOF
76    namesz: 0x5
77    descsz: 0x28
78    type:   [ NT_SECFLAGS ]
79    name:
80        CORE\0
81    desc: (prsecflags_t)
82        pr_version:    1
83        pr_effective:  [ ASLR ]
84        pr_inherit:    [ ASLR ]
85        pr_lower:      0
86        pr_upper:      [ ASLR FORBIDNULLMAP NOEXECSTACK ]
87EOF
88
89/usr/bin/elfdump -n core | grep -B5 -A5 prsecflags_t > core-output.$$
90
91if ! diff -u core-expected.$$ core-output.$$; then
92    exit 1;
93fi
94
95exit 0
96