tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 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 robust and compatible with older kernels by checking and update sysctrl_writes_strict value and restore it when test is done.
--- tools/testing/selftests/sysctl/common_tests | 14 ++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 3 +++ tools/testing/selftests/sysctl/run_stringtests | 3 +++ 3 files changed, 20 insertions(+)
(quoted diff) +0 -0
b/tools/testing/selftests/sysctl/common_tests
index 17d534b1b7b4..f5c5c51d16f3 100644
tools/testing/selftests/sysctl/common_tests +14 -0
@@ -63,6 +63,20 @@ else echo "ok" fi +echo -n "Checking writes 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 + val=$(cat ${WRITES_STRICT}) + if [ "$val" = "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.
(quoted diff) +0 -0
b/tools/testing/selftests/sysctl/run_numerictests
index 8510f93f2d14..c0a98fd82c5c 100755
tools/testing/selftests/sysctl/run_numerictests +3 -0
@@ -7,4 +7,7 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rc
(quoted diff) +0 -0
b/tools/testing/selftests/sysctl/run_stringtests
index 90a9293d520c..ae98d66a9ec6 100755
tools/testing/selftests/sysctl/run_stringtests +3 -0
@@ -74,4 +74,7 @@ else echo "ok" fi +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rc
--
2.12.2
Hi Orson,
Thanks for the patch.
Quoted 7 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 robust and compatible with older kernels by checking and update
sysctrl_writes_strictvalue and restore it when test is done.Signed-off-by Orson Zhai <[email protected]>
Please feel free to add my
Quoted 59 lines
--- tools/testing/selftests/sysctl/common_tests | 14 ++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 3 +++ tools/testing/selftests/sysctl/run_stringtests | 3 +++ 3 files changed, 20 insertions(+)tools/testing/selftests/sysctl/common_tests +14
-0@@ -63,6 +63,20 @@ else echo "ok" fi +echo -n "Checking writes 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 + val=$(cat ${WRITES_STRICT}) + if [ "$val" = "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 +3
-0@@ -7,4 +7,7 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rctools/testing/selftests/sysctl/run_stringtests +3
-1@@ -74,4 +74,7 @@ else echo "ok" fi +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rc --
Quoted 1 line
2.12.2
Best,
Sumit.
Quoted 11 lines · Sumit Semwal
Hi Orson,
Thanks for the patch.
Quoted 6 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 robust and compatible with older kernels by checking and update
sysctrl_writes_strictvalue and restore it when test is done.
Quoted 6 lines
Quoted 1 line
Signed-off-by Orson Zhai <[email protected]>Please feel free to add my
Reviewed-by Sumit Semwal <[email protected]>Tested-by Sumit Semwal <[email protected]>[sumits: tested LTS-4.4 with hikey (arm64) ]
Sure. I will add them to my patch V2.
Thanks,
Orson
Quoted 65 lines
Quoted 60 lines
--- tools/testing/selftests/sysctl/common_tests | 14 ++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 3 +++ tools/testing/selftests/sysctl/run_stringtests | 3 +++ 3 files changed, 20 insertions(+)tools/testing/selftests/sysctl/common_tests +14
-0@@ -63,6 +63,20 @@ else echo "ok" fi +echo -n "Checking writes 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 + val=$(cat ${WRITES_STRICT}) + if [ "$val" = "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 +3
-0@@ -7,4 +7,7 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rctools/testing/selftests/sysctl/run_stringtests +3
-1@@ -74,4 +74,7 @@ else echo "ok" fi +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rc --Quoted 1 line
2.12.2
Best,
Sumit.
Quoted 19 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 robust and compatible with older kernels by checking and update
sysctrl_writes_strictvalue and restore it when test is done.Signed-off-by Orson Zhai <[email protected]>--- tools/testing/selftests/sysctl/common_tests | 14 ++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 3 +++ tools/testing/selftests/sysctl/run_stringtests | 3 +++ 3 files changed, 20 insertions(+)tools/testing/selftests/sysctl/common_tests +0
-0
tools/testing/selftests/sysctl/common_tests else · line 71
Quoted 9 lines
tools/testing/selftests/sysctl/common_tests +6
-0@@ -63,6 +63,20 @@ else echo "ok" fi +echo -n "Checking writes 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 + val=$(cat ${WRITES_STRICT})
Can you give this a more meaningful name instead of "val". Perhaps "old_strict"?
Quoted 30 lines
tools/testing/selftests/sysctl/common_tests +8
-0+ if [ "$val" = "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 +3
-0@@ -7,4 +7,7 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rctools/testing/selftests/sysctl/run_stringtests +0
-0
tools/testing/selftests/sysctl/run_stringtests else · line 80
Quoted 7 lines
tools/testing/selftests/sysctl/run_stringtests +3
-0@@ -74,4 +74,7 @@ else echo "ok" fi +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rc
And instead of open-coding these, can you instead add an "exit_test" function to common_tests, which will do this and the exit $rc?
-Kees
Signature · 2 lines
Kees Cook Pixel Security
Hi Kees,
Thanks for reviewing.
I will update in V1 soon.
Br,
Orson
Quoted 78 lines · Kees Cook
Quoted 19 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 robust and compatible with older kernels by checking and update
sysctrl_writes_strictvalue and restore it when test is done.Signed-off-by Orson Zhai <[email protected]>--- tools/testing/selftests/sysctl/common_tests | 14 ++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 3 +++ tools/testing/selftests/sysctl/run_stringtests | 3 +++ 3 files changed, 20 insertions(+)tools/testing/selftests/sysctl/common_tests +0
-0tools/testing/selftests/sysctl/common_tests else · line 71
Quoted 9 lines
tools/testing/selftests/sysctl/common_tests +6
-0@@ -63,6 +63,20 @@ else echo "ok" fi +echo -n "Checking writes 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 + val=$(cat ${WRITES_STRICT})Can you give this a more meaningful name instead of "val". Perhaps "
old_strict"?Quoted 30 lines
tools/testing/selftests/sysctl/common_tests +8
-0+ if [ "$val" = "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 +3
-0@@ -7,4 +7,7 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rctools/testing/selftests/sysctl/run_stringtests +0
-0tools/testing/selftests/sysctl/run_stringtests else · line 80
Quoted 7 lines
tools/testing/selftests/sysctl/run_stringtests +3
-0@@ -74,4 +74,7 @@ else echo "ok" fi +if [ ! -z ${val} ]; then + echo ${val} > ${WRITES_STRICT} +fi exit $rcAnd instead of open-coding these, can you instead add an "
exit_test" function tocommon_tests, which will do this and the exit $rc?-Kees
--
Kees Cook
Pixel Security