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

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

Issue 23960006: Linux Sandbox: LOG error if a previous SIGSYS handler exists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't zero old_sa. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 #include <errno.h> 5 #include <errno.h>
6 #include <signal.h> 6 #include <signal.h>
7 #include <string.h> 7 #include <string.h>
8 #include <sys/prctl.h> 8 #include <sys/prctl.h>
9 #include <sys/syscall.h> 9 #include <sys/syscall.h>
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 void SetIsInSigHandler() { 55 void SetIsInSigHandler() {
56 sigset_t mask; 56 sigset_t mask;
57 if (sigemptyset(&mask) || 57 if (sigemptyset(&mask) ||
58 sigaddset(&mask, SIGBUS) || 58 sigaddset(&mask, SIGBUS) ||
59 sigprocmask(SIG_BLOCK, &mask, NULL)) { 59 sigprocmask(SIG_BLOCK, &mask, NULL)) {
60 SANDBOX_DIE("Failed to block SIGBUS"); 60 SANDBOX_DIE("Failed to block SIGBUS");
61 } 61 }
62 } 62 }
63 63
64 bool IsDefaultSignalAction(const struct sigaction& sa) {
65 if (sa.sa_flags & SA_SIGINFO ||
66 sa.sa_handler != SIG_DFL) {
67 return false;
68 }
69 return true;
70 }
71
64 } // namespace 72 } // namespace
65 73
66 namespace playground2 { 74 namespace playground2 {
67 75
68 Trap::Trap() 76 Trap::Trap()
69 : trap_array_(NULL), 77 : trap_array_(NULL),
70 trap_array_size_(0), 78 trap_array_size_(0),
71 trap_array_capacity_(0), 79 trap_array_capacity_(0),
72 has_unsafe_traps_(false) { 80 has_unsafe_traps_(false) {
73 // Set new SIGSYS handler 81 // Set new SIGSYS handler
74 struct sigaction sa = { }; 82 struct sigaction sa = { };
75 sa.sa_sigaction = SigSysAction; 83 sa.sa_sigaction = SigSysAction;
76 sa.sa_flags = SA_SIGINFO | SA_NODEFER; 84 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
77 if (sigaction(SIGSYS, &sa, NULL) < 0) { 85 struct sigaction old_sa;
86 if (sigaction(SIGSYS, &sa, &old_sa) < 0) {
78 SANDBOX_DIE("Failed to configure SIGSYS handler"); 87 SANDBOX_DIE("Failed to configure SIGSYS handler");
79 } 88 }
80 89
90 if (!IsDefaultSignalAction(old_sa)) {
91 // TODO(jln): make this FATAL, at least in DEBUG mode.
92 LOG(ERROR) << "Existing signal handler when trying to install SIGSYS";
93 }
94
81 // Unmask SIGSYS 95 // Unmask SIGSYS
82 sigset_t mask; 96 sigset_t mask;
83 if (sigemptyset(&mask) || 97 if (sigemptyset(&mask) ||
84 sigaddset(&mask, SIGSYS) || 98 sigaddset(&mask, SIGSYS) ||
85 sigprocmask(SIG_UNBLOCK, &mask, NULL)) { 99 sigprocmask(SIG_UNBLOCK, &mask, NULL)) {
86 SANDBOX_DIE("Failed to configure SIGSYS handler"); 100 SANDBOX_DIE("Failed to configure SIGSYS handler");
87 } 101 }
88 } 102 }
89 103
90 Trap *Trap::GetInstance() { 104 Trap *Trap::GetInstance() {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (global_trap_ && id > 0 && id <= global_trap_->trap_array_size_) { 352 if (global_trap_ && id > 0 && id <= global_trap_->trap_array_size_) {
339 return global_trap_->trap_array_[id - 1]; 353 return global_trap_->trap_array_[id - 1];
340 } else { 354 } else {
341 return ErrorCode(); 355 return ErrorCode();
342 } 356 }
343 } 357 }
344 358
345 Trap *Trap::global_trap_; 359 Trap *Trap::global_trap_;
346 360
347 } // namespace playground2 361 } // namespace playground2
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698