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/zygote_host/zygote_host_impl_linux.h" | 5 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include "base/base_switches.h" | 14 #include "base/base_switches.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/environment.h" | 16 #include "base/environment.h" |
17 #include "base/files/file_enumerator.h" | 17 #include "base/files/file_enumerator.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/files/scoped_file.h" | 19 #include "base/files/scoped_file.h" |
20 #include "base/linux_util.h" | 20 #include "base/linux_util.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/memory/linked_ptr.h" | 22 #include "base/memory/linked_ptr.h" |
23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
24 #include "base/memory/scoped_vector.h" | |
25 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
26 #include "base/metrics/sparse_histogram.h" | 25 #include "base/metrics/sparse_histogram.h" |
27 #include "base/path_service.h" | 26 #include "base/path_service.h" |
28 #include "base/posix/eintr_wrapper.h" | 27 #include "base/posix/eintr_wrapper.h" |
29 #include "base/posix/unix_domain_socket_linux.h" | 28 #include "base/posix/unix_domain_socket_linux.h" |
30 #include "base/process/launch.h" | 29 #include "base/process/launch.h" |
31 #include "base/process/memory.h" | 30 #include "base/process/memory.h" |
32 #include "base/process/process_handle.h" | 31 #include "base/process/process_handle.h" |
33 #include "base/strings/string_number_conversions.h" | 32 #include "base/strings/string_number_conversions.h" |
34 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
(...skipping 21 matching lines...) Expand all Loading... |
56 | 55 |
57 namespace { | 56 namespace { |
58 | 57 |
59 // Receive a fixed message on fd and return the sender's PID. | 58 // Receive a fixed message on fd and return the sender's PID. |
60 // Returns true if the message received matches the expected message. | 59 // Returns true if the message received matches the expected message. |
61 bool ReceiveFixedMessage(int fd, | 60 bool ReceiveFixedMessage(int fd, |
62 const char* expect_msg, | 61 const char* expect_msg, |
63 size_t expect_len, | 62 size_t expect_len, |
64 base::ProcessId* sender_pid) { | 63 base::ProcessId* sender_pid) { |
65 char buf[expect_len + 1]; | 64 char buf[expect_len + 1]; |
66 ScopedVector<base::ScopedFD> fds_vec; | 65 std::vector<base::ScopedFD> fds_vec; |
67 | 66 |
68 const ssize_t len = base::UnixDomainSocket::RecvMsgWithPid( | 67 const ssize_t len = base::UnixDomainSocket::RecvMsgWithPid( |
69 fd, buf, sizeof(buf), &fds_vec, sender_pid); | 68 fd, buf, sizeof(buf), &fds_vec, sender_pid); |
70 if (static_cast<size_t>(len) != expect_len) | 69 if (static_cast<size_t>(len) != expect_len) |
71 return false; | 70 return false; |
72 if (memcmp(buf, expect_msg, expect_len) != 0) | 71 if (memcmp(buf, expect_msg, expect_len) != 0) |
73 return false; | 72 return false; |
74 if (!fds_vec.empty()) | 73 if (!fds_vec.empty()) |
75 return false; | 74 return false; |
76 return true; | 75 return true; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 pid_t pid; | 355 pid_t pid; |
357 { | 356 { |
358 base::AutoLock lock(control_lock_); | 357 base::AutoLock lock(control_lock_); |
359 if (!SendMessage(pickle, &fds)) | 358 if (!SendMessage(pickle, &fds)) |
360 return base::kNullProcessHandle; | 359 return base::kNullProcessHandle; |
361 mapping.reset(); | 360 mapping.reset(); |
362 peer_sock.reset(); | 361 peer_sock.reset(); |
363 | 362 |
364 { | 363 { |
365 char buf[sizeof(kZygoteChildPingMessage) + 1]; | 364 char buf[sizeof(kZygoteChildPingMessage) + 1]; |
366 ScopedVector<base::ScopedFD> recv_fds; | 365 std::vector<base::ScopedFD> recv_fds; |
367 base::ProcessId real_pid; | 366 base::ProcessId real_pid; |
368 | 367 |
369 ssize_t n = base::UnixDomainSocket::RecvMsgWithPid( | 368 ssize_t n = base::UnixDomainSocket::RecvMsgWithPid( |
370 my_sock.get(), buf, sizeof(buf), &recv_fds, &real_pid); | 369 my_sock.get(), buf, sizeof(buf), &recv_fds, &real_pid); |
371 if (n != sizeof(kZygoteChildPingMessage) || | 370 if (n != sizeof(kZygoteChildPingMessage) || |
372 0 != memcmp(buf, | 371 0 != memcmp(buf, |
373 kZygoteChildPingMessage, | 372 kZygoteChildPingMessage, |
374 sizeof(kZygoteChildPingMessage))) { | 373 sizeof(kZygoteChildPingMessage))) { |
375 // Zygote children should still be trustworthy when they're supposed to | 374 // Zygote children should still be trustworthy when they're supposed to |
376 // ping us, so something's broken if we don't receive a valid ping. | 375 // ping us, so something's broken if we don't receive a valid ping. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 595 } |
597 | 596 |
598 if (!sandbox::Credentials::CanCreateProcessInNewUserNS()) { | 597 if (!sandbox::Credentials::CanCreateProcessInNewUserNS()) { |
599 return false; | 598 return false; |
600 } | 599 } |
601 | 600 |
602 return true; | 601 return true; |
603 } | 602 } |
604 | 603 |
605 } // namespace content | 604 } // namespace content |
OLD | NEW |