mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V4] tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
@ 2017-06-27  0:52 Orson Zhai
  2017-06-27  3:24 ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Orson Zhai @ 2017-06-27  0:52 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Sumit Semwal, linux-kselftest, linux-kernel, keescook, 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_strict value and restore it when test is done.

Signed-off-by: Orson Zhai <orson.zhai@linaro.org>
Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org>
Tested-by: Sumit Semwal <sumit.semwal@linaro.org>
---
 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(-)

diff --git a/tools/testing/selftests/sysctl/common_tests b/tools/testing/selftests/sysctl/common_tests
index 17d534b1b7b4..b6862322962f 100644
--- a/tools/testing/selftests/sysctl/common_tests
+++ b/tools/testing/selftests/sysctl/common_tests
@@ -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.
diff --git a/tools/testing/selftests/sysctl/run_numerictests b/tools/testing/selftests/sysctl/run_numerictests
index 8510f93f2d14..e6e76c93d948 100755
--- a/tools/testing/selftests/sysctl/run_numerictests
+++ b/tools/testing/selftests/sysctl/run_numerictests
@@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 ))
 
 . ./common_tests
 
-exit $rc
+exit_test
diff --git a/tools/testing/selftests/sysctl/run_stringtests b/tools/testing/selftests/sysctl/run_stringtests
index 90a9293d520c..857ec667fb02 100755
--- a/tools/testing/selftests/sysctl/run_stringtests
+++ b/tools/testing/selftests/sysctl/run_stringtests
@@ -74,4 +74,4 @@ else
 	echo "ok"
 fi
 
-exit $rc
+exit_test
-- 
2.12.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V4] tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
  2017-06-27  0:52 [PATCH V4] tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict Orson Zhai
@ 2017-06-27  3:24 ` Kees Cook
  2017-06-28 14:01   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2017-06-27  3:24 UTC (permalink / raw)
  To: Orson Zhai
  Cc: Shuah Khan, Sumit Semwal, open list:KERNEL SELFTEST FRAMEWORK, LKML

On Mon, Jun 26, 2017 at 5:52 PM, Orson Zhai <orson.zhai@linaro.org> wrote:
> 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.
>
> Signed-off-by: Orson Zhai <orson.zhai@linaro.org>
> Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org>
> Tested-by: Sumit Semwal <sumit.semwal@linaro.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

Thanks!

-Kees

> ---
>  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(-)
>
> diff --git a/tools/testing/selftests/sysctl/common_tests b/tools/testing/selftests/sysctl/common_tests
> index 17d534b1b7b4..b6862322962f 100644
> --- a/tools/testing/selftests/sysctl/common_tests
> +++ b/tools/testing/selftests/sysctl/common_tests
> @@ -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.
> diff --git a/tools/testing/selftests/sysctl/run_numerictests b/tools/testing/selftests/sysctl/run_numerictests
> index 8510f93f2d14..e6e76c93d948 100755
> --- a/tools/testing/selftests/sysctl/run_numerictests
> +++ b/tools/testing/selftests/sysctl/run_numerictests
> @@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 ))
>
>  . ./common_tests
>
> -exit $rc
> +exit_test
> diff --git a/tools/testing/selftests/sysctl/run_stringtests b/tools/testing/selftests/sysctl/run_stringtests
> index 90a9293d520c..857ec667fb02 100755
> --- a/tools/testing/selftests/sysctl/run_stringtests
> +++ b/tools/testing/selftests/sysctl/run_stringtests
> @@ -74,4 +74,4 @@ else
>         echo "ok"
>  fi
>
> -exit $rc
> +exit_test
> --
> 2.12.2
>



-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V4] tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
  2017-06-27  3:24 ` Kees Cook
@ 2017-06-28 14:01   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2017-06-28 14:01 UTC (permalink / raw)
  To: Kees Cook, Orson Zhai
  Cc: Sumit Semwal, open list:KERNEL SELFTEST FRAMEWORK, LKML, Shuah Khan

On 06/26/2017 09:24 PM, Kees Cook wrote:
> On Mon, Jun 26, 2017 at 5:52 PM, Orson Zhai <orson.zhai@linaro.org> wrote:
>> 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.
>>
>> Signed-off-by: Orson Zhai <orson.zhai@linaro.org>
>> Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org>
>> Tested-by: Sumit Semwal <sumit.semwal@linaro.org>
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>
> 
> Thanks!
> 
> -Kees
> 

Thanks. Applied to linux-kselftest next for 4.13-rc1

thanks,
-- Shuah

>> ---
>>  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(-)
>>
>> diff --git a/tools/testing/selftests/sysctl/common_tests b/tools/testing/selftests/sysctl/common_tests
>> index 17d534b1b7b4..b6862322962f 100644
>> --- a/tools/testing/selftests/sysctl/common_tests
>> +++ b/tools/testing/selftests/sysctl/common_tests
>> @@ -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.
>> diff --git a/tools/testing/selftests/sysctl/run_numerictests b/tools/testing/selftests/sysctl/run_numerictests
>> index 8510f93f2d14..e6e76c93d948 100755
>> --- a/tools/testing/selftests/sysctl/run_numerictests
>> +++ b/tools/testing/selftests/sysctl/run_numerictests
>> @@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 ))
>>
>>  . ./common_tests
>>
>> -exit $rc
>> +exit_test
>> diff --git a/tools/testing/selftests/sysctl/run_stringtests b/tools/testing/selftests/sysctl/run_stringtests
>> index 90a9293d520c..857ec667fb02 100755
>> --- a/tools/testing/selftests/sysctl/run_stringtests
>> +++ b/tools/testing/selftests/sysctl/run_stringtests
>> @@ -74,4 +74,4 @@ else
>>         echo "ok"
>>  fi
>>
>> -exit $rc
>> +exit_test
>> --
>> 2.12.2
>>
> 
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-28 14:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27  0:52 [PATCH V4] tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict Orson Zhai
2017-06-27  3:24 ` Kees Cook
2017-06-28 14:01   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®