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

Side by Side Diff: content/browser/zygote_main_linux.cc

Issue 10031027: Redirect fopen("/dev/urandom") so that NSS can properly seed it's RNG. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/zygote_host_impl_linux.h" 5 #include "content/browser/zygote_host_impl_linux.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <stdio.h>
10 #include <sys/socket.h> 11 #include <sys/socket.h>
11 #include <sys/stat.h> 12 #include <sys/stat.h>
12 #include <sys/types.h> 13 #include <sys/types.h>
13 #include <sys/wait.h> 14 #include <sys/wait.h>
14 #include <unistd.h> 15 #include <unistd.h>
15 16
16 #include "base/basictypes.h" 17 #include "base/basictypes.h"
17 #include "base/command_line.h" 18 #include "base/command_line.h"
18 #include "base/eintr_wrapper.h" 19 #include "base/eintr_wrapper.h"
19 #include "base/file_path.h" 20 #include "base/file_path.h"
20 #include "base/file_util.h" 21 #include "base/file_util.h"
21 #include "base/global_descriptors_posix.h" 22 #include "base/global_descriptors_posix.h"
22 #include "base/hash_tables.h" 23 #include "base/hash_tables.h"
23 #include "base/linux_util.h" 24 #include "base/linux_util.h"
24 #include "base/memory/scoped_ptr.h" 25 #include "base/memory/scoped_ptr.h"
25 #include "base/pickle.h" 26 #include "base/pickle.h"
26 #include "base/process_util.h" 27 #include "base/process_util.h"
27 #include "base/rand_util.h" 28 #include "base/rand_util.h"
29 #include "base/rand_util_c.h"
28 #include "base/sys_info.h" 30 #include "base/sys_info.h"
29 #include "build/build_config.h" 31 #include "build/build_config.h"
30 #include "crypto/nss_util.h" 32 #include "crypto/nss_util.h"
31 #include "content/common/chrome_descriptors.h" 33 #include "content/common/chrome_descriptors.h"
32 #include "content/common/font_config_ipc_linux.h" 34 #include "content/common/font_config_ipc_linux.h"
33 #include "content/common/pepper_plugin_registry.h" 35 #include "content/common/pepper_plugin_registry.h"
34 #include "content/common/sandbox_methods_linux.h" 36 #include "content/common/sandbox_methods_linux.h"
35 #include "content/common/seccomp_sandbox.h" 37 #include "content/common/seccomp_sandbox.h"
36 #include "content/common/set_process_title.h" 38 #include "content/common/set_process_title.h"
37 #include "content/common/unix_domain_socket_posix.h" 39 #include "content/common/unix_domain_socket_posix.h"
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 // Our first attempt involved some assembly to patch the GOT of the current 627 // Our first attempt involved some assembly to patch the GOT of the current
626 // module. This worked, but was platform specific and doesn't catch the case 628 // module. This worked, but was platform specific and doesn't catch the case
627 // where a library makes a call rather than current module. 629 // where a library makes a call rather than current module.
628 // 630 //
629 // We also considered patching the function in place, but this would again by 631 // We also considered patching the function in place, but this would again by
630 // platform specific and the above technique seems to work well enough. 632 // platform specific and the above technique seems to work well enough.
631 633
632 typedef struct tm* (*LocaltimeFunction)(const time_t* timep); 634 typedef struct tm* (*LocaltimeFunction)(const time_t* timep);
633 typedef struct tm* (*LocaltimeRFunction)(const time_t* timep, 635 typedef struct tm* (*LocaltimeRFunction)(const time_t* timep,
634 struct tm* result); 636 struct tm* result);
637 typedef FILE* (*FopenFunction)(const char* path, const char* mode);
635 638
636 static pthread_once_t g_libc_localtime_funcs_guard = PTHREAD_ONCE_INIT; 639 static pthread_once_t g_libc_localtime_funcs_guard = PTHREAD_ONCE_INIT;
637 static LocaltimeFunction g_libc_localtime; 640 static LocaltimeFunction g_libc_localtime;
638 static LocaltimeRFunction g_libc_localtime_r; 641 static LocaltimeRFunction g_libc_localtime_r;
639 642
643 static pthread_once_t g_libc_fopen_funcs_guard = PTHREAD_ONCE_INIT;
644 static FopenFunction g_libc_fopen;
645 static FopenFunction g_libc_fopen64;
646
640 static void InitLibcLocaltimeFunctions() { 647 static void InitLibcLocaltimeFunctions() {
641 g_libc_localtime = reinterpret_cast<LocaltimeFunction>( 648 g_libc_localtime = reinterpret_cast<LocaltimeFunction>(
642 dlsym(RTLD_NEXT, "localtime")); 649 dlsym(RTLD_NEXT, "localtime"));
643 g_libc_localtime_r = reinterpret_cast<LocaltimeRFunction>( 650 g_libc_localtime_r = reinterpret_cast<LocaltimeRFunction>(
644 dlsym(RTLD_NEXT, "localtime_r")); 651 dlsym(RTLD_NEXT, "localtime_r"));
645 652
646 if (!g_libc_localtime || !g_libc_localtime_r) { 653 if (!g_libc_localtime || !g_libc_localtime_r) {
647 // http://code.google.com/p/chromium/issues/detail?id=16800 654 // http://code.google.com/p/chromium/issues/detail?id=16800
648 // 655 //
649 // Nvidia's libGL.so overrides dlsym for an unknown reason and replaces 656 // Nvidia's libGL.so overrides dlsym for an unknown reason and replaces
(...skipping 29 matching lines...) Expand all
679 if (g_am_zygote_or_renderer) { 686 if (g_am_zygote_or_renderer) {
680 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0); 687 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0);
681 return result; 688 return result;
682 } else { 689 } else {
683 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, 690 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard,
684 InitLibcLocaltimeFunctions)); 691 InitLibcLocaltimeFunctions));
685 return g_libc_localtime_r(timep, result); 692 return g_libc_localtime_r(timep, result);
686 } 693 }
687 } 694 }
688 695
696 static void InitLibcFopenFunctions() {
697 g_libc_fopen = reinterpret_cast<FopenFunction>(
698 dlsym(RTLD_NEXT, "fopen"));
699 g_libc_fopen64 = reinterpret_cast<FopenFunction>(
700 dlsym(RTLD_NEXT, "fopen64"));
701
702 if (!g_libc_fopen || !g_libc_fopen64) {
703 LOG(ERROR) << "Failed to get fopen() from glibc.";
704 }
705 }
706
707 __attribute__ ((__visibility__("default")))
708 FILE* fopen(const char* path, const char* mode) __asm__ ("fopen");
709 FILE* fopen(const char* path, const char* mode) {
710 if (g_am_zygote_or_renderer && strcmp(path, "/dev/urandom") == 0) {
Ben Chan 2012/04/10 02:17:15 static const char kDevUrandomFile[] = "/dev/urando
Sergey Ulanov 2012/04/10 03:02:53 How would that be better than strcmp()? It would a
Ben Chan 2012/04/10 03:24:41 strcmp should be fine. But I think it's still good
Sergey Ulanov 2012/04/10 06:03:38 Done.
711 int fd = dup(GetUrandomFD());
712 if (fd < 0) {
713 LOG(ERROR) << "dup() failed.";
714 return NULL;
715 }
716 return fdopen(fd, mode);
717 } else {
718 CHECK_EQ(0, pthread_once(&g_libc_fopen_funcs_guard,
719 InitLibcFopenFunctions));
720 return g_libc_fopen(path, mode);
721 }
722 }
723
724 __attribute__ ((__visibility__("default")))
725 FILE* fopen64(const char* path, const char* mode) {
726 if (g_am_zygote_or_renderer && strcmp(path, "/dev/urandom") == 0) {
727 int fd = dup(GetUrandomFD());
728 if (fd < 0) {
729 PLOG(ERROR) << "dup() failed.";
730 return NULL;
731 }
732 return fdopen(fd, mode);
Ben Chan 2012/04/10 02:17:15 indentation
Sergey Ulanov 2012/04/10 03:02:53 Done.
733 } else {
734 CHECK_EQ(0, pthread_once(&g_libc_fopen_funcs_guard,
735 InitLibcFopenFunctions));
736 return g_libc_fopen64(path, mode);
737 }
738 }
739
689 #endif // !CHROMIUM_SELINUX 740 #endif // !CHROMIUM_SELINUX
690 741
691 // This function triggers the static and lazy construction of objects that need 742 // This function triggers the static and lazy construction of objects that need
692 // to be created before imposing the sandbox. 743 // to be created before imposing the sandbox.
693 static void PreSandboxInit() { 744 static void PreSandboxInit() {
694 base::RandUint64(); 745 base::RandUint64();
695 746
696 base::SysInfo::MaxSharedMemorySize(); 747 base::SysInfo::MaxSharedMemorySize();
697 748
698 // ICU DateFormat class (used in base/time_format.cc) needs to get the 749 // ICU DateFormat class (used in base/time_format.cc) needs to get the
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 VLOG(1) << "Enabling experimental Seccomp sandbox."; 924 VLOG(1) << "Enabling experimental Seccomp sandbox.";
874 sandbox_flags |= ZygoteHostImpl::kSandboxSeccomp; 925 sandbox_flags |= ZygoteHostImpl::kSandboxSeccomp;
875 } 926 }
876 } 927 }
877 #endif // SECCOMP_SANDBOX 928 #endif // SECCOMP_SANDBOX
878 929
879 Zygote zygote(sandbox_flags, forkdelegate); 930 Zygote zygote(sandbox_flags, forkdelegate);
880 // This function call can return multiple times, once per fork(). 931 // This function call can return multiple times, once per fork().
881 return zygote.ProcessRequests(); 932 return zygote.ProcessRequests();
882 } 933 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698