diff options
| author | Luis R. Rodriguez <mcgrof@kernel.org> | 2017-07-12 17:33:52 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-12 19:26:00 -0400 |
| commit | eb965eda1cabf26e62afc07a06cdf2fd5aaa2906 (patch) | |
| tree | b5b38008a45447eefe8450f73de0b441dce11f70 | |
| parent | 1c0357c846452add7c2c863ec372010e3d2ca943 (diff) | |
test_sysctl: add simple proc_dointvec() case
Test against a simple proc_dointvec() case. While at it, add a test
against INT_MAX. Make sure INT_MAX works, and INT_MAX+1 will fail.
Also test negative values work.
Link: http://lkml.kernel.org/r/20170630224431.17374-5-mcgrof@kernel.org
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | lib/test_sysctl.c | 11 | ||||
| -rw-r--r-- | tools/testing/selftests/sysctl/sysctl.sh | 62 |
2 files changed, 73 insertions, 0 deletions
diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index b2163bfb6eb2..1472e1ae4931 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c | |||
| @@ -41,11 +41,15 @@ static int i_one_hundred = 100; | |||
| 41 | 41 | ||
| 42 | struct test_sysctl_data { | 42 | struct test_sysctl_data { |
| 43 | int int_0001; | 43 | int int_0001; |
| 44 | int int_0002; | ||
| 45 | |||
| 44 | char string_0001[65]; | 46 | char string_0001[65]; |
| 45 | }; | 47 | }; |
| 46 | 48 | ||
| 47 | static struct test_sysctl_data test_data = { | 49 | static struct test_sysctl_data test_data = { |
| 48 | .int_0001 = 60, | 50 | .int_0001 = 60, |
| 51 | .int_0002 = 1, | ||
| 52 | |||
| 49 | .string_0001 = "(none)", | 53 | .string_0001 = "(none)", |
| 50 | }; | 54 | }; |
| 51 | 55 | ||
| @@ -61,6 +65,13 @@ static struct ctl_table test_table[] = { | |||
| 61 | .extra2 = &i_one_hundred, | 65 | .extra2 = &i_one_hundred, |
| 62 | }, | 66 | }, |
| 63 | { | 67 | { |
| 68 | .procname = "int_0002", | ||
| 69 | .data = &test_data.int_0002, | ||
| 70 | .maxlen = sizeof(int), | ||
| 71 | .mode = 0644, | ||
| 72 | .proc_handler = proc_dointvec, | ||
| 73 | }, | ||
| 74 | { | ||
| 64 | .procname = "string_0001", | 75 | .procname = "string_0001", |
| 65 | .data = &test_data.string_0001, | 76 | .data = &test_data.string_0001, |
| 66 | .maxlen = sizeof(test_data.string_0001), | 77 | .maxlen = sizeof(test_data.string_0001), |
diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index 6ec807576f7c..7ba3fa2bbd54 100644 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh | |||
| @@ -31,6 +31,7 @@ TEST_FILE=$(mktemp) | |||
| 31 | # we have tons of space. | 31 | # we have tons of space. |
| 32 | ALL_TESTS="0001:1:1" | 32 | ALL_TESTS="0001:1:1" |
| 33 | ALL_TESTS="$ALL_TESTS 0002:1:1" | 33 | ALL_TESTS="$ALL_TESTS 0002:1:1" |
| 34 | ALL_TESTS="$ALL_TESTS 0003:1:1" | ||
| 34 | 35 | ||
| 35 | test_modprobe() | 36 | test_modprobe() |
| 36 | { | 37 | { |
| @@ -82,6 +83,9 @@ function check_production_sysctl_writes_strict() | |||
| 82 | if [ -z $MAX_DIGITS ]; then | 83 | if [ -z $MAX_DIGITS ]; then |
| 83 | MAX_DIGITS=$(($PAGE_SIZE/8)) | 84 | MAX_DIGITS=$(($PAGE_SIZE/8)) |
| 84 | fi | 85 | fi |
| 86 | if [ -z $INT_MAX ]; then | ||
| 87 | INT_MAX=$(getconf INT_MAX) | ||
| 88 | fi | ||
| 85 | } | 89 | } |
| 86 | 90 | ||
| 87 | test_reqs() | 91 | test_reqs() |
| @@ -122,6 +126,9 @@ reset_vals() | |||
| 122 | int_0001) | 126 | int_0001) |
| 123 | VAL="60" | 127 | VAL="60" |
| 124 | ;; | 128 | ;; |
| 129 | int_0002) | ||
| 130 | VAL="1" | ||
| 131 | ;; | ||
| 125 | string_0001) | 132 | string_0001) |
| 126 | VAL="(none)" | 133 | VAL="(none)" |
| 127 | ;; | 134 | ;; |
| @@ -296,6 +303,48 @@ run_limit_digit() | |||
| 296 | test_rc | 303 | test_rc |
| 297 | } | 304 | } |
| 298 | 305 | ||
| 306 | # You are using an int | ||
| 307 | run_limit_digit_int() | ||
| 308 | { | ||
| 309 | echo -n "Testing INT_MAX works ..." | ||
| 310 | reset_vals | ||
| 311 | TEST_STR="$INT_MAX" | ||
| 312 | echo -n $TEST_STR > $TARGET | ||
| 313 | |||
| 314 | if ! verify "${TARGET}"; then | ||
| 315 | echo "FAIL" >&2 | ||
| 316 | rc=1 | ||
| 317 | else | ||
| 318 | echo "ok" | ||
| 319 | fi | ||
| 320 | test_rc | ||
| 321 | |||
| 322 | echo -n "Testing INT_MAX + 1 will fail as expected..." | ||
| 323 | reset_vals | ||
| 324 | let TEST_STR=$INT_MAX+1 | ||
| 325 | echo -n $TEST_STR > $TARGET 2> /dev/null | ||
| 326 | |||
| 327 | if verify "${TARGET}"; then | ||
| 328 | echo "FAIL" >&2 | ||
| 329 | rc=1 | ||
| 330 | else | ||
| 331 | echo "ok" | ||
| 332 | fi | ||
| 333 | test_rc | ||
| 334 | |||
| 335 | echo -n "Testing negative values will work as expected..." | ||
| 336 | reset_vals | ||
| 337 | TEST_STR="-3" | ||
| 338 | echo -n $TEST_STR > $TARGET 2> /dev/null | ||
| 339 | if ! verify "${TARGET}"; then | ||
| 340 | echo "FAIL" >&2 | ||
| 341 | rc=1 | ||
| 342 | else | ||
| 343 | echo "ok" | ||
| 344 | fi | ||
| 345 | test_rc | ||
| 346 | } | ||
| 347 | |||
| 299 | run_stringtests() | 348 | run_stringtests() |
| 300 | { | 349 | { |
| 301 | echo -n "Writing entire sysctl in short writes ... " | 350 | echo -n "Writing entire sysctl in short writes ... " |
| @@ -389,6 +438,18 @@ sysctl_test_0002() | |||
| 389 | run_stringtests | 438 | run_stringtests |
| 390 | } | 439 | } |
| 391 | 440 | ||
| 441 | sysctl_test_0003() | ||
| 442 | { | ||
| 443 | TARGET="${SYSCTL}/int_0002" | ||
| 444 | reset_vals | ||
| 445 | ORIG=$(cat "${TARGET}") | ||
| 446 | TEST_STR=$(( $ORIG + 1 )) | ||
| 447 | |||
| 448 | run_numerictests | ||
| 449 | run_limit_digit | ||
| 450 | run_limit_digit_int | ||
| 451 | } | ||
| 452 | |||
| 392 | list_tests() | 453 | list_tests() |
| 393 | { | 454 | { |
| 394 | echo "Test ID list:" | 455 | echo "Test ID list:" |
| @@ -399,6 +460,7 @@ list_tests() | |||
| 399 | echo | 460 | echo |
| 400 | echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()" | 461 | echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()" |
| 401 | echo "0002 x $(get_test_count 0002) - tests proc_dostring()" | 462 | echo "0002 x $(get_test_count 0002) - tests proc_dostring()" |
| 463 | echo "0003 x $(get_test_count 0003) - tests proc_dointvec()" | ||
| 402 | } | 464 | } |
| 403 | 465 | ||
| 404 | test_reqs | 466 | test_reqs |
