Thread (8 messages) 8 messages, 3 authors, 2021-01-08

Re: [PATCH v3 4/4] selftest/x86/signal: Include test cases for validating sigaltstack

From: Borislav Petkov <hidden>
Date: 2021-01-08 18:08:19
Also in: linux-api, linux-kselftest, lkml

On Tue, Dec 22, 2020 at 05:53:12PM -0800, Chang S. Bae wrote:
+static int setup_altstack(void *start, unsigned long size)
+{
+	stack_t ss;
+
+	memset(&ss, 0, sizeof(ss));
+	ss.ss_size = size;
+	ss.ss_sp = start;
+
+	return sigaltstack(&ss, NULL);
+}
+
+static jmp_buf jmpbuf;
+
+static void sigsegv(int sig, siginfo_t *info, void *ctx_void)
+{
+	if (sigalrm_expected) {
+		printf("[FAIL]\tSIGSEGV signal delivery is wrong.\n");
			 	"Wrong signal delivered: SIGSEGV (expected SIGALRM)."
+		nerrs++;
+	} else {
+		printf("[OK]\tSIGSEGV signal is delivered.\n");
					s/is //
+	}
+
+	siglongjmp(jmpbuf, 1);
+}
+
+static void sigalrm(int sig, siginfo_t *info, void *ctx_void)
+{
+	if (!sigalrm_expected) {
+		printf("[FAIL]\tSIGALRM sigal delivery is wrong.\n");
See above.
+		nerrs++;
+	} else {
+		printf("[OK]\tSIGALRM signal is delivered.\n");
Ditto.
+	}
+}
+
+static void test_sigaltstack(void *altstack, unsigned long size)
+{
+	if (setup_altstack(altstack, size))
+		err(1, "sigaltstack()");
+
+	sigalrm_expected = (size > at_minstack_size) ? true : false;
+
+	sethandler(SIGSEGV, sigsegv, 0);
+	sethandler(SIGALRM, sigalrm, SA_ONSTACK);
+
+	if (sigsetjmp(jmpbuf, 1) == 0) {
	if (!sigsetjmp...)
+		printf("[RUN]\tTest an (%s) alternate signal stack\n",
			"Test an alternate signal stack of %ssufficient size.\n"
+		       sigalrm_expected ? "enough" : "too-small");
					 "" : "in");
+		printf("\tRaise SIGALRM. %s is expected to be delivered.\n",
+		       sigalrm_expected ? "It" : "But SIGSEGV");
					"It" : "SIGSEGV"

Drop "But".

Ask if something's not clear.

-- 
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help