Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/sbin/sysctl Add a simple test case that writes random ...



details:   https://anonhg.NetBSD.org/src/rev/b5331ec57960
branches:  trunk
changeset: 935190:b5331ec57960
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sat Jun 27 08:50:46 2020 +0000

description:
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.

diffstat:

 distrib/sets/lists/tests/mi           |   3 +-
 tests/sbin/sysctl/Makefile            |   4 +-
 tests/sbin/sysctl/t_random_garbage.sh |  93 +++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 3 deletions(-)

diffs (129 lines):

diff -r 8c537e5b8b0c -r b5331ec57960 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jun 27 07:33:51 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jun 27 08:50:46 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.857 2020/06/27 06:57:44 jruoho Exp $
+# $NetBSD: mi,v 1.858 2020/06/27 08:50:46 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4032,6 +4032,7 @@
 ./usr/tests/sbin/sysctl/Atffile                        tests-sbin-tests        compattestfile,atf
 ./usr/tests/sbin/sysctl/Kyuafile               tests-sbin-tests        compattestfile,atf,kyua
 ./usr/tests/sbin/sysctl/t_perm                 tests-sbin-tests        compattestfile,atf
+./usr/tests/sbin/sysctl/t_random_garbage       tests-sbin-tests        compattestfile,atf
 ./usr/tests/sbin/sysctl/t_sysctl               tests-sbin-tests        compattestfile,atf
 ./usr/tests/share                              tests-sys-tests compattestfile,atf
 ./usr/tests/share/Atffile                      tests-sys-tests         compattestfile,atf
diff -r 8c537e5b8b0c -r b5331ec57960 tests/sbin/sysctl/Makefile
--- a/tests/sbin/sysctl/Makefile        Sat Jun 27 07:33:51 2020 +0000
+++ b/tests/sbin/sysctl/Makefile        Sat Jun 27 08:50:46 2020 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.2 2012/04/10 02:39:33 jruoho Exp $
+# $NetBSD: Makefile,v 1.3 2020/06/27 08:50:46 jruoho Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/sbin/sysctl
 
-TESTS_SH=      t_perm t_sysctl
+TESTS_SH=      t_perm t_random_garbage t_sysctl
 
 .include <bsd.test.mk>
diff -r 8c537e5b8b0c -r b5331ec57960 tests/sbin/sysctl/t_random_garbage.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sbin/sysctl/t_random_garbage.sh     Sat Jun 27 08:50:46 2020 +0000
@@ -0,0 +1,93 @@
+# $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
+}



Home | Main Index | Thread Index | Old Index