1*3f94c765Sjruoho# $NetBSD: t_random_garbage.sh,v 1.4 2020/07/27 07:36:19 jruoho Exp $ 27725c11dSjruoho# 37725c11dSjruoho# Copyright (c) 2020 The NetBSD Foundation, Inc. 47725c11dSjruoho# All rights reserved. 57725c11dSjruoho# 67725c11dSjruoho# This code is derived from software contributed to The NetBSD Foundation 77725c11dSjruoho# by Jukka Ruohonen. 87725c11dSjruoho# 97725c11dSjruoho# Redistribution and use in source and binary forms, with or without 107725c11dSjruoho# modification, are permitted provided that the following conditions 117725c11dSjruoho# are met: 127725c11dSjruoho# 1. Redistributions of source code must retain the above copyright 137725c11dSjruoho# notice, this list of conditions and the following disclaimer. 147725c11dSjruoho# 2. Redistributions in binary form must reproduce the above copyright 157725c11dSjruoho# notice, this list of conditions and the following disclaimer in the 167725c11dSjruoho# documentation and/or other materials provided with the distribution. 177725c11dSjruoho# 187725c11dSjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 197725c11dSjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 207725c11dSjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 217725c11dSjruoho# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 227725c11dSjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 237725c11dSjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 247725c11dSjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 257725c11dSjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 267725c11dSjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 277725c11dSjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 287725c11dSjruoho# POSSIBILITY OF SUCH DAMAGE. 297725c11dSjruoho# 307725c11dSjruohogetrint() { 317725c11dSjruoho echo $(od -An -N2 -i /dev/urandom | sed 's/ //') 327725c11dSjruoho} 337725c11dSjruoho 347725c11dSjruohogetrstr() { 357725c11dSjruoho echo $(cat /dev/urandom | head -n 1 | base64) 367725c11dSjruoho} 377725c11dSjruoho 387725c11dSjruohowrite_garbage() { 397725c11dSjruoho val=$(getrint) 407725c11dSjruoho echo "Test $3: write to $1 opt $2 -> $val" 413e2e2a93Sjruoho ifconfig $1 $2 $val >/dev/null 2>&1 427725c11dSjruoho val=$(getrstr) 437725c11dSjruoho echo "Test $3: write to $1 opt $2 -> $val" 443e2e2a93Sjruoho ifconfig $1 $2 $val >/dev/null 2>&1 457725c11dSjruoho} 467725c11dSjruoho 477725c11dSjruohoatf_test_case random_garbage 487725c11dSjruohorandom_garbage_head() { 497725c11dSjruoho atf_set "require.user" "root" 507b69662fSjruoho atf_set "descr" "Test writing random garbage to " \ 517b69662fSjruoho "ifconfig(8) options (PR kern/55451)" 527725c11dSjruoho} 537725c11dSjruoho 547725c11dSjruohorandom_garbage_body() { 557725c11dSjruoho 567725c11dSjruoho # Please note: 577725c11dSjruoho # 587725c11dSjruoho # 1. As some drivers seem to have input validation issues, it may 597725c11dSjruoho # be possible that horrors are written directly to the hardware. 607725c11dSjruoho # 617725c11dSjruoho # 2. Even if the test passes, there is no easy way to restore 627725c11dSjruoho # the existing state/configuration of any given interface. 637725c11dSjruoho # 647725c11dSjruoho # Take care. 657725c11dSjruoho # 66*3f94c765Sjruoho if ! [ $(atf_config_get "run_unsafe" "no") = "yes" ]; then 677b69662fSjruoho atf_skip "The test is not safe (PR kern/55451)" 68*3f94c765Sjruoho fi 697725c11dSjruoho 707725c11dSjruoho opts="advbase advskew broadcast carpdev description \ 717725c11dSjruoho media mediaopt -mediaopt mode instance metric mtu \ 727725c11dSjruoho netmask state frag rts ssid nwid nwkey pass powersavesleep \ 737725c11dSjruoho bssid chan tunnel session cookie pltime prefixlen linkstr \ 747725c11dSjruoho vhid vlan vlanif -vlanif agrport -agrport vltime maxupd \ 757725c11dSjruoho syncdev syncpeer" 767725c11dSjruoho 777725c11dSjruoho for i in $(ifconfig -l); do 787725c11dSjruoho 797725c11dSjruoho ifconfig $i up 807725c11dSjruoho 817725c11dSjruoho for o in $opts; do 827725c11dSjruoho 837725c11dSjruoho n=10 847725c11dSjruoho 857725c11dSjruoho while [ $n -gt 0 ]; do 867725c11dSjruoho write_garbage $i $o $n 877725c11dSjruoho n=$(expr $n - 1) 887725c11dSjruoho done 897725c11dSjruoho done 907725c11dSjruoho done 917725c11dSjruoho 927725c11dSjruoho atf_pass 937725c11dSjruoho} 947725c11dSjruoho 957725c11dSjruohoatf_init_test_cases() { 967725c11dSjruoho atf_add_test_case random_garbage 977725c11dSjruoho} 98