Sat Jun 27 08:50:46 2020 UTC ()
Add a simple test case that writes random garbage to (almost) every sysctl node.
This test reproduced already at least five unique panics in a few quick runs.
The test is skipped by default as it is not likely safe even without the panics.


(jruoho)
diff -r1.857 -r1.858 src/distrib/sets/lists/tests/mi
diff -r1.2 -r1.3 src/tests/sbin/sysctl/Makefile
diff -r0 -r1.1 src/tests/sbin/sysctl/t_random_garbage.sh

cvs diff -r1.857 -r1.858 src/distrib/sets/lists/tests/mi (expand / switch to unified diff)

--- src/distrib/sets/lists/tests/mi 2020/06/27 06:57:44 1.857
+++ src/distrib/sets/lists/tests/mi 2020/06/27 08:50:46 1.858
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: mi,v 1.857 2020/06/27 06:57:44 jruoho Exp $ 1# $NetBSD: mi,v 1.858 2020/06/27 08:50:46 jruoho Exp $
2# 2#
3# Note: don't delete entries from here - mark them as "obsolete" instead. 3# Note: don't delete entries from here - mark them as "obsolete" instead.
4# 4#
5./etc/mtree/set.tests tests-sys-root 5./etc/mtree/set.tests tests-sys-root
6./usr/libdata/debug/usr/tests tests-base-debug compattestdir 6./usr/libdata/debug/usr/tests tests-base-debug compattestdir
7./usr/libdata/debug/usr/tests/atf tests-atf-debug compattestfile,atf 7./usr/libdata/debug/usr/tests/atf tests-atf-debug compattestfile,atf
8./usr/libdata/debug/usr/tests/atf/atf-c tests-atf-debug compattestfile,atf 8./usr/libdata/debug/usr/tests/atf/atf-c tests-atf-debug compattestfile,atf
9./usr/libdata/debug/usr/tests/atf/atf-c++ tests-atf-debug compattestfile,atf 9./usr/libdata/debug/usr/tests/atf/atf-c++ tests-atf-debug compattestfile,atf
10./usr/libdata/debug/usr/tests/atf/atf-c++/detail tests-atf-debug compattestfile,atf 10./usr/libdata/debug/usr/tests/atf/atf-c++/detail tests-atf-debug compattestfile,atf
11./usr/libdata/debug/usr/tests/atf/atf-c/detail tests-atf-debug compattestfile,atf 11./usr/libdata/debug/usr/tests/atf/atf-c/detail tests-atf-debug compattestfile,atf
12./usr/libdata/debug/usr/tests/atf/atf-compile tests-obsolete obsolete 12./usr/libdata/debug/usr/tests/atf/atf-compile tests-obsolete obsolete
13./usr/libdata/debug/usr/tests/atf/atf-report tests-obsolete obsolete 13./usr/libdata/debug/usr/tests/atf/atf-report tests-obsolete obsolete
14./usr/libdata/debug/usr/tests/atf/atf-run tests-obsolete obsolete 14./usr/libdata/debug/usr/tests/atf/atf-run tests-obsolete obsolete
@@ -4022,26 +4022,27 @@ @@ -4022,26 +4022,27 @@
4022./usr/tests/sbin/resize_ffs/testdata.tar.gz.base64 tests-sbin-tests compattestfile,atf 4022./usr/tests/sbin/resize_ffs/testdata.tar.gz.base64 tests-sbin-tests compattestfile,atf
4023./usr/tests/sbin/route tests-sbin-tests compattestfile,atf 4023./usr/tests/sbin/route tests-sbin-tests compattestfile,atf
4024./usr/tests/sbin/route/Atffile tests-sbin-tests compattestfile,atf 4024./usr/tests/sbin/route/Atffile tests-sbin-tests compattestfile,atf
4025./usr/tests/sbin/route/Kyuafile tests-sbin-tests compattestfile,atf,kyua 4025./usr/tests/sbin/route/Kyuafile tests-sbin-tests compattestfile,atf,kyua
4026./usr/tests/sbin/route/t_missing tests-sbin-tests compattestfile,atf 4026./usr/tests/sbin/route/t_missing tests-sbin-tests compattestfile,atf
4027./usr/tests/sbin/setkey tests-sbin-tests compattestfile,atf 4027./usr/tests/sbin/setkey tests-sbin-tests compattestfile,atf
4028./usr/tests/sbin/setkey/Atffile tests-sbin-tests compattestfile,atf 4028./usr/tests/sbin/setkey/Atffile tests-sbin-tests compattestfile,atf
4029./usr/tests/sbin/setkey/Kyuafile tests-sbin-tests compattestfile,atf,kyua 4029./usr/tests/sbin/setkey/Kyuafile tests-sbin-tests compattestfile,atf,kyua
4030./usr/tests/sbin/setkey/t_setkey tests-sbin-tests compattestfile,atf 4030./usr/tests/sbin/setkey/t_setkey tests-sbin-tests compattestfile,atf
4031./usr/tests/sbin/sysctl tests-sbin-tests compattestfile,atf 4031./usr/tests/sbin/sysctl tests-sbin-tests compattestfile,atf
4032./usr/tests/sbin/sysctl/Atffile tests-sbin-tests compattestfile,atf 4032./usr/tests/sbin/sysctl/Atffile tests-sbin-tests compattestfile,atf
4033./usr/tests/sbin/sysctl/Kyuafile tests-sbin-tests compattestfile,atf,kyua 4033./usr/tests/sbin/sysctl/Kyuafile tests-sbin-tests compattestfile,atf,kyua
4034./usr/tests/sbin/sysctl/t_perm tests-sbin-tests compattestfile,atf 4034./usr/tests/sbin/sysctl/t_perm tests-sbin-tests compattestfile,atf
 4035./usr/tests/sbin/sysctl/t_random_garbage tests-sbin-tests compattestfile,atf
4035./usr/tests/sbin/sysctl/t_sysctl tests-sbin-tests compattestfile,atf 4036./usr/tests/sbin/sysctl/t_sysctl tests-sbin-tests compattestfile,atf
4036./usr/tests/share tests-sys-tests compattestfile,atf 4037./usr/tests/share tests-sys-tests compattestfile,atf
4037./usr/tests/share/Atffile tests-sys-tests compattestfile,atf 4038./usr/tests/share/Atffile tests-sys-tests compattestfile,atf
4038./usr/tests/share/Kyuafile tests-sys-tests compattestfile,atf,kyua 4039./usr/tests/share/Kyuafile tests-sys-tests compattestfile,atf,kyua
4039./usr/tests/share/examples tests-asm-tests compattestfile,atf 4040./usr/tests/share/examples tests-asm-tests compattestfile,atf
4040./usr/tests/share/examples/Atffile tests-asm-tests compattestfile,atf,share 4041./usr/tests/share/examples/Atffile tests-asm-tests compattestfile,atf,share
4041./usr/tests/share/examples/Kyuafile tests-asm-tests compattestfile,atf,share,kyua 4042./usr/tests/share/examples/Kyuafile tests-asm-tests compattestfile,atf,share,kyua
4042./usr/tests/share/examples/lutok tests-lutok-tests compattestfile,atf 4043./usr/tests/share/examples/lutok tests-lutok-tests compattestfile,atf
4043./usr/tests/share/examples/lutok/Atffile tests-lutok-tests compattestfile,atf,kyua,share 4044./usr/tests/share/examples/lutok/Atffile tests-lutok-tests compattestfile,atf,kyua,share
4044./usr/tests/share/examples/lutok/Kyuafile tests-lutok-tests compattestfile,atf,kyua,share,kyua 4045./usr/tests/share/examples/lutok/Kyuafile tests-lutok-tests compattestfile,atf,kyua,share,kyua
4045./usr/tests/share/examples/lutok/examples_test tests-lutok-tests compattestfile,atf,kyua,share 4046./usr/tests/share/examples/lutok/examples_test tests-lutok-tests compattestfile,atf,kyua,share
4046./usr/tests/share/examples/t_asm tests-asm-tests compattestfile,atf,share 4047./usr/tests/share/examples/t_asm tests-asm-tests compattestfile,atf,share
4047./usr/tests/share/mk tests-mk-tests compattestfile,atf 4048./usr/tests/share/mk tests-mk-tests compattestfile,atf

cvs diff -r1.2 -r1.3 src/tests/sbin/sysctl/Makefile (expand / switch to unified diff)

--- src/tests/sbin/sysctl/Makefile 2012/04/10 02:39:33 1.2
+++ src/tests/sbin/sysctl/Makefile 2020/06/27 08:50:46 1.3
@@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
1# $NetBSD: Makefile,v 1.2 2012/04/10 02:39:33 jruoho Exp $ 1# $NetBSD: Makefile,v 1.3 2020/06/27 08:50:46 jruoho Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4
5TESTSDIR= ${TESTSBASE}/sbin/sysctl 5TESTSDIR= ${TESTSBASE}/sbin/sysctl
6 6
7TESTS_SH= t_perm t_sysctl 7TESTS_SH= t_perm t_random_garbage t_sysctl
8 8
9.include <bsd.test.mk> 9.include <bsd.test.mk>

File Added: src/tests/sbin/sysctl/t_random_garbage.sh
# $NetBSD: t_random_garbage.sh,v 1.1 2020/06/27 08:50:46 jruoho Exp $
#
# Copyright (c) 2020 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Jukka Ruohonen.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
tmp="/tmp/sysctl.out"

getrint() {
	echo $(od -An -N2 -i /dev/urandom | sed 's/ //')
}

getrstr() {
	echo $(cat /dev/urandom | head -n 1 | base64)
}

atf_test_case random_garbage cleanup
random_garbage_head() {
	sysctl -a > $tmp
	atf_set "require.user" "root"
	atf_set "descr" "Test writing random garbage to sysctl nodes"
}

random_garbage_body() {

	atf_skip "The test is not safe"

	while read line; do

		var=$(echo $line | awk '{print $1}')

		case $var in
			kern.securelevel*)
			echo "Skipping $var"
			continue
			;;

			security*)
			echo "Skipping $var"
			continue
			;;
		esac

		val=$(getrint)
		echo "Write $var -> $val"
		sysctl -w $var=$val
		val=$(getrstr)
		echo "Write $var -> $val"
		sysctl -w $var=$val

	done < $tmp
}

random_garbage_cleanup() {

	atf_skip "The test is not safe"

	while read line; do
		var=$(echo $line | awk '{print $1}')
		val=$(echo $line | awk '{print $3}')
		echo "Restoring $var -> $val"
		sysctl -w $var=$val > /dev/null 2>&1
	done < $tmp

	rm $tmp
}

atf_init_test_cases() {
	atf_add_test_case random_garbage
}