| 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/zygote/zygote_main.h" | 5 #include "content/zygote/zygote_main.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <openssl/crypto.h> | 9 #include <openssl/crypto.h> |
| 10 #include <openssl/rand.h> | 10 #include <openssl/rand.h> |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 struct tm* localtime_override(const time_t* timep) __asm__ ("localtime"); | 216 struct tm* localtime_override(const time_t* timep) __asm__ ("localtime"); |
| 217 | 217 |
| 218 __attribute__ ((__visibility__("default"))) | 218 __attribute__ ((__visibility__("default"))) |
| 219 struct tm* localtime_override(const time_t* timep) { | 219 struct tm* localtime_override(const time_t* timep) { |
| 220 if (g_am_zygote_or_renderer) { | 220 if (g_am_zygote_or_renderer) { |
| 221 static struct tm time_struct; | 221 static struct tm time_struct; |
| 222 static char timezone_string[64]; | 222 static char timezone_string[64]; |
| 223 ProxyLocaltimeCallToBrowser(*timep, &time_struct, timezone_string, | 223 ProxyLocaltimeCallToBrowser(*timep, &time_struct, timezone_string, |
| 224 sizeof(timezone_string)); | 224 sizeof(timezone_string)); |
| 225 return &time_struct; | 225 return &time_struct; |
| 226 } else { | 226 } |
| 227 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, | 227 |
| 228 InitLibcLocaltimeFunctions)); | 228 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, |
| 229 struct tm* res = g_libc_localtime(timep); | 229 InitLibcLocaltimeFunctions)); |
| 230 struct tm* res = g_libc_localtime(timep); |
| 230 #if defined(MEMORY_SANITIZER) | 231 #if defined(MEMORY_SANITIZER) |
| 231 if (res) __msan_unpoison(res, sizeof(*res)); | 232 if (res) __msan_unpoison(res, sizeof(*res)); |
| 232 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); | 233 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); |
| 233 #endif | 234 #endif |
| 234 return res; | 235 return res; |
| 235 } | |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Use same trick to override localtime64(), localtime_r() and localtime64_r(). | 238 // Use same trick to override localtime64(), localtime_r() and localtime64_r(). |
| 239 __attribute__ ((__visibility__("default"))) | 239 __attribute__ ((__visibility__("default"))) |
| 240 struct tm* localtime64_override(const time_t* timep) __asm__ ("localtime64"); | 240 struct tm* localtime64_override(const time_t* timep) __asm__ ("localtime64"); |
| 241 | 241 |
| 242 __attribute__ ((__visibility__("default"))) | 242 __attribute__ ((__visibility__("default"))) |
| 243 struct tm* localtime64_override(const time_t* timep) { | 243 struct tm* localtime64_override(const time_t* timep) { |
| 244 if (g_am_zygote_or_renderer) { | 244 if (g_am_zygote_or_renderer) { |
| 245 static struct tm time_struct; | 245 static struct tm time_struct; |
| 246 static char timezone_string[64]; | 246 static char timezone_string[64]; |
| 247 ProxyLocaltimeCallToBrowser(*timep, &time_struct, timezone_string, | 247 ProxyLocaltimeCallToBrowser(*timep, &time_struct, timezone_string, |
| 248 sizeof(timezone_string)); | 248 sizeof(timezone_string)); |
| 249 return &time_struct; | 249 return &time_struct; |
| 250 } else { | 250 } |
| 251 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, | 251 |
| 252 InitLibcLocaltimeFunctions)); | 252 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, |
| 253 struct tm* res = g_libc_localtime64(timep); | 253 InitLibcLocaltimeFunctions)); |
| 254 struct tm* res = g_libc_localtime64(timep); |
| 254 #if defined(MEMORY_SANITIZER) | 255 #if defined(MEMORY_SANITIZER) |
| 255 if (res) __msan_unpoison(res, sizeof(*res)); | 256 if (res) __msan_unpoison(res, sizeof(*res)); |
| 256 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); | 257 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); |
| 257 #endif | 258 #endif |
| 258 return res; | 259 return res; |
| 259 } | |
| 260 } | 260 } |
| 261 | 261 |
| 262 __attribute__ ((__visibility__("default"))) | 262 __attribute__ ((__visibility__("default"))) |
| 263 struct tm* localtime_r_override(const time_t* timep, | 263 struct tm* localtime_r_override(const time_t* timep, |
| 264 struct tm* result) __asm__ ("localtime_r"); | 264 struct tm* result) __asm__ ("localtime_r"); |
| 265 | 265 |
| 266 __attribute__ ((__visibility__("default"))) | 266 __attribute__ ((__visibility__("default"))) |
| 267 struct tm* localtime_r_override(const time_t* timep, struct tm* result) { | 267 struct tm* localtime_r_override(const time_t* timep, struct tm* result) { |
| 268 if (g_am_zygote_or_renderer) { | 268 if (g_am_zygote_or_renderer) { |
| 269 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0); | 269 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0); |
| 270 return result; | 270 return result; |
| 271 } else { | 271 } |
| 272 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, | 272 |
| 273 InitLibcLocaltimeFunctions)); | 273 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, |
| 274 struct tm* res = g_libc_localtime_r(timep, result); | 274 InitLibcLocaltimeFunctions)); |
| 275 struct tm* res = g_libc_localtime_r(timep, result); |
| 275 #if defined(MEMORY_SANITIZER) | 276 #if defined(MEMORY_SANITIZER) |
| 276 if (res) __msan_unpoison(res, sizeof(*res)); | 277 if (res) __msan_unpoison(res, sizeof(*res)); |
| 277 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); | 278 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); |
| 278 #endif | 279 #endif |
| 279 return res; | 280 return res; |
| 280 } | |
| 281 } | 281 } |
| 282 | 282 |
| 283 __attribute__ ((__visibility__("default"))) | 283 __attribute__ ((__visibility__("default"))) |
| 284 struct tm* localtime64_r_override(const time_t* timep, | 284 struct tm* localtime64_r_override(const time_t* timep, |
| 285 struct tm* result) __asm__ ("localtime64_r"); | 285 struct tm* result) __asm__ ("localtime64_r"); |
| 286 | 286 |
| 287 __attribute__ ((__visibility__("default"))) | 287 __attribute__ ((__visibility__("default"))) |
| 288 struct tm* localtime64_r_override(const time_t* timep, struct tm* result) { | 288 struct tm* localtime64_r_override(const time_t* timep, struct tm* result) { |
| 289 if (g_am_zygote_or_renderer) { | 289 if (g_am_zygote_or_renderer) { |
| 290 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0); | 290 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0); |
| 291 return result; | 291 return result; |
| 292 } else { | 292 } |
| 293 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, | 293 |
| 294 InitLibcLocaltimeFunctions)); | 294 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard, |
| 295 struct tm* res = g_libc_localtime64_r(timep, result); | 295 InitLibcLocaltimeFunctions)); |
| 296 struct tm* res = g_libc_localtime64_r(timep, result); |
| 296 #if defined(MEMORY_SANITIZER) | 297 #if defined(MEMORY_SANITIZER) |
| 297 if (res) __msan_unpoison(res, sizeof(*res)); | 298 if (res) __msan_unpoison(res, sizeof(*res)); |
| 298 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); | 299 if (res->tm_zone) __msan_unpoison_string(res->tm_zone); |
| 299 #endif | 300 #endif |
| 300 return res; | 301 return res; |
| 301 } | |
| 302 } | 302 } |
| 303 | 303 |
| 304 #if defined(ENABLE_PLUGINS) | 304 #if defined(ENABLE_PLUGINS) |
| 305 // Loads the (native) libraries but does not initialize them (i.e., does not | 305 // Loads the (native) libraries but does not initialize them (i.e., does not |
| 306 // call PPP_InitializeModule). This is needed by the zygote on Linux to get | 306 // call PPP_InitializeModule). This is needed by the zygote on Linux to get |
| 307 // access to the plugins before entering the sandbox. | 307 // access to the plugins before entering the sandbox. |
| 308 void PreloadPepperPlugins() { | 308 void PreloadPepperPlugins() { |
| 309 std::vector<PepperPluginInfo> plugins; | 309 std::vector<PepperPluginInfo> plugins; |
| 310 ComputePepperPluginList(&plugins); | 310 ComputePepperPluginList(&plugins); |
| 311 for (size_t i = 0; i < plugins.size(); ++i) { | 311 for (const auto& plugin : plugins) { |
| 312 if (!plugins[i].is_internal) { | 312 if (!plugin.is_internal) { |
| 313 base::NativeLibraryLoadError error; | 313 base::NativeLibraryLoadError error; |
| 314 base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path, | 314 base::NativeLibrary library = base::LoadNativeLibrary(plugin.path, |
| 315 &error); | 315 &error); |
| 316 VLOG_IF(1, !library) << "Unable to load plugin " | 316 VLOG_IF(1, !library) << "Unable to load plugin " |
| 317 << plugins[i].path.value() << " " | 317 << plugin.path.value() << " " |
| 318 << error.ToString(); | 318 << error.ToString(); |
| 319 | 319 |
| 320 (void)library; // Prevent release-mode warning. | 320 (void)library; // Prevent release-mode warning. |
| 321 } | 321 } |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 #endif | 324 #endif |
| 325 | 325 |
| 326 // This function triggers the static and lazy construction of objects that need | 326 // This function triggers the static and lazy construction of objects that need |
| 327 // to be created before imposing the sandbox. | 327 // to be created before imposing the sandbox. |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; | 653 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; |
| 654 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); | 654 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); |
| 655 | 655 |
| 656 Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children, | 656 Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children, |
| 657 extra_fds); | 657 extra_fds); |
| 658 // This function call can return multiple times, once per fork(). | 658 // This function call can return multiple times, once per fork(). |
| 659 return zygote.ProcessRequests(); | 659 return zygote.ProcessRequests(); |
| 660 } | 660 } |
| 661 | 661 |
| 662 } // namespace content | 662 } // namespace content |
| OLD | NEW |