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

Side by Side Diff: sandbox/linux/syscall_broker/broker_process.cc

Issue 701443004: Linux sandbox: change the return type of HandleRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add blank line in header file. Created 6 years, 1 month 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
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 "sandbox/linux/syscall_broker/broker_process.h" 5 #include "sandbox/linux/syscall_broker/broker_process.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <signal.h> 8 #include <signal.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 10 matching lines...) Expand all
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "base/posix/eintr_wrapper.h" 23 #include "base/posix/eintr_wrapper.h"
24 #include "base/process/process_metrics.h" 24 #include "base/process/process_metrics.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "sandbox/linux/syscall_broker/broker_client.h" 26 #include "sandbox/linux/syscall_broker/broker_client.h"
27 #include "sandbox/linux/syscall_broker/broker_host.h" 27 #include "sandbox/linux/syscall_broker/broker_host.h"
28 28
29 namespace sandbox { 29 namespace sandbox {
30 30
31 namespace syscall_broker {
32
31 BrokerProcess::BrokerProcess(int denied_errno, 33 BrokerProcess::BrokerProcess(int denied_errno,
32 const std::vector<std::string>& allowed_r_files, 34 const std::vector<std::string>& allowed_r_files,
33 const std::vector<std::string>& allowed_w_files, 35 const std::vector<std::string>& allowed_w_files,
34 bool fast_check_in_client, 36 bool fast_check_in_client,
35 bool quiet_failures_for_tests) 37 bool quiet_failures_for_tests)
36 : initialized_(false), 38 : initialized_(false),
37 is_child_(false), 39 is_child_(false),
38 fast_check_in_client_(fast_check_in_client), 40 fast_check_in_client_(fast_check_in_client),
39 quiet_failures_for_tests_(quiet_failures_for_tests), 41 quiet_failures_for_tests_(quiet_failures_for_tests),
40 broker_pid_(-1), 42 broker_pid_(-1),
41 policy_(denied_errno, allowed_r_files, allowed_w_files), 43 policy_(denied_errno, allowed_r_files, allowed_w_files),
42 ipc_socketpair_(-1) { 44 ipc_socketpair_(-1) {
43 } 45 }
44 46
45 BrokerProcess::~BrokerProcess() { 47 BrokerProcess::~BrokerProcess() {
46 if (initialized_ && ipc_socketpair_ != -1) { 48 if (initialized_) {
47 // Closing the socket should be enough to notify the child to die, 49 if (ipc_socketpair_ != -1) {
48 // unless it has been duplicated. 50 // Closing the socket should be enough to notify the child to die,
49 PCHECK(0 == IGNORE_EINTR(close(ipc_socketpair_))); 51 // unless it has been duplicated.
52 CloseChannel();
53 }
50 PCHECK(0 == kill(broker_pid_, SIGKILL)); 54 PCHECK(0 == kill(broker_pid_, SIGKILL));
51 siginfo_t process_info; 55 siginfo_t process_info;
52 // Reap the child. 56 // Reap the child.
53 int ret = HANDLE_EINTR(waitid(P_PID, broker_pid_, &process_info, WEXITED)); 57 int ret = HANDLE_EINTR(waitid(P_PID, broker_pid_, &process_info, WEXITED));
54 PCHECK(0 == ret); 58 PCHECK(0 == ret);
55 } 59 }
56 } 60 }
57 61
58 bool BrokerProcess::Init( 62 bool BrokerProcess::Init(
59 const base::Callback<bool(void)>& broker_process_init_callback) { 63 const base::Callback<bool(void)>& broker_process_init_callback) {
(...skipping 18 matching lines...) Expand all
78 } 82 }
79 if (child_pid) { 83 if (child_pid) {
80 // We are the parent and we have just forked our broker process. 84 // We are the parent and we have just forked our broker process.
81 close(socket_pair[0]); 85 close(socket_pair[0]);
82 // We should only be able to write to the IPC channel. We'll always send 86 // We should only be able to write to the IPC channel. We'll always send
83 // a new file descriptor to receive the reply on. 87 // a new file descriptor to receive the reply on.
84 shutdown(socket_pair[1], SHUT_RD); 88 shutdown(socket_pair[1], SHUT_RD);
85 ipc_socketpair_ = socket_pair[1]; 89 ipc_socketpair_ = socket_pair[1];
86 is_child_ = false; 90 is_child_ = false;
87 broker_pid_ = child_pid; 91 broker_pid_ = child_pid;
88 broker_client_.reset( 92 broker_client_.reset(new BrokerClient(policy_, ipc_socketpair_,
89 new syscall_broker::BrokerClient(policy_, 93 fast_check_in_client_,
90 ipc_socketpair_, 94 quiet_failures_for_tests_));
91 fast_check_in_client_,
92 quiet_failures_for_tests_));
93 initialized_ = true; 95 initialized_ = true;
94 return true; 96 return true;
95 } else { 97 } else {
96 // We are the broker. 98 // We are the broker.
97 close(socket_pair[1]); 99 close(socket_pair[1]);
98 // We should only be able to read from this IPC channel. We will send our 100 // We should only be able to read from this IPC channel. We will send our
99 // replies on a new file descriptor attached to the requests. 101 // replies on a new file descriptor attached to the requests.
100 shutdown(socket_pair[0], SHUT_WR); 102 shutdown(socket_pair[0], SHUT_WR);
101 ipc_socketpair_ = socket_pair[0]; 103 ipc_socketpair_ = socket_pair[0];
102 is_child_ = true; 104 is_child_ = true;
103 CHECK(broker_process_init_callback.Run()); 105 CHECK(broker_process_init_callback.Run());
104 syscall_broker::BrokerHost broker_host(policy_, ipc_socketpair_); 106 BrokerHost broker_host(policy_, ipc_socketpair_);
105 initialized_ = true; 107 initialized_ = true;
106 for (;;) { 108 for (;;) {
107 broker_host.HandleRequest(); 109 switch (broker_host.HandleRequest()) {
110 case BrokerHost::RequestStatus::LOST_CLIENT:
111 _exit(1);
112 case BrokerHost::RequestStatus::SUCCESS:
113 case BrokerHost::RequestStatus::FAILURE:
114 continue;
115 }
108 } 116 }
109 _exit(1); 117 _exit(1);
110 } 118 }
111 NOTREACHED(); 119 NOTREACHED();
112 } 120 }
113 121
122 void BrokerProcess::CloseChannel() {
123 CHECK_NE(-1, ipc_socketpair_);
124 PCHECK(0 == IGNORE_EINTR(close(ipc_socketpair_)));
125 ipc_socketpair_ = -1;
126 }
127
114 int BrokerProcess::Access(const char* pathname, int mode) const { 128 int BrokerProcess::Access(const char* pathname, int mode) const {
115 RAW_CHECK(initialized_); 129 RAW_CHECK(initialized_);
116 return broker_client_->Access(pathname, mode); 130 return broker_client_->Access(pathname, mode);
117 } 131 }
118 132
119 int BrokerProcess::Open(const char* pathname, int flags) const { 133 int BrokerProcess::Open(const char* pathname, int flags) const {
120 RAW_CHECK(initialized_); 134 RAW_CHECK(initialized_);
121 return broker_client_->Open(pathname, flags); 135 return broker_client_->Open(pathname, flags);
122 } 136 }
123 137
138 } // namespace syscall_broker
139
124 } // namespace sandbox. 140 } // namespace sandbox.
OLDNEW
« no previous file with comments | « sandbox/linux/syscall_broker/broker_process.h ('k') | sandbox/linux/syscall_broker/broker_process_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698