Path: blob/main/tests/sys/kern/sysctl_security_jail_children.sh
39482 views
#1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2024 Igor Ostapenko <[email protected]>4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions7# are met:8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# 2. Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24# SUCH DAMAGE.2526atf_test_case "max_cur" "cleanup"27max_cur_head()28{29atf_set descr 'Test maximum and current number of child jails'30atf_set require.user root31atf_set execenv jail32}33max_cur_body()34{35origin_max=$(sysctl -n security.jail.children.max)36origin_cur=$(sysctl -n security.jail.children.cur)3738# Magic numbers reasoning:39# 3 stands for:40# - the test creates three jails: childfree, maxallowed, maxallowed.family41# 6 stands for:42# - maxallowed.family wants to set children.max=443# - it means that its parent (maxallowed) should have at least children.max=544# - it makes the origin (parent of maxallowed) provide children.max=6 minimum45#46test $origin_cur -le $origin_max || atf_fail "Abnormal cur=$origin_cur > max=$origin_max."47test $((origin_max - origin_cur)) -ge 3 || atf_skip "Not enough child jails are allowed for the test."48test $origin_max -ge 6 || atf_skip "Not high enough children.max limit for the test."4950jail -c name=childfree persist51atf_check_equal "$((origin_cur + 1))" "$(sysctl -n security.jail.children.cur)"52atf_check_equal "0" "$(jexec childfree sysctl -n security.jail.children.max)"53atf_check_equal "0" "$(jexec childfree sysctl -n security.jail.children.cur)"5455jail -c name=maxallowed children.max=$((origin_max - 1)) persist56atf_check_equal "$((origin_cur + 2))" "$(sysctl -n security.jail.children.cur)"57atf_check_equal "$((origin_max - 1))" "$(jexec maxallowed sysctl -n security.jail.children.max)"58atf_check_equal "0" "$(jexec maxallowed sysctl -n security.jail.children.cur)"5960jexec maxallowed jail -c name=family children.max=4 persist61atf_check_equal "$((origin_cur + 3))" "$(sysctl -n security.jail.children.cur)"62atf_check_equal "1" "$(jexec maxallowed sysctl -n security.jail.children.cur)"63atf_check_equal "4" "$(jexec maxallowed.family sysctl -n security.jail.children.max)"64atf_check_equal "0" "$(jexec maxallowed.family sysctl -n security.jail.children.cur)"65}66max_cur_cleanup()67{68jail -r maxallowed69jail -r childfree70return 071}7273atf_init_test_cases()74{75atf_add_test_case "max_cur"76}777879