diff options
| author | John Levon <john.levon@joyent.com> | 2019-10-17 02:54:25 -0700 |
|---|---|---|
| committer | John Levon <john.levon@joyent.com> | 2019-10-28 23:05:28 +0000 |
| commit | fdfb6e575f06007c35263fbcdc483157ef62d712 (patch) | |
| tree | 0ad10d599b53d2686eea3a7d6b5df835efb6af50 | |
| parent | 3dae5456c609a0bdfeffc8d1c0dc436db6ab3436 (diff) | |
| download | illumos-joyent-fdfb6e575f06007c35263fbcdc483157ef62d712.tar.gz | |
11838 secflag tests are racy
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Approved by: Dan McDonald <danmcd@joyent.com>
5 files changed, 46 insertions, 16 deletions
diff --git a/usr/src/test/os-tests/tests/secflags/secflags_core.sh b/usr/src/test/os-tests/tests/secflags/secflags_core.sh index 881f09f1aa..958e3c6b01 100644 --- a/usr/src/test/os-tests/tests/secflags/secflags_core.sh +++ b/usr/src/test/os-tests/tests/secflags/secflags_core.sh @@ -13,6 +13,7 @@ # # Copyright 2015, Richard Lowe. +# Copyright 2019 Joyent, Inc. # mkdir /tmp/secflags-test.$$ @@ -20,16 +21,26 @@ cd /tmp/secflags-test.$$ /usr/bin/psecflags -s aslr -e sleep 100000 & pid=$! -coreadm -p core $pid # We need to be able to reliably find the core +# Make sure we generate a kernel core we can find +coreadm -p core $pid +enabled=$(/usr/bin/svcprop -p config_params/process_enabled coreadm) +coreadm_restore="" +if [[ "$enabled" = "false" ]]; then + coreadm_restore="/usr/bin/coreadm -d process" + coreadm -e process +fi cleanup() { kill $pid >/dev/null 2>&1 cd / rm -fr /tmp/secflags-test.$$ + + $coreadm_restore } trap cleanup EXIT +sleep 1 ## gcore-produced core gcore $pid >/dev/null @@ -42,12 +53,14 @@ EOF /usr/bin/psecflags core.${pid} | grep -v '[LU]:' > gcore-output.$$ if ! diff -u gcore-expected.$$ gcore-output.$$; then + $coreadm_restore exit 1; fi ## kernel-produced core kill -SEGV $pid wait $pid >/dev/null 2>&1 +$coreadm_restore cat > core-expected.$$ <<EOF core 'core' of $pid: sleep 100000 diff --git a/usr/src/test/os-tests/tests/secflags/secflags_dts.sh b/usr/src/test/os-tests/tests/secflags/secflags_dts.sh index b140943145..0086ed065e 100644 --- a/usr/src/test/os-tests/tests/secflags/secflags_dts.sh +++ b/usr/src/test/os-tests/tests/secflags/secflags_dts.sh @@ -12,6 +12,7 @@ # # Copyright 2015, Richard Lowe. +# Copyright 2019 Joyent, Inc. tmpdir=/tmp/test.$$ mkdir $tmpdir @@ -51,6 +52,7 @@ check() { $bin & pid=$! + sleep 1 psecflags $pid | grep -q "${set}:.*aslr" (( $? != $state )) && ret=1 kill -9 $pid diff --git a/usr/src/test/os-tests/tests/secflags/secflags_elfdump.sh b/usr/src/test/os-tests/tests/secflags/secflags_elfdump.sh index 3c01fff8ac..334ebc16a9 100644 --- a/usr/src/test/os-tests/tests/secflags/secflags_elfdump.sh +++ b/usr/src/test/os-tests/tests/secflags/secflags_elfdump.sh @@ -13,6 +13,7 @@ # # Copyright 2015, Richard Lowe. +# Copyright 2019 Joyent, Inc. # mkdir /tmp/secflags-test.$$ @@ -30,6 +31,9 @@ cleanup() { trap cleanup EXIT +# We need to wait for sleep to get exec()ed +sleep 1 + ## gcore-produced core gcore $pid >/dev/null diff --git a/usr/src/test/os-tests/tests/secflags/secflags_proc.sh b/usr/src/test/os-tests/tests/secflags/secflags_proc.sh index e4a8c6bc82..8a48bc2f22 100644 --- a/usr/src/test/os-tests/tests/secflags/secflags_proc.sh +++ b/usr/src/test/os-tests/tests/secflags/secflags_proc.sh @@ -13,6 +13,7 @@ # # Copyright 2015, Richard Lowe. +# Copyright 2019 Joyent, Inc. # /usr/bin/psecflags -s aslr -e sleep 100000 & @@ -32,6 +33,9 @@ $pid: sleep 100000 I: aslr EOF +# We need to wait for sleep to get exec()ed +sleep 1 + /usr/bin/psecflags $pid | grep -v '[LU]:' > /tmp/output.$$ if ! diff -u /tmp/expected.$$ /tmp/output.$$; then diff --git a/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh b/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh index 9e1362ea30..566e22cee2 100644 --- a/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh +++ b/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh @@ -13,8 +13,15 @@ # # Copyright 2015, Richard Lowe. +# Copyright 2019 Joyent, Inc. # +# check secflags, waiting a little bit for the change to happen +secflags() { + sleep 1 + /usr/bin/psecflags $* +} + mkdir /tmp/$$-secflags-test cd /tmp/$$-secflags-test @@ -23,7 +30,7 @@ cat > expected <<EOF I: none EOF -/usr/bin/psecflags $$ | grep I: > output +secflags $$ | grep I: > output diff -u expected output || exit 1 # Make sure the setting of 'none' worked cleanup() { @@ -42,7 +49,7 @@ self_set() { I: aslr EOF - /usr/bin/psecflags $$ | grep I: > output + secflags $$ | grep I: > output diff -u expected output || exit 1 } @@ -53,7 +60,7 @@ self_add() { I: aslr,noexecstack EOF - /usr/bin/psecflags $$ | grep I: > output + secflags $$ | grep I: > output diff -u expected output || exit 1 } @@ -64,14 +71,14 @@ self_remove() { I: noexecstack EOF - /usr/bin/psecflags $$ | grep I: > output + secflags $$ | grep I: > output diff -u expected output || exit 1 } self_all() { echo "All (self)" /usr/bin/psecflags -s all $$ - /usr/bin/psecflags $$ | grep -q 'I:.*,.*,' || exit 1 # This is lame, but functional + secflags $$ | grep -q 'I:.*,.*,' || exit 1 # This is lame, but functional } self_none() { @@ -81,14 +88,14 @@ self_none() { cat > expected <<EOF I: none EOF - /usr/bin/psecflags $$ | grep I: > output + secflags $$ | grep I: > output diff -u expected output || exit 1 } child_set() { echo "Set (child)" - typeset pid; + typeset pid; /usr/bin/psecflags -s aslr -e sleep 10000 & pid=$! @@ -96,7 +103,7 @@ child_set() { E: aslr I: aslr EOF - /usr/bin/psecflags $pid | grep '[IE]:' > output + secflags $pid | grep '[IE]:' > output kill $pid diff -u expected output || exit 1 } @@ -104,7 +111,7 @@ EOF child_add() { echo "Add (child)" - typeset pid; + typeset pid; /usr/bin/psecflags -s aslr $$ /usr/bin/psecflags -s current,noexecstack -e sleep 10000 & @@ -113,7 +120,7 @@ child_add() { E: aslr,noexecstack I: aslr,noexecstack EOF - /usr/bin/psecflags $pid | grep '[IE]:' > output + secflags $pid | grep '[IE]:' > output kill $pid /usr/bin/psecflags -s none $$ diff -u expected output || exit 1 @@ -122,7 +129,7 @@ EOF child_remove() { echo "Remove (child)" - typeset pid; + typeset pid; /usr/bin/psecflags -s aslr $$ /usr/bin/psecflags -s current,-aslr -e sleep 10000 & @@ -131,7 +138,7 @@ child_remove() { E: none I: none EOF - /usr/bin/psecflags $pid | grep '[IE]:' > output + secflags $pid | grep '[IE]:' > output kill $pid /usr/bin/psecflags -s none $$ diff -u expected output || exit 1 @@ -144,7 +151,7 @@ child_all() { /usr/bin/psecflags -s all -e sleep 10000 & pid=$! - /usr/bin/psecflags $pid | grep -q 'E:.*,.*,' # This is lame, but functional + secflags $pid | grep -q 'E:.*,.*,' # This is lame, but functional ret=$? kill $pid (( $ret != 0 )) && exit $ret @@ -154,7 +161,7 @@ child_none() { echo "None (child)" typeset pid - + /usr/bin/psecflags -s all $$ /usr/bin/psecflags -s none -e sleep 10000 & @@ -163,7 +170,7 @@ child_none() { E: none I: none EOF - /usr/bin/psecflags $pid | grep '[IE]:' > output + secflags $pid | grep '[IE]:' > output kill $pid diff -u expected output || exit 1 } |
