Index: content/browser/zygote_main_linux.cc |
diff --git a/content/browser/zygote_main_linux.cc b/content/browser/zygote_main_linux.cc |
index 020d7771ca6ed9cfe8351dcba1098d10b8a47f84..cb1cda5532eed7c1f285df86db7bc67fec4db58d 100644 |
--- a/content/browser/zygote_main_linux.cc |
+++ b/content/browser/zygote_main_linux.cc |
@@ -7,6 +7,7 @@ |
#include <dlfcn.h> |
#include <fcntl.h> |
#include <pthread.h> |
+#include <stdio.h> |
#include <sys/socket.h> |
#include <sys/stat.h> |
#include <sys/types.h> |
@@ -25,6 +26,7 @@ |
#include "base/pickle.h" |
#include "base/process_util.h" |
#include "base/rand_util.h" |
+#include "base/rand_util_c.h" |
#include "base/sys_info.h" |
#include "build/build_config.h" |
#include "crypto/nss_util.h" |
@@ -64,6 +66,8 @@ static const int kMagicSandboxIPCDescriptor = 5; |
static const int kZygoteIdDescriptor = 7; |
static bool g_suid_sandbox_active = false; |
+static char kUrandomDevPath[] = "/dev/urandom"; |
agl
2012/04/10 15:18:13
const
Sergey Ulanov
2012/04/10 17:21:01
Done.
|
+ |
#if defined(SECCOMP_SANDBOX) |
static int g_proc_fd = -1; |
#endif |
@@ -632,11 +636,16 @@ static bool g_am_zygote_or_renderer = false; |
typedef struct tm* (*LocaltimeFunction)(const time_t* timep); |
typedef struct tm* (*LocaltimeRFunction)(const time_t* timep, |
struct tm* result); |
+typedef FILE* (*FopenFunction)(const char* path, const char* mode); |
static pthread_once_t g_libc_localtime_funcs_guard = PTHREAD_ONCE_INIT; |
static LocaltimeFunction g_libc_localtime; |
static LocaltimeRFunction g_libc_localtime_r; |
+static pthread_once_t g_libc_fopen_funcs_guard = PTHREAD_ONCE_INIT; |
+static FopenFunction g_libc_fopen; |
+static FopenFunction g_libc_fopen64; |
+ |
static void InitLibcLocaltimeFunctions() { |
g_libc_localtime = reinterpret_cast<LocaltimeFunction>( |
dlsym(RTLD_NEXT, "localtime")); |
@@ -686,6 +695,61 @@ struct tm* localtime_r(const time_t* timep, struct tm* result) { |
} |
} |
+static void InitLibcFopenFunctions() { |
+ g_libc_fopen = reinterpret_cast<FopenFunction>( |
+ dlsym(RTLD_NEXT, "fopen")); |
agl
2012/04/10 15:18:13
nit: indentation here should be four spaces from t
Sergey Ulanov
2012/04/10 17:21:01
Done.
|
+ g_libc_fopen64 = reinterpret_cast<FopenFunction>( |
+ dlsym(RTLD_NEXT, "fopen64")); |
+ |
+ if (!g_libc_fopen || !g_libc_fopen64) { |
+ LOG(ERROR) << "Failed to get fopen() from glibc."; |
+ } |
+} |
+ |
+// fopen() and fopen64() are intercepted here so that NSS can open |
+// /dev/urandom to seed it's random number generator. NSS is used by |
+// remoting in the sendbox. |
+ |
+// fopen() call may be redirected to fopen64() in stdio.h using |
+// __REDIRECT(), which sets asm name for fopen() to "fopen64". This |
+// means that we cannot override fopen() directly here. Instead the |
+// the code below defines fopen_override() function with asm name |
+// "fopen", so that all references to fopen() will resolve to this |
+// function. |
+__attribute__ ((__visibility__("default"))) |
+FILE* fopen_override(const char* path, const char* mode) __asm__ ("fopen"); |
agl
2012/04/10 15:18:13
nit: blank line between these.
Sergey Ulanov
2012/04/10 17:21:01
Done.
|
+__attribute__ ((__visibility__("default"))) |
+FILE* fopen_override(const char* path, const char* mode) { |
+ if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { |
+ int fd = dup(GetUrandomFD()); |
agl
2012/04/10 15:18:13
needs to be wrapped with HANDLE_EINTR
Sergey Ulanov
2012/04/10 17:21:01
Done.
|
+ if (fd < 0) { |
+ LOG(ERROR) << "dup() failed."; |
agl
2012/04/10 15:18:13
PLOG
Sergey Ulanov
2012/04/10 17:21:01
Done.
|
+ return NULL; |
+ } |
+ return fdopen(fd, mode); |
+ } else { |
+ CHECK_EQ(0, pthread_once(&g_libc_fopen_funcs_guard, |
+ InitLibcFopenFunctions)); |
+ return g_libc_fopen(path, mode); |
+ } |
+} |
+ |
+__attribute__ ((__visibility__("default"))) |
+FILE* fopen64(const char* path, const char* mode) { |
+ if (g_am_zygote_or_renderer && strcmp(path, kUrandomDevPath) == 0) { |
+ int fd = dup(GetUrandomFD()); |
agl
2012/04/10 15:18:13
needs to be wrapped with HANDLE_EINTR
Sergey Ulanov
2012/04/10 17:21:01
Done.
|
+ if (fd < 0) { |
+ PLOG(ERROR) << "dup() failed."; |
+ return NULL; |
+ } |
+ return fdopen(fd, mode); |
+ } else { |
+ CHECK_EQ(0, pthread_once(&g_libc_fopen_funcs_guard, |
+ InitLibcFopenFunctions)); |
+ return g_libc_fopen64(path, mode); |
+ } |
+} |
+ |
#endif // !CHROMIUM_SELINUX |
// This function triggers the static and lazy construction of objects that need |