selftests/sigaltstack: Fix the sigaltstack test on old kernels

The handling for old kernels was wrong, resulting in a segfault.  Fix it.

Reported-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Stas Sergeev <stsp@list.ru>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-api@vger.kernel.org
Link: http://lkml.kernel.org/r/f3e739bf435beeaecbd5f038f1359d2eac6d1e63.1462296606.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Andy Lutomirski 2016-05-03 10:31:50 -07:00 коммит произвёл Ingo Molnar
Родитель c876eeab64
Коммит 158b67b5c5
1 изменённых файлов: 14 добавлений и 7 удалений

Просмотреть файл

@ -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,