11 #if defined(__i386__) || defined(__x86_64__)
12 #define SUPPORTED_ARCH 1
15 #if defined(SUPPORTED_ARCH)
19 #include <linux/types.h>
20 #include <linux/filter.h>
21 #include <linux/seccomp.h>
27 #include <sys/prctl.h>
30 #define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]))
31 #define syscall_nr (offsetof(struct seccomp_data, nr))
34 #define REG_RESULT REG_EAX
35 #define REG_SYSCALL REG_EAX
36 #define REG_ARG0 REG_EBX
37 #define REG_ARG1 REG_ECX
38 #define REG_ARG2 REG_EDX
39 #define REG_ARG3 REG_ESI
40 #define REG_ARG4 REG_EDI
41 #define REG_ARG5 REG_EBP
42 #elif defined(__x86_64__)
43 #define REG_RESULT REG_RAX
44 #define REG_SYSCALL REG_RAX
45 #define REG_ARG0 REG_RDI
46 #define REG_ARG1 REG_RSI
47 #define REG_ARG2 REG_RDX
48 #define REG_ARG3 REG_R10
49 #define REG_ARG4 REG_R8
50 #define REG_ARG5 REG_R9
53 #ifndef PR_SET_NO_NEW_PRIVS
54 #define PR_SET_NO_NEW_PRIVS 38
78 if (ctx->
uc_mcontext.gregs[REG_ARG0] != STDERR_FILENO)
82 if (
write(STDOUT_FILENO,
"[ERR] ", 6) > 0) {
83 bytes =
write(STDOUT_FILENO, buf, len);
89 static int install_emulator(
void)
93 memset(&act, 0,
sizeof(act));
97 act.sa_sigaction = &emulator;
104 perror(
"sigprocmask");
110 static int install_filter(
void)
118 #ifdef __NR_sigreturn
145 .len = (
unsigned short)(
sizeof(filter)/
sizeof(filter[0])),
150 perror(
"prctl(NO_NEW_PRIVS)");
162 #define payload(_c) (_c), sizeof((_c))
167 if (install_emulator())
169 if (install_filter())
172 payload(
"OHAI! WHAT IS YOUR NAME? "));
173 bytes = syscall(
__NR_read, STDIN_FILENO, buf,
sizeof(buf));
175 syscall(
__NR_write, STDOUT_FILENO, buf, bytes);
177 payload(
"Error message going to STDERR\n"));