Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+30
+30
tools/testing/selftests/sysctl/sysctl.sh
··· 36 36 ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0" 37 37 ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0" 38 38 ALL_TESTS="$ALL_TESTS 0011:1:1:empty_add:0" 39 + ALL_TESTS="$ALL_TESTS 0012:1:1:u8_valid:0" 39 40 40 41 function allow_user_defaults() 41 42 { ··· 852 851 return 0 853 852 } 854 853 854 + sysctl_test_0012() 855 + { 856 + TARGET="${SYSCTL}/$(get_test_target 0012)" 857 + echo -n "Testing u8 range check in sysctl table check in ${TARGET} ... " 858 + if [ ! -f ${TARGET} ]; then 859 + echo -e "FAIL\nCould not create ${TARGET}" >&2 860 + rc=1 861 + test_rc 862 + fi 863 + 864 + local u8over_msg=$(dmesg | grep "u8_over range value" | wc -l) 865 + if [ ! ${u8over_msg} -eq 1 ]; then 866 + echo -e "FAIL\nu8 overflow not detected" >&2 867 + rc=1 868 + test_rc 869 + fi 870 + 871 + local u8under_msg=$(dmesg | grep "u8_under range value" | wc -l) 872 + if [ ! ${u8under_msg} -eq 1 ]; then 873 + echo -e "FAIL\nu8 underflow not detected" >&2 874 + rc=1 875 + test_rc 876 + fi 877 + 878 + echo "OK" 879 + return 0 880 + } 881 + 855 882 list_tests() 856 883 { 857 884 echo "Test ID list:" ··· 899 870 echo "0009 x $(get_test_count 0009) - tests sysct unregister" 900 871 echo "0010 x $(get_test_count 0010) - tests sysct mount point" 901 872 echo "0011 x $(get_test_count 0011) - tests empty directories" 873 + echo "0012 x $(get_test_count 0012) - tests range check for u8 proc_handler" 902 874 } 903 875 904 876 usage()