blob: b29a541aedd57b9158a5dca8bd69d726703d363d [file] [log] [blame]
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -07001/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
Ben Chanfc420602014-04-01 14:00:36 -07006/* These header files need to be included before asm/siginfo.h such that
7 * pid_t, timer_t, and clock_t are defined. */
8#include <stdlib.h>
9#include <unistd.h>
10
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070011#include <asm/siginfo.h>
12#define __have_siginfo_t 1
13#define __have_sigval_t 1
14#define __have_sigevent_t 1
15
16#include <signal.h>
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070017#include <string.h>
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070018
Jorge Lucangeli Obesa21c8fc2015-07-15 16:22:34 -070019#include "signal_handler.h"
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070020
21#include "util.h"
22
23struct local_sigsys {
24 void *ip;
25 int nr;
26 unsigned int arch;
27};
28
Mike Frysinger33d051a2018-05-30 16:41:10 -040029void log_sigsys_handler(int sig attribute_unused, siginfo_t *info,
Mike Frysingerd9ef07c2018-05-30 16:51:36 -040030 void *void_context attribute_unused)
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070031{
32 struct local_sigsys sigsys;
33 const char *syscall_name;
34 memcpy(&sigsys, &info->_sifields, sizeof(sigsys));
35 syscall_name = lookup_syscall_name(sigsys.nr);
36
Jeff Vander Stoep00c57912016-02-03 15:48:06 -080037 if (syscall_name)
38 die("blocked syscall: %s", syscall_name);
39 else
Mike Frysinger33d051a2018-05-30 16:41:10 -040040 die("blocked syscall: %d", sigsys.nr);
Jeff Vander Stoep00c57912016-02-03 15:48:06 -080041
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070042 /*
43 * We trapped on a syscall that should have killed the process.
44 * This should never ever return, but we're paranoid.
45 */
46 for (;;)
47 _exit(1);
48}
49
50int install_sigsys_handler()
51{
52 int ret = 0;
53 struct sigaction act;
54 sigset_t mask;
55
56 memset(&act, 0, sizeof(act));
57 act.sa_sigaction = &log_sigsys_handler;
58 act.sa_flags = SA_SIGINFO;
59
60 sigemptyset(&mask);
61 sigaddset(&mask, SIGSYS);
62
63 ret = sigaction(SIGSYS, &act, NULL);
64 if (ret < 0)
65 return ret;
66
67 ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);
68 if (ret < 0)
69 return ret;
70
71 return 0;
72}