| 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 <dlfcn.h> | 5 #include <dlfcn.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <pthread.h> | 7 #include <pthread.h> |
| 8 #include <stdio.h> | 8 #include <stdio.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 <sys/wait.h> | 12 #include <sys/wait.h> |
| 13 #include <unistd.h> | 13 #include <unistd.h> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/eintr_wrapper.h" | 17 #include "base/eintr_wrapper.h" |
| 18 #include "base/file_path.h" | 18 #include "base/file_path.h" |
| 19 #include "base/hash_tables.h" | 19 #include "base/hash_tables.h" |
| 20 #include "base/linux_util.h" | 20 #include "base/linux_util.h" |
| 21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/pickle.h" | 22 #include "base/pickle.h" |
| 23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
| 24 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
| 25 #include "base/rand_util_c.h" | |
| 26 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
| 27 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 28 #include "crypto/nss_util.h" | 27 #include "crypto/nss_util.h" |
| 29 #include "content/common/font_config_ipc_linux.h" | 28 #include "content/common/font_config_ipc_linux.h" |
| 30 #include "content/common/pepper_plugin_registry.h" | 29 #include "content/common/pepper_plugin_registry.h" |
| 31 #include "content/common/sandbox_methods_linux.h" | 30 #include "content/common/sandbox_methods_linux.h" |
| 32 #include "content/common/seccomp_sandbox.h" | 31 #include "content/common/seccomp_sandbox.h" |
| 33 #include "content/common/unix_domain_socket_posix.h" | 32 #include "content/common/unix_domain_socket_posix.h" |
| 34 #include "content/common/zygote_commands_linux.h" | 33 #include "content/common/zygote_commands_linux.h" |
| 35 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // means that we cannot override fopen() directly here. Instead the | 332 // means that we cannot override fopen() directly here. Instead the |
| 334 // the code below defines fopen_override() function with asm name | 333 // the code below defines fopen_override() function with asm name |
| 335 // "fopen", so that all references to fopen() will resolve to this | 334 // "fopen", so that all references to fopen() will resolve to this |
| 336 // function. | 335 // function. |
| 337 __attribute__ ((__visibility__("default"))) | 336 __attribute__ ((__visibility__("default"))) |
| 338 FILE* fopen_override(const char* path, const char* mode) __asm__ ("fopen"); | 337 FILE* fopen_override(const char* path, const char* mode) __asm__ ("fopen"); |
| 339 | 338 |
| 340 __attribute__ ((__visibility__("default"))) | 339 __attribute__ ((__visibility__("default"))) |
| 341 FILE* fopen_override(const char* path, const char* mode) { | 340 FILE* fopen_override(const char* path, const char* mode) { |
| 342 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { | 341 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { |
| 343 int fd = HANDLE_EINTR(dup(GetUrandomFD())); | 342 int fd = HANDLE_EINTR(dup(base::GetUrandomFD())); |
| 344 if (fd < 0) { | 343 if (fd < 0) { |
| 345 PLOG(ERROR) << "dup() failed."; | 344 PLOG(ERROR) << "dup() failed."; |
| 346 return NULL; | 345 return NULL; |
| 347 } | 346 } |
| 348 return fdopen(fd, mode); | 347 return fdopen(fd, mode); |
| 349 } else { | 348 } else { |
| 350 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, | 349 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, |
| 351 InitLibcFileIOFunctions)); | 350 InitLibcFileIOFunctions)); |
| 352 return g_libc_fopen(path, mode); | 351 return g_libc_fopen(path, mode); |
| 353 } | 352 } |
| 354 } | 353 } |
| 355 | 354 |
| 356 __attribute__ ((__visibility__("default"))) | 355 __attribute__ ((__visibility__("default"))) |
| 357 FILE* fopen64(const char* path, const char* mode) { | 356 FILE* fopen64(const char* path, const char* mode) { |
| 358 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { | 357 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { |
| 359 int fd = HANDLE_EINTR(dup(GetUrandomFD())); | 358 int fd = HANDLE_EINTR(dup(base::GetUrandomFD())); |
| 360 if (fd < 0) { | 359 if (fd < 0) { |
| 361 PLOG(ERROR) << "dup() failed."; | 360 PLOG(ERROR) << "dup() failed."; |
| 362 return NULL; | 361 return NULL; |
| 363 } | 362 } |
| 364 return fdopen(fd, mode); | 363 return fdopen(fd, mode); |
| 365 } else { | 364 } else { |
| 366 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, | 365 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, |
| 367 InitLibcFileIOFunctions)); | 366 InitLibcFileIOFunctions)); |
| 368 return g_libc_fopen64(path, mode); | 367 return g_libc_fopen64(path, mode); |
| 369 } | 368 } |
| 370 } | 369 } |
| 371 | 370 |
| 372 // stat() is subject to the same problem as fopen(), so we have to use | 371 // stat() is subject to the same problem as fopen(), so we have to use |
| 373 // the same trick to override it. | 372 // the same trick to override it. |
| 374 __attribute__ ((__visibility__("default"))) | 373 __attribute__ ((__visibility__("default"))) |
| 375 int xstat_override(int version, | 374 int xstat_override(int version, |
| 376 const char *path, | 375 const char *path, |
| 377 struct stat *buf) __asm__ ("__xstat"); | 376 struct stat *buf) __asm__ ("__xstat"); |
| 378 | 377 |
| 379 __attribute__ ((__visibility__("default"))) | 378 __attribute__ ((__visibility__("default"))) |
| 380 int xstat_override(int version, const char *path, struct stat *buf) { | 379 int xstat_override(int version, const char *path, struct stat *buf) { |
| 381 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { | 380 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { |
| 382 int result = __fxstat(version, GetUrandomFD(), buf); | 381 int result = __fxstat(version, base::GetUrandomFD(), buf); |
| 383 return result; | 382 return result; |
| 384 } else { | 383 } else { |
| 385 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, | 384 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, |
| 386 InitLibcFileIOFunctions)); | 385 InitLibcFileIOFunctions)); |
| 387 return g_libc_xstat(version, path, buf); | 386 return g_libc_xstat(version, path, buf); |
| 388 } | 387 } |
| 389 } | 388 } |
| 390 | 389 |
| 391 __attribute__ ((__visibility__("default"))) | 390 __attribute__ ((__visibility__("default"))) |
| 392 int xstat64_override(int version, | 391 int xstat64_override(int version, |
| 393 const char *path, | 392 const char *path, |
| 394 struct stat64 *buf) __asm__ ("__xstat64"); | 393 struct stat64 *buf) __asm__ ("__xstat64"); |
| 395 | 394 |
| 396 __attribute__ ((__visibility__("default"))) | 395 __attribute__ ((__visibility__("default"))) |
| 397 int xstat64_override(int version, const char *path, struct stat64 *buf) { | 396 int xstat64_override(int version, const char *path, struct stat64 *buf) { |
| 398 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { | 397 if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { |
| 399 int result = __fxstat64(version, GetUrandomFD(), buf); | 398 int result = __fxstat64(version, base::GetUrandomFD(), buf); |
| 400 return result; | 399 return result; |
| 401 } else { | 400 } else { |
| 402 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, | 401 CHECK_EQ(0, pthread_once(&g_libc_file_io_funcs_guard, |
| 403 InitLibcFileIOFunctions)); | 402 InitLibcFileIOFunctions)); |
| 404 CHECK(g_libc_xstat64); | 403 CHECK(g_libc_xstat64); |
| 405 return g_libc_xstat64(version, path, buf); | 404 return g_libc_xstat64(version, path, buf); |
| 406 } | 405 } |
| 407 } | 406 } |
| 408 | 407 |
| 409 #endif // !ADDRESS_SANITIZER | 408 #endif // !ADDRESS_SANITIZER |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 } | 687 } |
| 689 } | 688 } |
| 690 #endif // SECCOMP_SANDBOX | 689 #endif // SECCOMP_SANDBOX |
| 691 | 690 |
| 692 Zygote zygote(sandbox_flags, forkdelegate, proc_fd_for_seccomp); | 691 Zygote zygote(sandbox_flags, forkdelegate, proc_fd_for_seccomp); |
| 693 // This function call can return multiple times, once per fork(). | 692 // This function call can return multiple times, once per fork(). |
| 694 return zygote.ProcessRequests(); | 693 return zygote.ProcessRequests(); |
| 695 } | 694 } |
| 696 | 695 |
| 697 } // namespace content | 696 } // namespace content |
| OLD | NEW |