diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-07-14 19:39:25 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-07-14 19:39:25 +0200 |
commit | 8bc6a711fbbad02abcf98f441330be19627ce3a0 (patch) | |
tree | 4a54b010d4d1fcb2955ae4049b893da5fc3f106f | |
download | fail-8bc6a711fbbad02abcf98f441330be19627ce3a0.tar.gz fail-8bc6a711fbbad02abcf98f441330be19627ce3a0.tar.xz fail-8bc6a711fbbad02abcf98f441330be19627ce3a0.zip |
initial commit of fail
-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | README | 59 | ||||
-rw-r--r-- | fail.1 | 72 | ||||
-rw-r--r-- | fail.c | 116 |
4 files changed, 270 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7dca2f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +ALL=fail + +CFLAGS=-g -O2 -Wall -Wno-switch -Wextra -Wwrite-strings + +DESTDIR= +PREFIX=/usr/local +BINDIR=$(PREFIX)/bin +MANDIR=$(PREFIX)/share/man + +all: $(ALL) + +README: fail.1 + mandoc -Tutf8 $< | col -bx >$@ + +clean: FRC + rm -f $(ALL) + +install: FRC all + mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 + install -m0755 $(ALL) $(DESTDIR)$(BINDIR) + install -m0644 $(ALL:=.1) $(DESTDIR)$(MANDIR)/man1 + +FRC: diff --git a/README b/README new file mode 100644 index 0000000..c0ab3f2 --- /dev/null +++ b/README @@ -0,0 +1,59 @@ +FAIL(1) General Commands Manual FAIL(1) + +NAME + fail – crash in various possible ways + +SYNOPSIS + fail [-123Oacdikrst] + +DESCRIPTION + fail crashes in various possible ways to help you debug how other + software reacts to this. + + The options are as follows: + + -1 Return with exit status -1. + + -2 Return with exit status 2. + + -3 Return with exit status 111. + + -O Allocate memory in an infinite loop, to trigger an out of memory + situation. A dot is printed after each 16MB allocation. + Warning: this may lock up your machine and/or result in killing + other processes, too. Use with caution. + + -a Call abort(). + + -c Violate a seccomp() strict mode restriction. + + -d Divide by zero. + + -i Execute an illegal instruction. + + -k Raise SIGKILL. + + -r Trigger an infinite recursion. + + -s Trigger a segmentation fault by writing to a null pointer. + + -t Trigger GCC's __builtin_trap(). + +EXIT STATUS + The fail utility never returns 0, because failure is inevitable. + +SEE ALSO + false(1), seccomp(2), abort(3) + +AUTHORS + Leah Neukirchen <leah@vuxu.org> + +LICENSE + fail is in the public domain. + + To the extent possible under law, the creator of this work has waived all + copyright and related or neighboring rights to this work. + + http://creativecommons.org/publicdomain/zero/1.0/ + +Void Linux July 14, 2017 Void Linux diff --git a/fail.1 b/fail.1 new file mode 100644 index 0000000..c47fbd5 --- /dev/null +++ b/fail.1 @@ -0,0 +1,72 @@ +.Dd July 14, 2017 +.Dt FAIL 1 +.Os +.Sh NAME +.Nm fail +.Nd crash in various possible ways +.Sh SYNOPSIS +.Nm +.Op Fl 123Oacdikrst +.Sh DESCRIPTION +.Nm +crashes in various possible ways to +help you debug how other software reacts to this. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl 1 +Return with exit status -1. +.It Fl 2 +Return with exit status 2. +.It Fl 3 +Return with exit status 111. +.It Fl O +Allocate memory in an infinite loop, +to trigger an out of memory situation. +A dot is printed after each 16MB allocation. +.Sy Warning : +this may lock up your machine +and/or result in killing other processes, too. +Use with caution. +.It Fl a +Call +.Fn abort . +.It Fl c +Violate a +.Fn seccomp +strict mode restriction. +.It Fl d +Divide by zero. +.It Fl i +Execute an illegal instruction. +.It Fl k +Raise SIGKILL. +.It Fl r +Trigger an infinite recursion. +.It Fl s +Trigger a segmentation fault by writing to a null pointer. +.It Fl t +Trigger GCC's +.Fn __builtin_trap . +.El +.Sh EXIT STATUS +The +.Nm +utility never returns 0, +because failure is inevitable. +.Sh SEE ALSO +.Xr false 1 , +.Xr seccomp 2 , +.Xr abort 3 +.Sh AUTHORS +.An Leah Neukirchen Aq Mt leah@vuxu.org +.Sh LICENSE +.Nm +is in the public domain. +.Pp +To the extent possible under law, +the creator of this work +has waived all copyright and related or +neighboring rights to this work. +.Pp +.Lk http://creativecommons.org/publicdomain/zero/1.0/ diff --git a/fail.c b/fail.c new file mode 100644 index 0000000..36896c5 --- /dev/null +++ b/fail.c @@ -0,0 +1,116 @@ +/* fail - crash in various possible ways */ + +#include <linux/seccomp.h> + +#include <sys/prctl.h> +#include <sys/ptrace.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include <fcntl.h> +#include <signal.h> +#include <stdlib.h> +#include <unistd.h> + +void +segfault() { + volatile int *nullp = 0; + + *nullp = 42; +} + +// can lockup your machine +void +oom() { + long c = 0; + static long last = 0; + + int fd; + fd = open("/proc/self/oom_score_adj", O_WRONLY); + write(fd, "1000\n", 5); + close(fd); + + while (1) { + long *m = malloc(4096*4096); + m[0] = last; + m[1] = c++; + last = (long)m; + write(1, ".", 1); + } +} + +void +recurse(char *n) { + char m[1024]; + recurse(m); + if (n) + m[0] = n[0] = 42; +} + +void +abortme() { + abort(); +} + +void +killme() { + raise(SIGKILL); +} + +void illegalins() { +#if defined(__x86_64__) || defined(__i386__) + __asm__ __volatile__( "ud1" : : : "memory" ); +#elif defined(__arm__) + __asm__ __volatile__( + #ifndef __thumb__ + ".word 0xe7f000f0" + #else + ".short 0xdeff" + #endif + : : : "memory"); +#elif defined(__aarch64__) + __asm__ __volatile__( ".word 0x00800011" : : : "memory" ); +#else + #error implement illegalins for this architecture +#endif +} + +void trap() { + __builtin_trap(); +} + +int zero = 0; +void divtrap() { + zero = 1/zero; +} + +void +violate_seccomp() { + prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); + chdir("/"); +} + +int +main(int argc, char *argv[]) { + int c; + + while ((c = getopt(argc, argv, "123Oacdikrst")) != -1) { + switch (c) { + case '1': exit(-1); break; + case '2': exit(2); break; + case '3': exit(111); break; + case 'c': violate_seccomp(); break; + case 'd': divtrap(); break; + case 'i': illegalins(); break; + case 't': trap(); break; + case 'O': oom(); break; + case 'a': abortme(); break; + case 'k': killme(); break; + case 'r': recurse(0); break; + case 's': segfault(); break; + } + } + + write(2, "Usage: fail [-123Oacdikrst]", 8); + exit(1); +} |