]> mj.ucw.cz Git - moe.git/blob - src/box.c
Converted matching of paths to a table-driven system.
[moe.git] / src / box.c
1 /*
2  *      A Simple Sandbox for MO-Eval
3  *
4  *      (c) 2001--2008 Martin Mares <mj@ucw.cz>
5  */
6
7 #define _LARGEFILE64_SOURCE
8 #define _GNU_SOURCE
9
10 #include <errno.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stdarg.h>
16 #include <unistd.h>
17 #include <getopt.h>
18 #include <time.h>
19 #include <sys/wait.h>
20 #include <sys/user.h>
21 #include <sys/time.h>
22 #include <sys/ptrace.h>
23 #include <sys/signal.h>
24 #include <sys/sysinfo.h>
25 #include <sys/syscall.h>
26 #include <sys/resource.h>
27
28 #define NONRET __attribute__((noreturn))
29 #define UNUSED __attribute__((unused))
30 #define ARRAY_SIZE(a) (int)(sizeof(a)/sizeof(a[0]))
31
32 static int filter_syscalls;             /* 0=off, 1=liberal, 2=totalitarian */
33 static int timeout;                     /* milliseconds */
34 static int wall_timeout;
35 static int pass_environ;
36 static int file_access;
37 static int verbose;
38 static int memory_limit;
39 static char *redir_stdin, *redir_stdout;
40 static char *set_cwd;
41
42 static pid_t box_pid;
43 static int is_ptraced;
44 static volatile int timer_tick;
45 static struct timeval start_time;
46 static int ticks_per_sec;
47 static int exec_seen;
48
49 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
50 /* glibc 2.1 or newer -> has lseek64 */
51 #define long_seek(f,o,w) lseek64(f,o,w)
52 #else
53 /* Touching clandestine places in glibc */
54 extern loff_t llseek(int fd, loff_t pos, int whence);
55 #define long_seek(f,o,w) llseek(f,o,w)
56 #endif
57
58 static void NONRET
59 box_exit(void)
60 {
61   if (box_pid > 0)
62     {
63       if (is_ptraced)
64         ptrace(PTRACE_KILL, box_pid);
65       kill(-box_pid, SIGKILL);
66       kill(box_pid, SIGKILL);
67     }
68   exit(1);
69 }
70
71 static void NONRET __attribute__((format(printf,1,2)))
72 die(char *msg, ...)
73 {
74   va_list args;
75   va_start(args, msg);
76   vfprintf(stderr, msg, args);
77   fputc('\n', stderr);
78   box_exit();
79 }
80
81 static void __attribute__((format(printf,1,2)))
82 msg(char *msg, ...)
83 {
84   va_list args;
85   va_start(args, msg);
86   if (verbose)
87     {
88       vfprintf(stderr, msg, args);
89       fflush(stderr);
90     }
91   va_end(args);
92 }
93
94 static const char * const syscall_tab[] = {
95 #include "syscall-table.h"
96 };
97 #define NUM_SYSCALLS (sizeof(syscall_tab)/sizeof(syscall_tab[0]))
98 #define NUM_ACTIONS (NUM_SYSCALLS+64)
99
100 enum action {
101   SC_DEFAULT,           // Use the default action
102   SC_NO,                // Always forbid
103   SC_YES,               // Always permit
104   SC_FILENAME,          // Permit if arg1 is a known filename
105   SC_LIBERAL = 128,     // Valid only in liberal mode
106 };
107
108 static unsigned char syscall_action[NUM_ACTIONS] = {
109 #define S(x) [__NR_##x]
110
111     // Syscalls permitted for specific file names
112     S(open) = SC_FILENAME,
113     S(creat) = SC_FILENAME,
114     S(unlink) = SC_FILENAME,
115     S(oldstat) = SC_FILENAME,
116     S(access) = SC_FILENAME,                    
117     S(oldlstat) = SC_FILENAME,                  
118     S(truncate) = SC_FILENAME,
119     S(stat) = SC_FILENAME,
120     S(lstat) = SC_FILENAME,
121     S(truncate64) = SC_FILENAME,
122     S(stat64) = SC_FILENAME,
123     S(lstat64) = SC_FILENAME,
124     S(readlink) = SC_FILENAME,
125
126     // Syscalls permitted always
127     S(exit) = SC_YES,
128     S(read) = SC_YES,
129     S(write) = SC_YES,
130     S(close) = SC_YES,
131     S(lseek) = SC_YES,
132     S(getpid) = SC_YES,
133     S(getuid) = SC_YES,
134     S(oldfstat) = SC_YES,
135     S(dup) = SC_YES,
136     S(brk) = SC_YES,
137     S(getgid) = SC_YES,
138     S(geteuid) = SC_YES,
139     S(getegid) = SC_YES,
140     S(dup2) = SC_YES,
141     S(ftruncate) = SC_YES,
142     S(fstat) = SC_YES,
143     S(personality) = SC_YES,
144     S(_llseek) = SC_YES,
145     S(readv) = SC_YES,
146     S(writev) = SC_YES,
147     S(getresuid) = SC_YES,
148 #ifdef __NR_pread64
149     S(pread64) = SC_YES,
150     S(pwrite64) = SC_YES,
151 #else
152     S(pread) = SC_YES,
153     S(pwrite) = SC_YES,
154 #endif
155     S(ftruncate64) = SC_YES,
156     S(fstat64) = SC_YES,
157     S(fcntl) = SC_YES,
158     S(fcntl64) = SC_YES,
159     S(mmap) = SC_YES,
160     S(munmap) = SC_YES,
161     S(ioctl) = SC_YES,
162     S(uname) = SC_YES,
163     S(gettid) = SC_YES,
164     S(set_thread_area) = SC_YES,
165     S(get_thread_area) = SC_YES,
166     S(exit_group) = SC_YES,
167
168     // Syscalls permitted only in liberal mode
169     S(time) = SC_YES | SC_LIBERAL,
170     S(alarm) = SC_YES | SC_LIBERAL,
171     S(pause) = SC_YES | SC_LIBERAL,
172     S(signal) = SC_YES | SC_LIBERAL,
173     S(fchmod) = SC_YES | SC_LIBERAL,
174     S(sigaction) = SC_YES | SC_LIBERAL,
175     S(sgetmask) = SC_YES | SC_LIBERAL,
176     S(ssetmask) = SC_YES | SC_LIBERAL,
177     S(sigsuspend) = SC_YES | SC_LIBERAL,
178     S(sigpending) = SC_YES | SC_LIBERAL,
179     S(getrlimit) = SC_YES | SC_LIBERAL,
180     S(getrusage) = SC_YES | SC_LIBERAL,
181     S(ugetrlimit) = SC_YES | SC_LIBERAL,
182     S(gettimeofday) = SC_YES | SC_LIBERAL,
183     S(select) = SC_YES | SC_LIBERAL,
184     S(readdir) = SC_YES | SC_LIBERAL,
185     S(setitimer) = SC_YES | SC_LIBERAL,
186     S(getitimer) = SC_YES | SC_LIBERAL,
187     S(sigreturn) = SC_YES | SC_LIBERAL,
188     S(mprotect) = SC_YES | SC_LIBERAL,
189     S(sigprocmask) = SC_YES | SC_LIBERAL,
190     S(getdents) = SC_YES | SC_LIBERAL,
191     S(getdents64) = SC_YES | SC_LIBERAL,
192     S(_newselect) = SC_YES | SC_LIBERAL,
193     S(fdatasync) = SC_YES | SC_LIBERAL,
194     S(mremap) = SC_YES | SC_LIBERAL,
195     S(poll) = SC_YES | SC_LIBERAL,
196     S(getcwd) = SC_YES | SC_LIBERAL,
197     S(nanosleep) = SC_YES | SC_LIBERAL,
198     S(rt_sigreturn) = SC_YES | SC_LIBERAL,
199     S(rt_sigaction) = SC_YES | SC_LIBERAL,
200     S(rt_sigprocmask) = SC_YES | SC_LIBERAL,
201     S(rt_sigpending) = SC_YES | SC_LIBERAL,
202     S(rt_sigtimedwait) = SC_YES | SC_LIBERAL,
203     S(rt_sigqueueinfo) = SC_YES | SC_LIBERAL,
204     S(rt_sigsuspend) = SC_YES | SC_LIBERAL,
205     S(mmap2) = SC_YES | SC_LIBERAL,
206     S(_sysctl) = SC_YES | SC_LIBERAL,
207 #undef S
208 };
209
210 static const char *
211 syscall_name(unsigned int id, char *buf)
212 {
213   if (id < NUM_SYSCALLS && syscall_tab[id])
214     return syscall_tab[id];
215   else
216     {
217       sprintf(buf, "#%d", id);
218       return buf;
219     }
220 }
221
222 static int
223 syscall_by_name(char *name)
224 {
225   for (unsigned int i=0; i<sizeof(syscall_tab)/sizeof(syscall_tab[0]); i++)
226     if (syscall_tab[i] && !strcmp(syscall_tab[i], name))
227       return i;
228   if (name[0] == '#')
229     name++;
230   if (!*name)
231     return -1;
232   char *ep;
233   unsigned long l = strtoul(name, &ep, 0);
234   if (*ep)
235     return -1;
236   if (l >= NUM_ACTIONS)
237     return NUM_ACTIONS;
238   return l;
239 }
240
241 static int
242 set_action(char *a)
243 {
244   char *sep = strchr(a, '=');
245   enum action act = SC_YES;
246   if (sep)
247     {
248       *sep++ = 0;
249       if (!strcmp(sep, "yes"))
250         act = SC_YES;
251       else if (!strcmp(sep, "no"))
252         act = SC_NO;
253       else if (!strcmp(sep, "file"))
254         act = SC_FILENAME;
255       else
256         return 0;
257     }
258
259   int sys = syscall_by_name(a);
260   if (sys < 0)
261     die("Unknown syscall `%s'", a);
262   if (sys >= (int)NUM_ACTIONS)
263     die("Syscall `%s' out of range", a);
264   syscall_action[sys] = act;
265   return 1;
266 }
267
268 struct path_rule {
269   char *path;
270   enum action action;
271   struct path_rule *next;
272 };
273
274 static struct path_rule default_path_rules[] = {
275   { "/etc/", SC_YES },
276   { "/lib/", SC_YES },
277   { "/usr/lib/", SC_YES },
278   { "/opt/lib/", SC_YES },
279   { "/usr/share/zoneinfo/", SC_YES },
280   { "/dev/null", SC_YES },
281   { "/dev/zero", SC_YES },
282   { "/proc/meminfo", SC_YES },
283   { "/proc/self/stat", SC_YES },
284   { "/proc/self/exe", SC_YES },                 // Needed by FPC 2.0.x runtime
285 };
286
287 static enum action
288 match_path_rule(struct path_rule *r, char *path)
289 {
290   char *rr = r->path;
291   while (*rr)
292     if (*rr++ != *path++)
293       {
294         if (rr[-1] == '/' && !path[-1])
295           break;
296         return SC_DEFAULT;
297       }
298   if (rr > r->path && rr[-1] != '/' && *path)
299     return SC_DEFAULT;
300   return r->action;
301 }
302
303 static void
304 valid_filename(unsigned long addr)
305 {
306   char namebuf[4096], *p, *end;
307   static int mem_fd;
308
309   if (!file_access)
310     die("File access forbidden");
311   if (file_access >= 9)
312     return;
313
314   if (!mem_fd)
315     {
316       sprintf(namebuf, "/proc/%d/mem", (int) box_pid);
317       mem_fd = open(namebuf, O_RDONLY);
318       if (mem_fd < 0)
319         die("open(%s): %m", namebuf);
320     }
321   p = end = namebuf;
322   do
323     {
324       if (p >= end)
325         {
326           int remains = PAGE_SIZE - (addr & (PAGE_SIZE-1));
327           int l = namebuf + sizeof(namebuf) - end;
328           if (l > remains)
329             l = remains;
330           if (!l)
331             die("Access to file with name too long");
332           if (long_seek(mem_fd, addr, SEEK_SET) < 0)
333             die("long_seek(mem): %m");
334           remains = read(mem_fd, end, l);
335           if (remains < 0)
336             die("read(mem): %m");
337           if (!remains)
338             die("Access to file with name out of memory");
339           end += l;
340           addr += l;
341         }
342     }
343   while (*p++);
344
345   msg("[%s] ", namebuf);
346   if (file_access >= 3)
347     return;
348
349   // Everything in current directory is permitted
350   if (!strchr(namebuf, '/') && strcmp(namebuf, ".."))
351     return;
352
353   // ".." anywhere in the path is forbidden
354   enum action act = SC_DEFAULT;
355   if (strstr(namebuf, ".."))
356     act = SC_NO;
357
358   // Scan built-in rules
359   if (file_access >= 2)
360     for (int i=0; i<ARRAY_SIZE(default_path_rules) && !act; i++)
361       act = match_path_rule(&default_path_rules[i], namebuf);
362
363   if (act != SC_YES)
364     die("Forbidden access to file `%s'", namebuf);
365 }
366
367 static int
368 valid_syscall(struct user *u)
369 {
370   unsigned int sys = u->regs.orig_eax;
371   enum action act = (sys < NUM_ACTIONS) ? syscall_action[sys] : SC_DEFAULT;
372
373   if (act & SC_LIBERAL)
374     {
375       if (filter_syscalls == 1)
376         act &= ~SC_LIBERAL;
377       else
378         act = SC_DEFAULT;
379     }
380   switch (act)
381     {
382     case SC_YES:
383       return 1;
384     case SC_NO:
385       return 0;
386     case SC_FILENAME:
387       valid_filename(u->regs.ebx);
388       return 1;
389     default: ;
390     }
391
392   switch (sys)
393     {
394     case __NR_kill:
395       if (u->regs.ebx == box_pid)
396         die("Committed suicide by signal %d", (int)u->regs.ecx);
397       return 0;
398     case __NR_tgkill:
399       if (u->regs.ebx == box_pid && u->regs.ecx == box_pid)
400         die("Committed suicide by signal %d", (int)u->regs.edx);
401       return 0;
402     default:
403       return 0;
404     }
405 }
406
407 static void
408 signal_alarm(int unused UNUSED)
409 {
410   /* Time limit checks are synchronous, so we only schedule them there. */
411   timer_tick = 1;
412   alarm(1);
413 }
414
415 static void
416 signal_int(int unused UNUSED)
417 {
418   /* Interrupts are fatal, so no synchronization requirements. */
419   die("Interrupted");
420 }
421
422 static void
423 check_timeout(void)
424 {
425   if (wall_timeout)
426     {
427       struct timeval now, wall;
428       int wall_ms;
429       gettimeofday(&now, NULL);
430       timersub(&now, &start_time, &wall);
431       wall_ms = wall.tv_sec*1000 + wall.tv_usec/1000;
432       if (wall_ms > wall_timeout)
433         die("Time limit exceeded (wall clock)");
434       if (verbose > 1)
435         fprintf(stderr, "[wall time check: %d msec]\n", wall_ms);
436     }
437   if (timeout)
438     {
439       char buf[4096], *x;
440       int c, utime, stime, ms;
441       static int proc_status_fd;
442       if (!proc_status_fd)
443         {
444           sprintf(buf, "/proc/%d/stat", (int) box_pid);
445           proc_status_fd = open(buf, O_RDONLY);
446           if (proc_status_fd < 0)
447             die("open(%s): %m", buf);
448         }
449       lseek(proc_status_fd, 0, SEEK_SET);
450       if ((c = read(proc_status_fd, buf, sizeof(buf)-1)) < 0)
451         die("read on /proc/$pid/stat: %m");
452       if (c >= (int) sizeof(buf) - 1)
453         die("/proc/$pid/stat too long");
454       buf[c] = 0;
455       x = buf;
456       while (*x && *x != ' ')
457         x++;
458       while (*x == ' ')
459         x++;
460       if (*x++ != '(')
461         die("proc syntax error 1");
462       while (*x && (*x != ')' || x[1] != ' '))
463         x++;
464       while (*x == ')' || *x == ' ')
465         x++;
466       if (sscanf(x, "%*c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %d %d", &utime, &stime) != 2)
467         die("proc syntax error 2");
468       ms = (utime + stime) * 1000 / ticks_per_sec;
469       if (verbose > 1)
470         fprintf(stderr, "[time check: %d msec]\n", ms);
471       if (ms > timeout)
472         die("Time limit exceeded");
473     }
474 }
475
476 static void
477 boxkeeper(void)
478 {
479   int syscall_count = 0;
480   struct sigaction sa;
481
482   is_ptraced = 1;
483   bzero(&sa, sizeof(sa));
484   sa.sa_handler = signal_int;
485   sigaction(SIGINT, &sa, NULL);
486   gettimeofday(&start_time, NULL);
487   ticks_per_sec = sysconf(_SC_CLK_TCK);
488   if (ticks_per_sec <= 0)
489     die("Invalid ticks_per_sec!");
490   if (timeout || wall_timeout)
491     {
492       sa.sa_handler = signal_alarm;
493       sigaction(SIGALRM, &sa, NULL);
494       alarm(1);
495     }
496   for(;;)
497     {
498       struct rusage rus;
499       int stat;
500       pid_t p;
501       if (timer_tick)
502         {
503           check_timeout();
504           timer_tick = 0;
505         }
506       p = wait4(box_pid, &stat, WUNTRACED, &rus);
507       if (p < 0)
508         {
509           if (errno == EINTR)
510             continue;
511           die("wait4: %m");
512         }
513       if (p != box_pid)
514         die("wait4: unknown pid %d exited!", p);
515       if (WIFEXITED(stat))
516         {
517           struct timeval total, now, wall;
518           int total_ms, wall_ms;
519           box_pid = 0;
520           if (WEXITSTATUS(stat))
521             die("Exited with error status %d", WEXITSTATUS(stat));
522           timeradd(&rus.ru_utime, &rus.ru_stime, &total);
523           total_ms = total.tv_sec*1000 + total.tv_usec/1000;
524           gettimeofday(&now, NULL);
525           timersub(&now, &start_time, &wall);
526           wall_ms = wall.tv_sec*1000 + wall.tv_usec/1000;
527           if (timeout && total_ms > timeout)
528             die("Time limit exceeded");
529           if (wall_timeout && wall_ms > wall_timeout)
530             die("Time limit exceeded (wall clock)");
531           fprintf(stderr, "OK (%d.%03d sec real, %d.%03d sec wall, %d syscalls)\n",
532               (int) total.tv_sec, (int) total.tv_usec/1000,
533               (int) wall.tv_sec, (int) wall.tv_usec/1000,
534               syscall_count);
535           exit(0);
536         }
537       if (WIFSIGNALED(stat))
538         {
539           box_pid = 0;
540           die("Caught fatal signal %d%s", WTERMSIG(stat), (syscall_count ? "" : " during startup"));
541         }
542       if (WIFSTOPPED(stat))
543         {
544           int sig = WSTOPSIG(stat);
545           if (sig == SIGTRAP)
546             {
547               struct user u;
548               static int stop_count = -1;
549               if (ptrace(PTRACE_GETREGS, box_pid, NULL, &u) < 0)
550                 die("ptrace(PTRACE_GETREGS): %m");
551               stop_count++;
552               if (!stop_count)                  /* Traceme request */
553                 msg(">> Traceme request caught\n");
554               else if (stop_count & 1)          /* Syscall entry */
555                 {
556                   char namebuf[32];
557                   msg(">> Syscall %-12s (%08lx,%08lx,%08lx) ", syscall_name(u.regs.orig_eax, namebuf), u.regs.ebx, u.regs.ecx, u.regs.edx);
558                   if (!exec_seen)
559                     {
560                       msg("[master] ");
561                       if (u.regs.orig_eax == __NR_execve)
562                         exec_seen = 1;
563                     }
564                   else if (valid_syscall(&u))
565                     syscall_count++;
566                   else
567                     {
568                       /*
569                        * Unfortunately, PTRACE_KILL kills _after_ the syscall completes,
570                        * so we have to change it to something harmless (e.g., an undefined
571                        * syscall) and make the program continue.
572                        */
573                       unsigned int sys = u.regs.orig_eax;
574                       u.regs.orig_eax = 0xffffffff;
575                       if (ptrace(PTRACE_SETREGS, box_pid, NULL, &u) < 0)
576                         die("ptrace(PTRACE_SETREGS): %m");
577                       die("Forbidden syscall %s", syscall_name(sys, namebuf));
578                     }
579                 }
580               else                                      /* Syscall return */
581                 msg("= %ld\n", u.regs.eax);
582               ptrace(PTRACE_SYSCALL, box_pid, 0, 0);
583             }
584           else if (sig != SIGSTOP && sig != SIGXCPU && sig != SIGXFSZ)
585             {
586               msg(">> Signal %d\n", sig);
587               ptrace(PTRACE_SYSCALL, box_pid, 0, sig);
588             }
589           else
590             die("Received signal %d", sig);
591         }
592       else
593         die("wait4: unknown status %x, giving up!", stat);
594     }
595 }
596
597 static void
598 box_inside(int argc, char **argv)
599 {
600   struct rlimit rl;
601   char *args[argc+1];
602   char *env[] = { "LIBC_FATAL_STDERR_=1", NULL };
603
604   memcpy(args, argv, argc * sizeof(char *));
605   args[argc] = NULL;
606   if (set_cwd && chdir(set_cwd))
607     die("chdir: %m");
608   if (redir_stdin)
609     {
610       close(0);
611       if (open(redir_stdin, O_RDONLY) != 0)
612         die("open(\"%s\"): %m", redir_stdin);
613     }
614   if (redir_stdout)
615     {
616       close(1);
617       if (open(redir_stdout, O_WRONLY | O_CREAT | O_TRUNC, 0666) != 1)
618         die("open(\"%s\"): %m", redir_stdout);
619     }
620   dup2(1, 2);
621   setpgrp();
622   if (memory_limit)
623     {
624       rl.rlim_cur = rl.rlim_max = memory_limit * 1024;
625       if (setrlimit(RLIMIT_AS, &rl) < 0)
626         die("setrlimit: %m");
627     }
628   rl.rlim_cur = rl.rlim_max = 64;
629   if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
630     die("setrlimit: %m");
631   if (filter_syscalls)
632     {
633       if (ptrace(PTRACE_TRACEME) < 0)
634         die("ptrace(PTRACE_TRACEME): %m");
635       /* Trick: Make sure that we are stopped until the boxkeeper wakes up. */
636       signal(SIGCHLD, SIG_IGN);
637       raise(SIGCHLD);
638     }
639   execve(args[0], args, (pass_environ ? environ : env));
640   die("execve(\"%s\"): %m", args[0]);
641 }
642
643 static void
644 usage(void)
645 {
646   fprintf(stderr, "Invalid arguments!\n");
647   printf("\
648 Usage: box [<options>] -- <command> <arguments>\n\
649 \n\
650 Options:\n\
651 -a <level>\tSet file access level (0=none, 1=cwd, 2=/etc,/lib,..., 3=whole fs, 9=no checks; needs -f)\n\
652 -c <dir>\tChange directory to <dir> first\n\
653 -e\t\tPass full environment of parent process\n\
654 -f\t\tFilter system calls (-ff=very restricted)\n\
655 -i <file>\tRedirect stdin from <file>\n\
656 -m <size>\tLimit address space to <size> KB\n\
657 -o <file>\tRedirect stdout to <file>\n\
658 -s <sys>\tPermit the specified syscall (be careful)\n\
659 -s <sys>=<act>\tDefine action for the specified syscall (<act>=yes/no/file)\n\
660 -t <time>\tSet run time limit (seconds, fractions allowed)\n\
661 -T\t\tAllow syscalls for measuring run time\n\
662 -v\t\tBe verbose\n\
663 -w <time>\tSet wall clock time limit (seconds, fractions allowed)\n\
664 ");
665   exit(1);
666 }
667
668 int
669 main(int argc, char **argv)
670 {
671   int c;
672   uid_t uid;
673
674   while ((c = getopt(argc, argv, "a:c:efi:m:o:s:t:Tvw:")) >= 0)
675     switch (c)
676       {
677       case 'a':
678         file_access = atol(optarg);
679         break;
680       case 'c':
681         set_cwd = optarg;
682         break;
683       case 'e':
684         pass_environ = 1;
685         break;
686       case 'f':
687         filter_syscalls++;
688         break;
689       case 'i':
690         redir_stdin = optarg;
691         break;
692       case 'm':
693         memory_limit = atol(optarg);
694         break;
695       case 'o':
696         redir_stdout = optarg;
697         break;
698       case 's':
699         if (!set_action(optarg))
700           usage();
701         break;
702       case 't':
703         timeout = 1000*atof(optarg);
704         break;
705       case 'T':
706         syscall_action[__NR_times] = SC_YES;
707         break;
708       case 'v':
709         verbose++;
710         break;
711       case 'w':
712         wall_timeout = 1000*atof(optarg);
713         break;
714       default:
715         usage();
716       }
717   if (optind >= argc)
718     usage();
719
720   uid = geteuid();
721   if (setreuid(uid, uid) < 0)
722     die("setreuid: %m");
723   box_pid = fork();
724   if (box_pid < 0)
725     die("fork: %m");
726   if (!box_pid)
727     box_inside(argc-optind, argv+optind);
728   else
729     boxkeeper();
730   die("Internal error: fell over edge of the world");
731 }