]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sysctl: Add 0012 to test the u8 range check
authorJoel Granados <joel.granados@kernel.org>
Fri, 21 Mar 2025 08:44:39 +0000 (09:44 +0100)
committerJoel Granados <joel.granados@kernel.org>
Mon, 14 Apr 2025 12:13:41 +0000 (14:13 +0200)
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>
tools/testing/selftests/sysctl/sysctl.sh

index db1616857d8987fc364d33494c5fc30521e7939e..a10350c8a46e42691f4f89763bc3e2d3dc270097 100755 (executable)
@@ -36,6 +36,7 @@ ALL_TESTS="$ALL_TESTS 0008:1:1:match_int:1"
 ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0"
 ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0"
 ALL_TESTS="$ALL_TESTS 0011:1:1:empty_add:0"
+ALL_TESTS="$ALL_TESTS 0012:1:1:u8_valid:0"
 
 function allow_user_defaults()
 {
@@ -851,6 +852,34 @@ sysctl_test_0011()
        return 0
 }
 
+sysctl_test_0012()
+{
+       TARGET="${SYSCTL}/$(get_test_target 0012)"
+       echo -n "Testing u8 range check in sysctl table check in ${TARGET} ... "
+       if [ ! -f ${TARGET} ]; then
+               echo -e "FAIL\nCould not create ${TARGET}" >&2
+               rc=1
+               test_rc
+       fi
+
+       local u8over_msg=$(dmesg | grep "u8_over range value" | wc -l)
+       if [ ! ${u8over_msg} -eq 1 ]; then
+               echo -e "FAIL\nu8 overflow not detected" >&2
+               rc=1
+               test_rc
+       fi
+
+       local u8under_msg=$(dmesg | grep "u8_under range value" | wc -l)
+       if [ ! ${u8under_msg} -eq 1 ]; then
+               echo -e "FAIL\nu8 underflow not detected" >&2
+               rc=1
+               test_rc
+       fi
+
+       echo "OK"
+       return 0
+}
+
 list_tests()
 {
        echo "Test ID list:"
@@ -870,6 +899,7 @@ list_tests()
        echo "0009 x $(get_test_count 0009) - tests sysct unregister"
        echo "0010 x $(get_test_count 0010) - tests sysct mount point"
        echo "0011 x $(get_test_count 0011) - tests empty directories"
+       echo "0012 x $(get_test_count 0012) - tests range check for u8 proc_handler"
 }
 
 usage()