From: Joel Granados <joel.granados@kernel.org>
To: Kees Cook <kees@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>,
John Sperbeck <jsperbeck@google.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Joel Granados <joel.granados@kernel.org>
Subject: [PATCH 2/4] sysctl: Add 0012 to test the u8 range check
Date: Fri, 21 Mar 2025 13:47:25 +0100 [thread overview]
Message-ID: <20250321-jag-test_extra_val-v1-2-a01b3b17dc66@kernel.org> (raw)
In-Reply-To: <20250321-jag-test_extra_val-v1-0-a01b3b17dc66@kernel.org>
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.
Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
tools/testing/selftests/sysctl/sysctl.sh | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
index 84472b436c07faf43e555999951e554f8e1a60c5..22b53c263dd4525ee8d4655272d6842e5249a7dc 100755
--- a/tools/testing/selftests/sysctl/sysctl.sh
+++ b/tools/testing/selftests/sysctl/sysctl.sh
@@ -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()
--
2.47.2
next prev parent reply other threads:[~2025-03-21 12:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 12:47 [PATCH 0/4] sysctl: Move the u8 range check test to lib/test_sysctl.c Joel Granados
2025-03-21 12:47 ` [PATCH 1/4] sysctl: move u8 register " Joel Granados
2025-04-09 17:26 ` Kees Cook
2025-04-11 12:37 ` Joel Granados
2025-03-21 12:47 ` Joel Granados [this message]
2025-04-09 17:27 ` [PATCH 2/4] sysctl: Add 0012 to test the u8 range check Kees Cook
2025-03-21 12:47 ` [PATCH 3/4] sysctl: call sysctl tests with a for loop Joel Granados
2025-04-09 17:28 ` Kees Cook
2025-03-21 12:47 ` [PATCH 4/4] sysctl: Close test ctl_headers " Joel Granados
2025-04-09 17:29 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250321-jag-test_extra_val-v1-2-a01b3b17dc66@kernel.org \
--to=joel.granados@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jsperbeck@google.com \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox