| 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 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 5 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
| 6 | 6 |
| 7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // sending datagrams to other sockets on the system. The sandbox may prevent | 30 // sending datagrams to other sockets on the system. The sandbox may prevent |
| 31 // the renderer from calling socket() to create new sockets, but it'll still | 31 // the renderer from calling socket() to create new sockets, but it'll still |
| 32 // inherit some sockets. With AF_UNIX+SOCK_DGRAM, it can call sendmsg to send | 32 // inherit some sockets. With AF_UNIX+SOCK_DGRAM, it can call sendmsg to send |
| 33 // a datagram to any (abstract) socket on the same system. With | 33 // a datagram to any (abstract) socket on the same system. With |
| 34 // SOCK_SEQPACKET, this is prevented. | 34 // SOCK_SEQPACKET, this is prevented. |
| 35 CHECK(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); | 35 CHECK(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); |
| 36 | 36 |
| 37 renderer_socket_ = fds[0]; | 37 renderer_socket_ = fds[0]; |
| 38 // The SandboxIPC client is not expected to read from |renderer_socket_|. | 38 // The SandboxIPC client is not expected to read from |renderer_socket_|. |
| 39 // Instead, it reads from a temporary socket sent with the request. | 39 // Instead, it reads from a temporary socket sent with the request. |
| 40 PCHECK(0 == shutdown(renderer_socket_, SHUT_RD)) << "shutdown"; | 40 // shutdown |
| 41 CHECK(0 == shutdown(renderer_socket_, SHUT_RD)); |
| 41 | 42 |
| 42 const int browser_socket = fds[1]; | 43 const int browser_socket = fds[1]; |
| 43 // The SandboxIPC handler is not expected to write to |browser_socket|. | 44 // The SandboxIPC handler is not expected to write to |browser_socket|. |
| 44 // Instead, it replies on a temporary socket provided by the caller. | 45 // Instead, it replies on a temporary socket provided by the caller. |
| 45 PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown"; | 46 // shutdown |
| 47 CHECK(0 == shutdown(browser_socket, SHUT_WR)); |
| 46 | 48 |
| 47 int pipefds[2]; | 49 int pipefds[2]; |
| 48 CHECK(0 == pipe(pipefds)); | 50 CHECK(0 == pipe(pipefds)); |
| 49 const int child_lifeline_fd = pipefds[0]; | 51 const int child_lifeline_fd = pipefds[0]; |
| 50 childs_lifeline_fd_ = pipefds[1]; | 52 childs_lifeline_fd_ = pipefds[1]; |
| 51 | 53 |
| 52 ipc_handler_.reset( | 54 ipc_handler_.reset( |
| 53 new SandboxIPCHandler(child_lifeline_fd, browser_socket)); | 55 new SandboxIPCHandler(child_lifeline_fd, browser_socket)); |
| 54 ipc_thread_.reset( | 56 ipc_thread_.reset( |
| 55 new base::DelegateSimpleThread(ipc_handler_.get(), "sandbox_ipc_thread")); | 57 new base::DelegateSimpleThread(ipc_handler_.get(), "sandbox_ipc_thread")); |
| 56 ipc_thread_->Start(); | 58 ipc_thread_->Start(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 bool RenderSandboxHostLinux::ShutdownIPCChannel() { | 61 bool RenderSandboxHostLinux::ShutdownIPCChannel() { |
| 60 return IGNORE_EINTR(close(childs_lifeline_fd_)) == 0; | 62 return IGNORE_EINTR(close(childs_lifeline_fd_)) == 0; |
| 61 } | 63 } |
| 62 | 64 |
| 63 RenderSandboxHostLinux::~RenderSandboxHostLinux() { | 65 RenderSandboxHostLinux::~RenderSandboxHostLinux() { |
| 64 if (initialized_) { | 66 if (initialized_) { |
| 65 if (!ShutdownIPCChannel()) | 67 if (!ShutdownIPCChannel()) |
| 66 LOG(ERROR) << "ShutdownIPCChannel failed"; | 68 LOG(ERROR) << "ShutdownIPCChannel failed"; |
| 67 if (IGNORE_EINTR(close(renderer_socket_)) < 0) | 69 if (IGNORE_EINTR(close(renderer_socket_)) < 0) |
| 68 PLOG(ERROR) << "close"; | 70 PLOG(ERROR) << "close"; |
| 69 | 71 |
| 70 ipc_thread_->Join(); | 72 ipc_thread_->Join(); |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 | 75 |
| 74 } // namespace content | 76 } // namespace content |
| OLD | NEW |