Skip to content

Commit 8e4acab

Browse files
committed
sysctl: Add 0012 to test the u8 range check
Add a sysctl test that uses the new u8 test ctl files in a created by the sysctl test module. Check that the u8 proc file that is valid is created and that there are two messages in dmesg for the files that were out of range. Reviewed-by: Kees Cook <kees@kernel.org> Signed-off-by: Joel Granados <joel.granados@kernel.org>
1 parent 138303e commit 8e4acab

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tools/testing/selftests/sysctl/sysctl.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ALL_TESTS="$ALL_TESTS 0008:1:1:match_int:1"
3636
ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0"
3737
ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0"
3838
ALL_TESTS="$ALL_TESTS 0011:1:1:empty_add:0"
39+
ALL_TESTS="$ALL_TESTS 0012:1:1:u8_valid:0"
3940

4041
function allow_user_defaults()
4142
{
@@ -851,6 +852,34 @@ sysctl_test_0011()
851852
return 0
852853
}
853854

855+
sysctl_test_0012()
856+
{
857+
TARGET="${SYSCTL}/$(get_test_target 0012)"
858+
echo -n "Testing u8 range check in sysctl table check in ${TARGET} ... "
859+
if [ ! -f ${TARGET} ]; then
860+
echo -e "FAIL\nCould not create ${TARGET}" >&2
861+
rc=1
862+
test_rc
863+
fi
864+
865+
local u8over_msg=$(dmesg | grep "u8_over range value" | wc -l)
866+
if [ ! ${u8over_msg} -eq 1 ]; then
867+
echo -e "FAIL\nu8 overflow not detected" >&2
868+
rc=1
869+
test_rc
870+
fi
871+
872+
local u8under_msg=$(dmesg | grep "u8_under range value" | wc -l)
873+
if [ ! ${u8under_msg} -eq 1 ]; then
874+
echo -e "FAIL\nu8 underflow not detected" >&2
875+
rc=1
876+
test_rc
877+
fi
878+
879+
echo "OK"
880+
return 0
881+
}
882+
854883
list_tests()
855884
{
856885
echo "Test ID list:"
@@ -870,6 +899,7 @@ list_tests()
870899
echo "0009 x $(get_test_count 0009) - tests sysct unregister"
871900
echo "0010 x $(get_test_count 0010) - tests sysct mount point"
872901
echo "0011 x $(get_test_count 0011) - tests empty directories"
902+
echo "0012 x $(get_test_count 0012) - tests range check for u8 proc_handler"
873903
}
874904

875905
usage()

0 commit comments

Comments
 (0)