Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: sandbox/linux/seccomp-bpf/trap.h

Issue 937303005: Revert of bpf_dsl: decouple PolicyCompiler from Syscall (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('k') | sandbox/linux/seccomp-bpf/trap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 16 matching lines...) Expand all
27 class SANDBOX_EXPORT Trap : public bpf_dsl::TrapRegistry { 27 class SANDBOX_EXPORT Trap : public bpf_dsl::TrapRegistry {
28 public: 28 public:
29 uint16_t Add(TrapFnc fnc, const void* aux, bool safe) override; 29 uint16_t Add(TrapFnc fnc, const void* aux, bool safe) override;
30 30
31 bool EnableUnsafeTraps() override; 31 bool EnableUnsafeTraps() override;
32 32
33 // Registry returns the trap registry used by Trap's SIGSYS handler, 33 // Registry returns the trap registry used by Trap's SIGSYS handler,
34 // creating it if necessary. 34 // creating it if necessary.
35 static bpf_dsl::TrapRegistry* Registry(); 35 static bpf_dsl::TrapRegistry* Registry();
36 36
37 // SandboxDebuggingAllowedByUser returns whether the 37 // Registers a new trap handler and sets up the appropriate SIGSYS handler
38 // "CHROME_SANDBOX_DEBUGGING" environment variable is set. 38 // as needed.
39 static bool SandboxDebuggingAllowedByUser(); 39 // N.B.: This makes a permanent state change. Traps cannot be unregistered,
40 // as that would break existing BPF filters that are still active.
41 // TODO(mdempsky): Deprecated; remove.
42 static uint16_t MakeTrap(TrapFnc fnc, const void* aux, bool safe);
43
44 // Enables support for unsafe traps in the SIGSYS signal handler. This is a
45 // one-way fuse. It works in conjunction with the BPF compiler emitting code
46 // that unconditionally allows system calls, if they have a magic return
47 // address (i.e. SandboxSyscall(-1)).
48 // Once unsafe traps are enabled, the sandbox is essentially compromised.
49 // But this is still a very useful feature for debugging purposes. Use with
50 // care. This feature is availably only if enabled by the user (see above).
51 // Returns "true", if unsafe traps were turned on.
52 // TODO(mdempsky): Deprecated; remove.
53 static bool EnableUnsafeTrapsInSigSysHandler();
40 54
41 private: 55 private:
42 struct TrapKey { 56 struct TrapKey {
43 TrapKey() : fnc(NULL), aux(NULL), safe(false) {} 57 TrapKey() : fnc(NULL), aux(NULL), safe(false) {}
44 TrapKey(TrapFnc f, const void* a, bool s) : fnc(f), aux(a), safe(s) {} 58 TrapKey(TrapFnc f, const void* a, bool s) : fnc(f), aux(a), safe(s) {}
45 TrapFnc fnc; 59 TrapFnc fnc;
46 const void* aux; 60 const void* aux;
47 bool safe; 61 bool safe;
48 bool operator<(const TrapKey&) const; 62 bool operator<(const TrapKey&) const;
49 }; 63 };
50 typedef std::map<TrapKey, uint16_t> TrapIds; 64 typedef std::map<TrapKey, uint16_t> TrapIds;
51 65
52 // Our constructor is private. A shared global instance is created 66 // Our constructor is private. A shared global instance is created
53 // automatically as needed. 67 // automatically as needed.
54 Trap(); 68 Trap();
55 69
56 // The destructor is unimplemented. Don't ever attempt to destruct this 70 // The destructor is unimplemented. Don't ever attempt to destruct this
57 // object. It'll break subsequent system calls that trigger a SIGSYS. 71 // object. It'll break subsequent system calls that trigger a SIGSYS.
58 ~Trap(); 72 ~Trap();
59 73
60 static void SigSysAction(int nr, siginfo_t* info, void* void_context); 74 static void SigSysAction(int nr, siginfo_t* info, void* void_context);
61 75
62 // Make sure that SigSys is not inlined in order to get slightly better crash 76 // Make sure that SigSys is not inlined in order to get slightly better crash
63 // dumps. 77 // dumps.
64 void SigSys(int nr, siginfo_t* info, void* void_context) 78 void SigSys(int nr, siginfo_t* info, void* void_context)
65 __attribute__((noinline)); 79 __attribute__((noinline));
80 bool SandboxDebuggingAllowedByUser() const;
81
66 // We have a global singleton that handles all of our SIGSYS traps. This 82 // 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 83 // 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 84 // there is no way to reset in-kernel BPF filters that generate SIGSYS
69 // events. 85 // events.
70 static Trap* global_trap_; 86 static Trap* global_trap_;
71 87
72 TrapIds trap_ids_; // Maps from TrapKeys to numeric ids 88 TrapIds trap_ids_; // Maps from TrapKeys to numeric ids
73 TrapKey* trap_array_; // Array of TrapKeys indexed by ids 89 TrapKey* trap_array_; // Array of TrapKeys indexed by ids
74 size_t trap_array_size_; // Currently used size of array 90 size_t trap_array_size_; // Currently used size of array
75 size_t trap_array_capacity_; // Currently allocated capacity of array 91 size_t trap_array_capacity_; // Currently allocated capacity of array
76 bool has_unsafe_traps_; // Whether unsafe traps have been enabled 92 bool has_unsafe_traps_; // Whether unsafe traps have been enabled
77 93
78 // Copying and assigning is unimplemented. It doesn't make sense for a 94 // Copying and assigning is unimplemented. It doesn't make sense for a
79 // singleton. 95 // singleton.
80 DISALLOW_COPY_AND_ASSIGN(Trap); 96 DISALLOW_COPY_AND_ASSIGN(Trap);
81 }; 97 };
82 98
83 } // namespace sandbox 99 } // namespace sandbox
84 100
85 #endif // SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__ 101 #endif // SANDBOX_LINUX_SECCOMP_BPF_TRAP_H__
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('k') | sandbox/linux/seccomp-bpf/trap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698