1# 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2024 Igor Ostapenko <pm@igoro.pro> 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26 27# 28# Even being is_exclusive="true" this test does not expect a host to spawn 29# other jails during the test execution. 30# 31atf_test_case "max_cur" "cleanup" 32max_cur_head() 33{ 34 atf_set descr 'Test maximum and current number of child jails' 35 atf_set require.user root 36} 37max_cur_body() 38{ 39 origin_max=$(sysctl -n security.jail.children.max) 40 origin_cur=$(sysctl -n security.jail.children.cur) 41 42 # Magic numbers reasoning: 43 # 3 stands for: 44 # - the test creates three jails: childfree, maxallowed, maxallowed.family 45 # 6 stands for: 46 # - maxallowed.family wants to set children.max=4 47 # - it means that its parent (maxallowed) should have at least children.max=5 48 # - it makes the origin (parent of maxallowed) provide children.max=6 minimum 49 # 50 test $origin_cur -le $origin_max || atf_fail "Abnormal cur=$origin_cur > max=$origin_max." 51 test $((origin_max - origin_cur)) -ge 3 || atf_skip "Not enough child jails are allowed for the test." 52 test $origin_max -ge 6 || atf_skip "Not high enough children.max limit for the test." 53 54 jail -c name=childfree persist 55 atf_check_equal "$((origin_cur + 1))" "$(sysctl -n security.jail.children.cur)" 56 atf_check_equal "0" "$(jexec childfree sysctl -n security.jail.children.max)" 57 atf_check_equal "0" "$(jexec childfree sysctl -n security.jail.children.cur)" 58 59 jail -c name=maxallowed children.max=$((origin_max - 1)) persist 60 atf_check_equal "$((origin_cur + 2))" "$(sysctl -n security.jail.children.cur)" 61 atf_check_equal "$((origin_max - 1))" "$(jexec maxallowed sysctl -n security.jail.children.max)" 62 atf_check_equal "0" "$(jexec maxallowed sysctl -n security.jail.children.cur)" 63 64 jexec maxallowed jail -c name=family children.max=4 persist 65 atf_check_equal "$((origin_cur + 3))" "$(sysctl -n security.jail.children.cur)" 66 atf_check_equal "1" "$(jexec maxallowed sysctl -n security.jail.children.cur)" 67 atf_check_equal "4" "$(jexec maxallowed.family sysctl -n security.jail.children.max)" 68 atf_check_equal "0" "$(jexec maxallowed.family sysctl -n security.jail.children.cur)" 69} 70max_cur_cleanup() 71{ 72 jail -r maxallowed 73 jail -r childfree 74 return 0 75} 76 77atf_init_test_cases() 78{ 79 atf_add_test_case "max_cur" 80} 81