diff options
author | Luis R. Rodriguez <mcgrof@kernel.org> | 2017-07-12 17:33:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-12 19:26:00 -0400 |
commit | 2920fad3a5d394b66011c7f35c7b05278354055e (patch) | |
tree | 70e445d6cffd910679f1349d64f683cc01f3839e | |
parent | eb965eda1cabf26e62afc07a06cdf2fd5aaa2906 (diff) |
test_sysctl: add simple proc_douintvec() case
Test against a simple proc_douintvec() case. While at it, add a test
against UINT_MAX. Make sure UINT_MAX works, and UINT_MAX+1 will fail
and that negative values are not accepted.
Link: http://lkml.kernel.org/r/20170630224431.17374-6-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 | 63 |
2 files changed, 74 insertions, 0 deletions
diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index 1472e1ae4931..53db3513ab08 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c | |||
@@ -43,6 +43,8 @@ struct test_sysctl_data { | |||
43 | int int_0001; | 43 | int int_0001; |
44 | int int_0002; | 44 | int int_0002; |
45 | 45 | ||
46 | unsigned int uint_0001; | ||
47 | |||
46 | char string_0001[65]; | 48 | char string_0001[65]; |
47 | }; | 49 | }; |
48 | 50 | ||
@@ -50,6 +52,8 @@ static struct test_sysctl_data test_data = { | |||
50 | .int_0001 = 60, | 52 | .int_0001 = 60, |
51 | .int_0002 = 1, | 53 | .int_0002 = 1, |
52 | 54 | ||
55 | .uint_0001 = 314, | ||
56 | |||
53 | .string_0001 = "(none)", | 57 | .string_0001 = "(none)", |
54 | }; | 58 | }; |
55 | 59 | ||
@@ -72,6 +76,13 @@ static struct ctl_table test_table[] = { | |||
72 | .proc_handler = proc_dointvec, | 76 | .proc_handler = proc_dointvec, |
73 | }, | 77 | }, |
74 | { | 78 | { |
79 | .procname = "uint_0001", | ||
80 | .data = &test_data.uint_0001, | ||
81 | .maxlen = sizeof(unsigned int), | ||
82 | .mode = 0644, | ||
83 | .proc_handler = proc_douintvec, | ||
84 | }, | ||
85 | { | ||
75 | .procname = "string_0001", | 86 | .procname = "string_0001", |
76 | .data = &test_data.string_0001, | 87 | .data = &test_data.string_0001, |
77 | .maxlen = sizeof(test_data.string_0001), | 88 | .maxlen = sizeof(test_data.string_0001), |
diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index 7ba3fa2bbd54..abeef675a884 100644 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh | |||
@@ -32,6 +32,7 @@ TEST_FILE=$(mktemp) | |||
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 | ALL_TESTS="$ALL_TESTS 0003:1:1" |
35 | ALL_TESTS="$ALL_TESTS 0004:1:1" | ||
35 | 36 | ||
36 | test_modprobe() | 37 | test_modprobe() |
37 | { | 38 | { |
@@ -86,6 +87,9 @@ function check_production_sysctl_writes_strict() | |||
86 | if [ -z $INT_MAX ]; then | 87 | if [ -z $INT_MAX ]; then |
87 | INT_MAX=$(getconf INT_MAX) | 88 | INT_MAX=$(getconf INT_MAX) |
88 | fi | 89 | fi |
90 | if [ -z $UINT_MAX ]; then | ||
91 | UINT_MAX=$(getconf UINT_MAX) | ||
92 | fi | ||
89 | } | 93 | } |
90 | 94 | ||
91 | test_reqs() | 95 | test_reqs() |
@@ -129,6 +133,9 @@ reset_vals() | |||
129 | int_0002) | 133 | int_0002) |
130 | VAL="1" | 134 | VAL="1" |
131 | ;; | 135 | ;; |
136 | uint_0001) | ||
137 | VAL="314" | ||
138 | ;; | ||
132 | string_0001) | 139 | string_0001) |
133 | VAL="(none)" | 140 | VAL="(none)" |
134 | ;; | 141 | ;; |
@@ -345,6 +352,49 @@ run_limit_digit_int() | |||
345 | test_rc | 352 | test_rc |
346 | } | 353 | } |
347 | 354 | ||
355 | # You are using an unsigned int | ||
356 | run_limit_digit_uint() | ||
357 | { | ||
358 | echo -n "Testing UINT_MAX works ..." | ||
359 | reset_vals | ||
360 | TEST_STR="$UINT_MAX" | ||
361 | echo -n $TEST_STR > $TARGET | ||
362 | |||
363 | if ! verify "${TARGET}"; then | ||
364 | echo "FAIL" >&2 | ||
365 | rc=1 | ||
366 | else | ||
367 | echo "ok" | ||
368 | fi | ||
369 | test_rc | ||
370 | |||
371 | echo -n "Testing UINT_MAX + 1 will fail as expected..." | ||
372 | reset_vals | ||
373 | TEST_STR=$(($UINT_MAX+1)) | ||
374 | echo -n $TEST_STR > $TARGET 2> /dev/null | ||
375 | |||
376 | if verify "${TARGET}"; then | ||
377 | echo "FAIL" >&2 | ||
378 | rc=1 | ||
379 | else | ||
380 | echo "ok" | ||
381 | fi | ||
382 | test_rc | ||
383 | |||
384 | echo -n "Testing negative values will not work as expected ..." | ||
385 | reset_vals | ||
386 | TEST_STR="-3" | ||
387 | echo -n $TEST_STR > $TARGET 2> /dev/null | ||
388 | |||
389 | if verify "${TARGET}"; then | ||
390 | echo "FAIL" >&2 | ||
391 | rc=1 | ||
392 | else | ||
393 | echo "ok" | ||
394 | fi | ||
395 | test_rc | ||
396 | } | ||
397 | |||
348 | run_stringtests() | 398 | run_stringtests() |
349 | { | 399 | { |
350 | echo -n "Writing entire sysctl in short writes ... " | 400 | echo -n "Writing entire sysctl in short writes ... " |
@@ -450,6 +500,18 @@ sysctl_test_0003() | |||
450 | run_limit_digit_int | 500 | run_limit_digit_int |
451 | } | 501 | } |
452 | 502 | ||
503 | sysctl_test_0004() | ||
504 | { | ||
505 | TARGET="${SYSCTL}/uint_0001" | ||
506 | reset_vals | ||
507 | ORIG=$(cat "${TARGET}") | ||
508 | TEST_STR=$(( $ORIG + 1 )) | ||
509 | |||
510 | run_numerictests | ||
511 | run_limit_digit | ||
512 | run_limit_digit_uint | ||
513 | } | ||
514 | |||
453 | list_tests() | 515 | list_tests() |
454 | { | 516 | { |
455 | echo "Test ID list:" | 517 | echo "Test ID list:" |
@@ -461,6 +523,7 @@ list_tests() | |||
461 | echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()" | 523 | echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()" |
462 | echo "0002 x $(get_test_count 0002) - tests proc_dostring()" | 524 | echo "0002 x $(get_test_count 0002) - tests proc_dostring()" |
463 | echo "0003 x $(get_test_count 0003) - tests proc_dointvec()" | 525 | echo "0003 x $(get_test_count 0003) - tests proc_dointvec()" |
526 | echo "0004 x $(get_test_count 0004) - tests proc_douintvec()" | ||
464 | } | 527 | } |
465 | 528 | ||
466 | test_reqs | 529 | test_reqs |