Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andy Lutomirski and committed by
Ingo Molnar
158b67b5 c876eeab

+14 -7
+14 -7
tools/testing/selftests/sigaltstack/sas.c
··· 15 15 #include <alloca.h> 16 16 #include <string.h> 17 17 #include <assert.h> 18 + #include <errno.h> 18 19 19 20 #ifndef SS_AUTODISARM 20 21 #define SS_AUTODISARM (1 << 4) ··· 118 117 stk.ss_flags = SS_ONSTACK | SS_AUTODISARM; 119 118 err = sigaltstack(&stk, NULL); 120 119 if (err) { 121 - perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)"); 122 - stk.ss_flags = SS_ONSTACK; 123 - } 124 - err = sigaltstack(&stk, NULL); 125 - if (err) { 126 - perror("[FAIL]\tsigaltstack(SS_ONSTACK)"); 127 - return EXIT_FAILURE; 120 + if (errno == EINVAL) { 121 + printf("[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n"); 122 + /* 123 + * If test cases for the !SS_AUTODISARM variant were 124 + * added, we could still run them. We don't have any 125 + * test cases like that yet, so just exit and report 126 + * success. 127 + */ 128 + return 0; 129 + } else { 130 + perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)"); 131 + return EXIT_FAILURE; 132 + } 128 133 } 129 134 130 135 ustack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE,