From: Punit Agrawal Date: Thu, 26 Oct 2017 15:14:40 +0100 Subject: [LTP] [PATCH 11/18] sigwaitinfo: catch SEGV and report success for bad_address2 testcase In-Reply-To: <20171026141447.26749-1-punit.agrawal@arm.com> References: <20171026141447.26749-1-punit.agrawal@arm.com> Message-ID: <20171026141447.26749-12-punit.agrawal@arm.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ltp@lists.linux.it From: Will Deacon The bad_address2 testcase passes (void *)1 as a sigset pointer to the sigwaitinfo syscall. Unsurprisingly, this segfaults in libc rather than returning -1 (errno = EFAULT) as LTP expects. This patch registers a SIGSEGV handler to catch any SEGV's generated by the sigwaitinfo syscall and treat them as success. Signed-off-by: Will Deacon Signed-off-by: Punit Agrawal --- .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c index 16b5096b8..44aa849af 100644 --- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c @@ -23,6 +23,8 @@ #include "test.h" #include #include +#include +#include #include "../utils/include_j_h.h" #include "../utils/common_j_h.c" #include @@ -361,9 +363,36 @@ void test_bad_address(swi_func sigwaitinfo, int signo) kill(child, SIGTERM); } +sigjmp_buf jmpbuf; + +static void segv_handler(int signal, siginfo_t *info, struct ucontext *ut) +{ + if (signal == SIGSEGV) + longjmp(jmpbuf, 1); + + fprintf(stderr, "caught unexpected signal - %d --- exiting\n", signal); + _exit(-1); +} + void test_bad_address2(swi_func sigwaitinfo, int signo) { - TEST(sigwaitinfo((void *)1, NULL, NULL)); + struct sigaction sigptr, oldact; + + sigptr.sa_sigaction = segv_handler; + sigfillset(&sigptr.sa_mask); + sigdelset(&sigptr.sa_mask, SIGSEGV); + sigptr.sa_flags = SA_SIGINFO; + + SUCCEED_OR_DIE(sigaction, "sigaction failed", SIGSEGV, &sigptr, &oldact); + + if (setjmp(jmpbuf) == 0) { + TEST(sigwaitinfo((void*)1, NULL, NULL)); + } else { + TEST_RETURN = -1; + TEST_ERRNO = EFAULT; + } + + SUCCEED_OR_DIE(sigaction, "sigaction failed", SIGSEGV, &oldact, NULL); REPORT_SUCCESS(-1, EFAULT); } -- 2.14.2