| 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 21 matching lines...) Expand all Loading... |
| 32 int fds[2]; | 32 int fds[2]; |
| 33 // We use SOCK_SEQPACKET rather than SOCK_DGRAM to prevent the renderer from | 33 // We use SOCK_SEQPACKET rather than SOCK_DGRAM to prevent the renderer from |
| 34 // sending datagrams to other sockets on the system. The sandbox may prevent | 34 // sending datagrams to other sockets on the system. The sandbox may prevent |
| 35 // the renderer from calling socket() to create new sockets, but it'll still | 35 // the renderer from calling socket() to create new sockets, but it'll still |
| 36 // inherit some sockets. With AF_UNIX+SOCK_DGRAM, it can call sendmsg to send | 36 // inherit some sockets. With AF_UNIX+SOCK_DGRAM, it can call sendmsg to send |
| 37 // a datagram to any (abstract) socket on the same system. With | 37 // a datagram to any (abstract) socket on the same system. With |
| 38 // SOCK_SEQPACKET, this is prevented. | 38 // SOCK_SEQPACKET, this is prevented. |
| 39 CHECK(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); | 39 CHECK(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); |
| 40 | 40 |
| 41 renderer_socket_ = fds[0]; | 41 renderer_socket_ = fds[0]; |
| 42 // The SandboxIPC client is not expected to read from |renderer_socket_|. |
| 43 // Instead, it reads from a temporary socket sent with the request. |
| 44 PCHECK(0 == shutdown(renderer_socket_, SHUT_RD)) << "shutdown"; |
| 45 |
| 42 const int browser_socket = fds[1]; | 46 const int browser_socket = fds[1]; |
| 47 // The SandboxIPC handler is not expected to write to |browser_socket|. |
| 48 // Instead, it replies on a temporary socket provided by the caller. |
| 49 PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown"; |
| 43 | 50 |
| 44 int pipefds[2]; | 51 int pipefds[2]; |
| 45 CHECK(0 == pipe(pipefds)); | 52 CHECK(0 == pipe(pipefds)); |
| 46 const int child_lifeline_fd = pipefds[0]; | 53 const int child_lifeline_fd = pipefds[0]; |
| 47 childs_lifeline_fd_ = pipefds[1]; | 54 childs_lifeline_fd_ = pipefds[1]; |
| 48 | 55 |
| 49 // We need to be monothreaded before we fork(). | 56 // We need to be monothreaded before we fork(). |
| 50 #if !defined(THREAD_SANITIZER) | 57 #if !defined(THREAD_SANITIZER) |
| 51 DCHECK_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); | 58 DCHECK_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); |
| 52 #endif // !defined(THREAD_SANITIZER) | 59 #endif // !defined(THREAD_SANITIZER) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 66 RenderSandboxHostLinux::~RenderSandboxHostLinux() { | 73 RenderSandboxHostLinux::~RenderSandboxHostLinux() { |
| 67 if (initialized_) { | 74 if (initialized_) { |
| 68 if (IGNORE_EINTR(close(renderer_socket_)) < 0) | 75 if (IGNORE_EINTR(close(renderer_socket_)) < 0) |
| 69 PLOG(ERROR) << "close"; | 76 PLOG(ERROR) << "close"; |
| 70 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) | 77 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) |
| 71 PLOG(ERROR) << "close"; | 78 PLOG(ERROR) << "close"; |
| 72 } | 79 } |
| 73 } | 80 } |
| 74 | 81 |
| 75 } // namespace content | 82 } // namespace content |
| OLD | NEW |