OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__ |
6 #define SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__ |
7 | 7 |
8 #include <signal.h> | 8 #include <signal.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 | 12 |
| 13 #include "build/build_config.h" |
| 14 |
13 #include "base/macros.h" | 15 #include "base/macros.h" |
14 #include "sandbox/linux/bpf_dsl/trap_registry.h" | 16 #include "sandbox/linux/bpf_dsl/trap_registry.h" |
| 17 #include "sandbox/linux/system_headers/linux_signal.h" |
15 #include "sandbox/sandbox_export.h" | 18 #include "sandbox/sandbox_export.h" |
16 | 19 |
17 namespace sandbox { | 20 namespace sandbox { |
18 | 21 |
19 // The Trap class allows a BPF filter program to branch out to user space by | 22 // The Trap class allows a BPF filter program to branch out to user space by |
20 // raising a SIGSYS signal. | 23 // raising a SIGSYS signal. |
21 // N.B.: This class does not perform any synchronization operations. If | 24 // N.B.: This class does not perform any synchronization operations. If |
22 // modifications are made to any of the traps, it is the caller's | 25 // modifications are made to any of the traps, it is the caller's |
23 // responsibility to ensure that this happens in a thread-safe fashion. | 26 // responsibility to ensure that this happens in a thread-safe fashion. |
24 // Preferably, that means that no other threads should be running at that | 27 // Preferably, that means that no other threads should be running at that |
(...skipping 25 matching lines...) Expand all Loading... |
50 typedef std::map<TrapKey, uint16_t> TrapIds; | 53 typedef std::map<TrapKey, uint16_t> TrapIds; |
51 | 54 |
52 // Our constructor is private. A shared global instance is created | 55 // Our constructor is private. A shared global instance is created |
53 // automatically as needed. | 56 // automatically as needed. |
54 Trap(); | 57 Trap(); |
55 | 58 |
56 // The destructor is unimplemented as destroying this object would | 59 // The destructor is unimplemented as destroying this object would |
57 // break subsequent system calls that trigger a SIGSYS. | 60 // break subsequent system calls that trigger a SIGSYS. |
58 ~Trap() = delete; | 61 ~Trap() = delete; |
59 | 62 |
60 static void SigSysAction(int nr, siginfo_t* info, void* void_context); | 63 static void SigSysAction(int nr, linux_siginfo_t* info, void* void_context); |
61 | 64 |
62 // Make sure that SigSys is not inlined in order to get slightly better crash | 65 // Make sure that SigSys is not inlined in order to get slightly better crash |
63 // dumps. | 66 // dumps. |
64 void SigSys(int nr, siginfo_t* info, void* void_context) | 67 void SigSys(int nr, linux_siginfo_t* info, void* void_context) |
65 __attribute__((noinline)); | 68 __attribute__((noinline)); |
| 69 |
66 // We have a global singleton that handles all of our SIGSYS traps. This | 70 // We have a global singleton that handles all of our SIGSYS traps. This |
67 // variable must never be deallocated after it has been set up initially, as | 71 // variable must never be deallocated after it has been set up initially, as |
68 // there is no way to reset in-kernel BPF filters that generate SIGSYS | 72 // there is no way to reset in-kernel BPF filters that generate SIGSYS |
69 // events. | 73 // events. |
70 static Trap* global_trap_; | 74 static Trap* global_trap_; |
71 | 75 |
72 TrapIds trap_ids_; // Maps from TrapKeys to numeric ids | 76 TrapIds trap_ids_; // Maps from TrapKeys to numeric ids |
73 TrapKey* trap_array_; // Array of TrapKeys indexed by ids | 77 TrapKey* trap_array_; // Array of TrapKeys indexed by ids |
74 size_t trap_array_size_; // Currently used size of array | 78 size_t trap_array_size_; // Currently used size of array |
75 size_t trap_array_capacity_; // Currently allocated capacity of array | 79 size_t trap_array_capacity_; // Currently allocated capacity of array |
76 bool has_unsafe_traps_; // Whether unsafe traps have been enabled | 80 bool has_unsafe_traps_; // Whether unsafe traps have been enabled |
77 | 81 |
78 // Copying and assigning is unimplemented. It doesn't make sense for a | 82 // Copying and assigning is unimplemented. It doesn't make sense for a |
79 // singleton. | 83 // singleton. |
80 DISALLOW_COPY_AND_ASSIGN(Trap); | 84 DISALLOW_COPY_AND_ASSIGN(Trap); |
81 }; | 85 }; |
82 | 86 |
83 } // namespace sandbox | 87 } // namespace sandbox |
84 | 88 |
85 #endif // SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__ | 89 #endif // SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__ |
OLD | NEW |