1 /*	$OpenBSD: syscallwx.c,v 1.1 2019/09/23 08:34:07 bluhm Exp $	*/
2 /*
3  * Copyright (c) 2018 Todd Mortimer <mortimer@openbsd.org>
4  * Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/mman.h>
20 
21 #include <err.h>
22 #include <signal.h>
23 #include <unistd.h>
24 
25 void handler(int);
26 
27 int
28 main(int argc, char *argv[])
29 {
30 	pid_t pid;
31 
32 	pid = getpid();
33 	if (pid == -1)
34 		err(1, "getpid");
35 	/* map kill system call in libc writeable */
36 	if (mprotect(kill, 100, PROT_EXEC | PROT_WRITE | PROT_READ) == -1)
37 		err(1, "mprotect");
38 
39 	if (signal(SIGSEGV, handler) == SIG_ERR)
40 		err(1, "signal");
41 	if (kill(pid, SIGABRT) == -1)
42 		err(1, "kill");
43 	return 3;
44 }
45 
46 void
47 handler(int signum)
48 {
49 	_exit(0);
50 }
51