* [PATCH v2] selftests: livepatch: Fix it to do root uid check and skip
@ 2019-12-16 19:18 Shuah Khan
2019-12-16 21:01 ` Joe Lawrence
2019-12-17 9:02 ` Petr Mladek
0 siblings, 2 replies; 4+ messages in thread
From: Shuah Khan @ 2019-12-16 19:18 UTC (permalink / raw)
To: jpoimboe, jikos, mbenes, pmladek, joe.lawrence, shuah
Cc: Shuah Khan, live-patching, linux-kselftest, linux-kernel
livepatch test configures the system and debug environment to run
tests. Some of these actions fail without root access and test
dumps several permission denied messages before it exits.
Fix test-state.sh to call setup_config instead of set_dynamic_debug
as suggested by Petr Mladek <pmladek@suse.com>
Fix it to check root uid and exit with skip code instead.
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
tools/testing/selftests/livepatch/functions.sh | 15 ++++++++++++++-
tools/testing/selftests/livepatch/test-state.sh | 3 +--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index 31eb09e38729..a6e3d5517a6f 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -7,6 +7,9 @@
MAX_RETRIES=600
RETRY_INTERVAL=".1" # seconds
+# Kselftest framework requirement - SKIP code is 4
+ksft_skip=4
+
# log(msg) - write message to kernel log
# msg - insightful words
function log() {
@@ -18,7 +21,16 @@ function log() {
function skip() {
log "SKIP: $1"
echo "SKIP: $1" >&2
- exit 4
+ exit $ksft_skip
+}
+
+# root test
+function is_root() {
+ uid=$(id -u)
+ if [ $uid -ne 0 ]; then
+ echo "skip all tests: must be run as root" >&2
+ exit $ksft_skip
+ fi
}
# die(msg) - game over, man
@@ -62,6 +74,7 @@ function set_ftrace_enabled() {
# for verbose livepatching output and turn on
# the ftrace_enabled sysctl.
function setup_config() {
+ is_root
push_config
set_dynamic_debug
set_ftrace_enabled 1
diff --git a/tools/testing/selftests/livepatch/test-state.sh b/tools/testing/selftests/livepatch/test-state.sh
index dc2908c22c26..a08212708115 100755
--- a/tools/testing/selftests/livepatch/test-state.sh
+++ b/tools/testing/selftests/livepatch/test-state.sh
@@ -8,8 +8,7 @@ MOD_LIVEPATCH=test_klp_state
MOD_LIVEPATCH2=test_klp_state2
MOD_LIVEPATCH3=test_klp_state3
-set_dynamic_debug
-
+setup_config
# TEST: Loading and removing a module that modifies the system state
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftests: livepatch: Fix it to do root uid check and skip
2019-12-16 19:18 [PATCH v2] selftests: livepatch: Fix it to do root uid check and skip Shuah Khan
@ 2019-12-16 21:01 ` Joe Lawrence
2019-12-17 9:02 ` Petr Mladek
1 sibling, 0 replies; 4+ messages in thread
From: Joe Lawrence @ 2019-12-16 21:01 UTC (permalink / raw)
To: Shuah Khan
Cc: jpoimboe, jikos, mbenes, pmladek, shuah, live-patching,
linux-kselftest, linux-kernel
On Mon, Dec 16, 2019 at 12:18:40PM -0700, Shuah Khan wrote:
> livepatch test configures the system and debug environment to run
> tests. Some of these actions fail without root access and test
> dumps several permission denied messages before it exits.
>
> Fix test-state.sh to call setup_config instead of set_dynamic_debug
> as suggested by Petr Mladek <pmladek@suse.com>
>
> Fix it to check root uid and exit with skip code instead.
>
> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
> ---
> tools/testing/selftests/livepatch/functions.sh | 15 ++++++++++++++-
> tools/testing/selftests/livepatch/test-state.sh | 3 +--
> 2 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
> index 31eb09e38729..a6e3d5517a6f 100644
> --- a/tools/testing/selftests/livepatch/functions.sh
> +++ b/tools/testing/selftests/livepatch/functions.sh
> @@ -7,6 +7,9 @@
> MAX_RETRIES=600
> RETRY_INTERVAL=".1" # seconds
>
> +# Kselftest framework requirement - SKIP code is 4
> +ksft_skip=4
> +
> # log(msg) - write message to kernel log
> # msg - insightful words
> function log() {
> @@ -18,7 +21,16 @@ function log() {
> function skip() {
> log "SKIP: $1"
> echo "SKIP: $1" >&2
> - exit 4
> + exit $ksft_skip
> +}
> +
> +# root test
> +function is_root() {
> + uid=$(id -u)
> + if [ $uid -ne 0 ]; then
> + echo "skip all tests: must be run as root" >&2
> + exit $ksft_skip
> + fi
> }
>
> # die(msg) - game over, man
> @@ -62,6 +74,7 @@ function set_ftrace_enabled() {
> # for verbose livepatching output and turn on
> # the ftrace_enabled sysctl.
> function setup_config() {
> + is_root
> push_config
> set_dynamic_debug
> set_ftrace_enabled 1
> diff --git a/tools/testing/selftests/livepatch/test-state.sh b/tools/testing/selftests/livepatch/test-state.sh
> index dc2908c22c26..a08212708115 100755
> --- a/tools/testing/selftests/livepatch/test-state.sh
> +++ b/tools/testing/selftests/livepatch/test-state.sh
> @@ -8,8 +8,7 @@ MOD_LIVEPATCH=test_klp_state
> MOD_LIVEPATCH2=test_klp_state2
> MOD_LIVEPATCH3=test_klp_state3
>
> -set_dynamic_debug
> -
> +setup_config
>
> # TEST: Loading and removing a module that modifies the system state
>
> --
> 2.20.1
>
Thanks for fixing these, Shuah.
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
-- Joe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftests: livepatch: Fix it to do root uid check and skip
2019-12-16 19:18 [PATCH v2] selftests: livepatch: Fix it to do root uid check and skip Shuah Khan
2019-12-16 21:01 ` Joe Lawrence
@ 2019-12-17 9:02 ` Petr Mladek
2019-12-17 15:08 ` Shuah Khan
1 sibling, 1 reply; 4+ messages in thread
From: Petr Mladek @ 2019-12-17 9:02 UTC (permalink / raw)
To: Shuah Khan
Cc: jpoimboe, jikos, mbenes, joe.lawrence, shuah, live-patching,
linux-kselftest, linux-kernel
On Mon 2019-12-16 12:18:40, Shuah Khan wrote:
> livepatch test configures the system and debug environment to run
> tests. Some of these actions fail without root access and test
> dumps several permission denied messages before it exits.
>
> Fix test-state.sh to call setup_config instead of set_dynamic_debug
> as suggested by Petr Mladek <pmladek@suse.com>
>
> Fix it to check root uid and exit with skip code instead.
>
> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Shuah, I assume that you will push this fix via linux-kselftest tree.
Please, tell us if you have other preference.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftests: livepatch: Fix it to do root uid check and skip
2019-12-17 9:02 ` Petr Mladek
@ 2019-12-17 15:08 ` Shuah Khan
0 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2019-12-17 15:08 UTC (permalink / raw)
To: Petr Mladek
Cc: jpoimboe, jikos, mbenes, joe.lawrence, shuah, live-patching,
linux-kselftest, linux-kernel, Shuah Khan
On 12/17/19 2:02 AM, Petr Mladek wrote:
> On Mon 2019-12-16 12:18:40, Shuah Khan wrote:
>> livepatch test configures the system and debug environment to run
>> tests. Some of these actions fail without root access and test
>> dumps several permission denied messages before it exits.
>>
>> Fix test-state.sh to call setup_config instead of set_dynamic_debug
>> as suggested by Petr Mladek <pmladek@suse.com>
>>
>> Fix it to check root uid and exit with skip code instead.
>>
>> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
>
> Reviewed-by: Petr Mladek <pmladek@suse.com>
>
> Shuah, I assume that you will push this fix via linux-kselftest tree.
> Please, tell us if you have other preference.
>
Hi Petr, Yes I will push this in. Thanks for the reviews.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-17 15:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-16 19:18 [PATCH v2] selftests: livepatch: Fix it to do root uid check and skip Shuah Khan
2019-12-16 21:01 ` Joe Lawrence
2019-12-17 9:02 ` Petr Mladek
2019-12-17 15:08 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).