[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220126191441.3380389-3-stsp2@yandex.ru>
Date: Wed, 26 Jan 2022 22:14:41 +0300
From: Stas Sergeev <stsp2@...dex.ru>
To: unlisted-recipients:; (no To-header on input)
Cc: Stas Sergeev <stsp2@...dex.ru>, Shuah Khan <shuah@...nel.org>,
"Chang S. Bae" <chang.seok.bae@...el.com>,
Borislav Petkov <bp@...e.de>,
Thomas Gleixner <tglx@...utronix.de>,
Len Brown <len.brown@...el.com>,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] selftests: sigaltstack: add new SS_DISABLE test
This test makes sure that when SS_DISABLE is used, all other flags
are ignored.
Also remove unneeded exit()s after ksft_exit_fail_msg(). That function
exits by itself.
Signed-off-by: Stas Sergeev <stsp2@...dex.ru>
CC: Shuah Khan <shuah@...nel.org>
CC: "Chang S. Bae" <chang.seok.bae@...el.com>
CC: Borislav Petkov <bp@...e.de>
CC: Thomas Gleixner <tglx@...utronix.de>
CC: Len Brown <len.brown@...el.com>
CC: linux-kselftest@...r.kernel.org
CC: linux-kernel@...r.kernel.org
---
tools/testing/selftests/sigaltstack/sas.c | 48 ++++++++++++-----------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/tools/testing/selftests/sigaltstack/sas.c b/tools/testing/selftests/sigaltstack/sas.c
index c53b070755b6..7be377e84aa0 100644
--- a/tools/testing/selftests/sigaltstack/sas.c
+++ b/tools/testing/selftests/sigaltstack/sas.c
@@ -119,7 +119,7 @@ int main(void)
ksft_print_msg("[NOTE]\tthe stack size is %lu\n", stack_size);
ksft_print_header();
- ksft_set_plan(3);
+ ksft_set_plan(4);
sigemptyset(&act.sa_mask);
act.sa_flags = SA_ONSTACK | SA_SIGINFO;
@@ -129,24 +129,18 @@ int main(void)
sigaction(SIGUSR2, &act, NULL);
sstack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
- if (sstack == MAP_FAILED) {
+ if (sstack == MAP_FAILED)
ksft_exit_fail_msg("mmap() - %s\n", strerror(errno));
- return EXIT_FAILURE;
- }
err = sigaltstack(NULL, &stk);
- if (err) {
+ if (err)
ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- if (stk.ss_flags == SS_DISABLE) {
+ if (stk.ss_flags == SS_DISABLE)
ksft_test_result_pass(
"Initial sigaltstack state was SS_DISABLE\n");
- } else {
+ else
ksft_exit_fail_msg("Initial sigaltstack state was %x; "
"should have been SS_DISABLE\n", stk.ss_flags);
- return EXIT_FAILURE;
- }
stk.ss_sp = sstack;
stk.ss_size = stack_size;
@@ -167,16 +161,13 @@ int main(void)
ksft_exit_fail_msg(
"sigaltstack(SS_ONSTACK | SS_AUTODISARM) %s\n",
strerror(errno));
- return EXIT_FAILURE;
}
}
ustack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
- if (ustack == MAP_FAILED) {
+ if (ustack == MAP_FAILED)
ksft_exit_fail_msg("mmap() - %s\n", strerror(errno));
- return EXIT_FAILURE;
- }
getcontext(&uc);
uc.uc_link = NULL;
uc.uc_stack.ss_sp = ustack;
@@ -185,17 +176,28 @@ int main(void)
raise(SIGUSR1);
err = sigaltstack(NULL, &stk);
- if (err) {
+ if (err)
ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- if (stk.ss_flags != SS_AUTODISARM) {
- ksft_exit_fail_msg("ss_flags=%x, should be SS_AUTODISARM\n",
+ if (stk.ss_flags != SS_AUTODISARM)
+ ksft_test_result_fail("ss_flags=%x, should be SS_AUTODISARM\n",
stk.ss_flags);
- exit(EXIT_FAILURE);
- }
- ksft_test_result_pass(
+ else
+ ksft_test_result_pass(
"sigaltstack is still SS_AUTODISARM after signal\n");
+ /* We are done, disable SS and exit. */
+ stk.ss_flags = SS_DISABLE | SS_AUTODISARM;
+ err = sigaltstack(&stk, NULL);
+ if (err)
+ ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
+ err = sigaltstack(NULL, &stk);
+ if (err)
+ ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
+ if (stk.ss_flags != SS_DISABLE)
+ ksft_test_result_fail("ss_flags=%x, should be SS_DISABLE\n",
+ stk.ss_flags);
+ else
+ ksft_test_result_pass(
+ "sigaltstack disabled\n");
ksft_exit_pass();
return 0;
--
2.34.1
Powered by blists - more mailing lists