[LTP] [PATCH 11/18] sigwaitinfo: catch SEGV and report success for bad_address2 testcase

Punit Agrawal punit.agrawal@arm.com
Thu Oct 26 16:14:40 CEST 2017


From: Will Deacon <will.deacon@arm.com>

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 <will.deacon@arm.com>
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
---
 .../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 <errno.h>
 #include <signal.h>
+#include <sys/ucontext.h>
+#include <setjmp.h>
 #include "../utils/include_j_h.h"
 #include "../utils/common_j_h.c"
 #include <limits.h>
@@ -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



More information about the ltp mailing list