[PATCH 2/4] selftests/sigaltstack: Fix the sas test on old kernels

From: Andy Lutomirski
Date: Tue May 03 2016 - 13:32:19 EST


The handling for old kernels was wrong. Fix it.

Reported-by: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Stas Sergeev <stsp@xxxxxxx>
Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Brian Gerst <brgerst@xxxxxxxxx>
Cc: Denys Vlasenko <dvlasenk@xxxxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: Pavel Emelyanov <xemul@xxxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Shuah Khan <shuahkh@xxxxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: linux-api@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxx>
---
tools/testing/selftests/sigaltstack/sas.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/sigaltstack/sas.c b/tools/testing/selftests/sigaltstack/sas.c
index 57da8bfde60b..a98c3ef8141f 100644
--- a/tools/testing/selftests/sigaltstack/sas.c
+++ b/tools/testing/selftests/sigaltstack/sas.c
@@ -15,6 +15,7 @@
#include <alloca.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>

#ifndef SS_AUTODISARM
#define SS_AUTODISARM (1 << 4)
@@ -117,13 +118,19 @@ int main(void)
stk.ss_flags = SS_ONSTACK | SS_AUTODISARM;
err = sigaltstack(&stk, NULL);
if (err) {
- perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)");
- stk.ss_flags = SS_ONSTACK;
- }
- err = sigaltstack(&stk, NULL);
- if (err) {
- perror("[FAIL]\tsigaltstack(SS_ONSTACK)");
- return EXIT_FAILURE;
+ if (errno == EINVAL) {
+ printf("[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n");
+ /*
+ * If test cases for the !SS_AUTODISARM variant were
+ * added, we could still run them. We don't have any
+ * test cases like that yet, so just exit and report
+ * success.
+ */
+ return 0;
+ } else {
+ perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)");
+ return EXIT_FAILURE;
+ }
}

ustack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE,
--
2.5.5