tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
Subsystems (2)
PATCH v4 1/1 tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
Sysctl test will fail in some items if the value of /proc/sys/kernel /sysctrl_writes_strict is 0 as the default value in kernel older than v4.5.
Make this test more robus and compatible with older kernel by checking and update writes_strict value and restore it when test is done.
--- tools/testing/selftests/sysctl/common_tests | 22 ++++++++++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 2 +- tools/testing/selftests/sysctl/run_stringtests | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-)
tools/testing/selftests/sysctl/common_tests +22 -0
@@ -24,6 +24,14 @@ verify() return 0 } +exit_test() +{ + if [ ! -z ${old_strict} ]; then + echo ${old_strict} > ${WRITES_STRICT} + fi + exit $rc +} + trap 'set_orig; rm -f "${TEST_FILE}"' EXIT rc=0
@@ -63,6 +71,20 @@ else echo "ok" fi +echo -n "Checking write strict setting ... " +WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict" +if [ ! -e ${WRITES_STRICT} ]; then + echo "FAIL, but skip in case of old kernel" >&2 +else + old_strict=$(cat ${WRITES_STRICT}) + if [ "$old_strict" = "1" ]; then + echo "ok" + else + echo "FAIL, strict value is 0 but force to 1 to continue" >&2 + echo "1" > ${WRITES_STRICT} + fi +fi + # Now that we've validated the sanity of "set_test" and "set_orig", # we can use those functions to set starting states before running # specific behavioral tests.
tools/testing/selftests/sysctl/run_numerictests +1 -1
@@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests -exit $rc +exit_test
tools/testing/selftests/sysctl/run_stringtests +1 -1
@@ -74,4 +74,4 @@ else echo "ok" fi -exit $rc +exit_test
Signature · 1 line
2.12.2
Quoted 9 lines · Orson Zhai
Sysctl test will fail in some items if the value of
/proc/sys/kernel/sysctrl_writes_strict is 0 as the default value in kernel older than v4.5.Make this test more robus and compatible with older kernel by checking and update
writes_strictvalue and restore it when test is done.Signed-off-by Orson Zhai <[email protected]>Reviewed-by Sumit Semwal <[email protected]>Tested-by Sumit Semwal <[email protected]>
Thanks!
-Kees
Quoted 69 lines
--- tools/testing/selftests/sysctl/common_tests | 22 ++++++++++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 2 +- tools/testing/selftests/sysctl/run_stringtests | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-)tools/testing/selftests/sysctl/common_tests +22
-0@@ -24,6 +24,14 @@ verify() return 0 } +exit_test() +{ + if [ ! -z ${old_strict} ]; then + echo ${old_strict} > ${WRITES_STRICT} + fi + exit $rc +} + trap 'set_orig; rm -f "${TEST_FILE}"' EXIT rc=0@@ -63,6 +71,20 @@ else echo "ok" fi +echo -n "Checking write strict setting ... " +WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict" +if [ ! -e ${WRITES_STRICT} ]; then + echo "FAIL, but skip in case of old kernel" >&2 +else + old_strict=$(cat ${WRITES_STRICT}) + if [ "$old_strict" = "1" ]; then + echo "ok" + else + echo "FAIL, strict value is 0 but force to 1 to continue" >&2 + echo "1" > ${WRITES_STRICT} + fi +fi + # Now that we've validated the sanity of "set_test" and "set_orig", # we can use those functions to set starting states before running # specific behavioral tests.tools/testing/selftests/sysctl/run_numerictests +1
-1@@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests -exit $rc +exit_testtools/testing/selftests/sysctl/run_stringtests +1
-2@@ -74,4 +74,4 @@ else echo "ok" fi -exit $rc +exit_test --2.12.2
Signature · 2 lines
Kees Cook Pixel Security
Shuah Khan
maintainerQuoted 11 lines · Kees Cook
Quoted 9 lines · Orson Zhai
Sysctl test will fail in some items if the value of
/proc/sys/kernel/sysctrl_writes_strict is 0 as the default value in kernel older than v4.5.Make this test more robus and compatible with older kernel by checking and update
writes_strictvalue and restore it when test is done.Signed-off-by Orson Zhai <[email protected]>Reviewed-by Sumit Semwal <[email protected]>Tested-by Sumit Semwal <[email protected]>
Quoted 6 lines
Reviewed-by Kees Cook <[email protected]>Thanks!
-Kees
Thanks. Applied to linux-kselftest next for 4.13-rc1
thanks,
-- Shuah
Quoted 72 lines
Quoted 69 lines
--- tools/testing/selftests/sysctl/common_tests | 22 ++++++++++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 2 +- tools/testing/selftests/sysctl/run_stringtests | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-)tools/testing/selftests/sysctl/common_tests +22
-0@@ -24,6 +24,14 @@ verify() return 0 } +exit_test() +{ + if [ ! -z ${old_strict} ]; then + echo ${old_strict} > ${WRITES_STRICT} + fi + exit $rc +} + trap 'set_orig; rm -f "${TEST_FILE}"' EXIT rc=0@@ -63,6 +71,20 @@ else echo "ok" fi +echo -n "Checking write strict setting ... " +WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict" +if [ ! -e ${WRITES_STRICT} ]; then + echo "FAIL, but skip in case of old kernel" >&2 +else + old_strict=$(cat ${WRITES_STRICT}) + if [ "$old_strict" = "1" ]; then + echo "ok" + else + echo "FAIL, strict value is 0 but force to 1 to continue" >&2 + echo "1" > ${WRITES_STRICT} + fi +fi + # Now that we've validated the sanity of "set_test" and "set_orig", # we can use those functions to set starting states before running # specific behavioral tests.tools/testing/selftests/sysctl/run_numerictests +1
-1@@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests -exit $rc +exit_testtools/testing/selftests/sysctl/run_stringtests +1
-2@@ -74,4 +74,4 @@ else echo "ok" fi -exit $rc +exit_test --2.12.2