Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/loader/nacl_listener.h" | 5 #include "components/nacl/loader/nacl_listener.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "components/nacl/common/nacl_renderer_messages.h" | 22 #include "components/nacl/common/nacl_renderer_messages.h" |
| 23 #include "components/nacl/loader/nacl_ipc_adapter.h" | 23 #include "components/nacl/loader/nacl_ipc_adapter.h" |
| 24 #include "components/nacl/loader/nacl_validation_db.h" | 24 #include "components/nacl/loader/nacl_validation_db.h" |
| 25 #include "components/nacl/loader/nacl_validation_query.h" | 25 #include "components/nacl/loader/nacl_validation_query.h" |
| 26 #include "ipc/ipc_channel_handle.h" | 26 #include "ipc/ipc_channel_handle.h" |
| 27 #include "ipc/ipc_switches.h" | 27 #include "ipc/ipc_switches.h" |
| 28 #include "ipc/ipc_sync_channel.h" | 28 #include "ipc/ipc_sync_channel.h" |
| 29 #include "ipc/ipc_sync_message_filter.h" | 29 #include "ipc/ipc_sync_message_filter.h" |
| 30 #include "native_client/src/public/chrome_main.h" | 30 #include "native_client/src/public/chrome_main.h" |
| 31 #include "native_client/src/public/nacl_app.h" | 31 #include "native_client/src/public/nacl_app.h" |
| 32 #include "native_client/src/public/nacl_desc.h" | |
| 32 #include "native_client/src/public/nacl_file_info.h" | 33 #include "native_client/src/public/nacl_file_info.h" |
| 34 #include "native_client/src/trusted/desc/nacl_desc_io.h" | |
| 33 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | 35 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 36 #include "native_client/src/trusted/validator/rich_file_info.h" | |
|
Mark Seaborn
2014/10/14 17:37:24
This isn't needed, is it?
teravest
2014/10/14 18:15:00
Nope, removed.
| |
| 34 | 37 |
| 35 #if defined(OS_POSIX) | 38 #if defined(OS_POSIX) |
| 36 #include "base/file_descriptor_posix.h" | 39 #include "base/file_descriptor_posix.h" |
| 37 #endif | 40 #endif |
| 38 | 41 |
| 39 #if defined(OS_LINUX) | 42 #if defined(OS_LINUX) |
| 40 #include "content/public/common/child_process_sandbox_support_linux.h" | 43 #include "content/public/common/child_process_sandbox_support_linux.h" |
| 41 #endif | 44 #endif |
| 42 | 45 |
| 43 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 return result; | 179 return result; |
| 177 } | 180 } |
| 178 | 181 |
| 179 virtual void SetKnownToValidate(const std::string& signature) override { | 182 virtual void SetKnownToValidate(const std::string& signature) override { |
| 180 // Caching is optional: NaCl will still work correctly if the IPC fails. | 183 // Caching is optional: NaCl will still work correctly if the IPC fails. |
| 181 if (!listener_->Send(new NaClProcessMsg_SetKnownToValidate(signature))) { | 184 if (!listener_->Send(new NaClProcessMsg_SetKnownToValidate(signature))) { |
| 182 LOG(ERROR) << "Failed to update NaCl validation cache."; | 185 LOG(ERROR) << "Failed to update NaCl validation cache."; |
| 183 } | 186 } |
| 184 } | 187 } |
| 185 | 188 |
| 186 // This is the "old" code path for resolving file tokens. It's only | 189 // This function is no longer used. |
| 187 // used for resolving the main nexe. | |
| 188 // TODO(teravest): Remove this. | |
| 189 virtual bool ResolveFileToken(struct NaClFileToken* file_token, | 190 virtual bool ResolveFileToken(struct NaClFileToken* file_token, |
| 190 int32* fd, std::string* path) override { | 191 int32* fd, std::string* path) override { |
| 191 *fd = -1; | 192 CHECK(false); |
| 192 *path = ""; | 193 return false; |
| 193 if (!NaClFileTokenIsValid(file_token)) { | |
| 194 return false; | |
| 195 } | |
| 196 IPC::PlatformFileForTransit ipc_fd = IPC::InvalidPlatformFileForTransit(); | |
| 197 base::FilePath ipc_path; | |
| 198 if (!listener_->Send(new NaClProcessMsg_ResolveFileToken(file_token->lo, | |
| 199 file_token->hi, | |
| 200 &ipc_fd, | |
| 201 &ipc_path))) { | |
| 202 return false; | |
| 203 } | |
| 204 if (ipc_fd == IPC::InvalidPlatformFileForTransit()) { | |
| 205 return false; | |
| 206 } | |
| 207 base::PlatformFile handle = | |
| 208 IPC::PlatformFileForTransitToPlatformFile(ipc_fd); | |
| 209 #if defined(OS_WIN) | |
| 210 // On Windows, valid handles are 32 bit unsigned integers so this is safe. | |
| 211 *fd = reinterpret_cast<uintptr_t>(handle); | |
| 212 #else | |
| 213 *fd = handle; | |
| 214 #endif | |
| 215 // It doesn't matter if the path is invalid UTF8 as long as it's consistent | |
| 216 // and unforgeable. | |
| 217 *path = ipc_path.AsUTF8Unsafe(); | |
| 218 return true; | |
| 219 } | 194 } |
| 220 | 195 |
| 221 private: | 196 private: |
| 222 // The listener never dies, otherwise this might be a dangling reference. | 197 // The listener never dies, otherwise this might be a dangling reference. |
| 223 NaClListener* listener_; | 198 NaClListener* listener_; |
| 224 }; | 199 }; |
| 225 | 200 |
| 226 | 201 |
| 227 NaClListener::NaClListener() : shutdown_event_(true, false), | 202 NaClListener::NaClListener() : shutdown_event_(true, false), |
| 228 io_thread_("NaCl_IOThread"), | 203 io_thread_("NaCl_IOThread"), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 #if defined(OS_WIN) | 422 #if defined(OS_WIN) |
| 448 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 423 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
| 449 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 424 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
| 450 args->debug_stub_server_port_selected_handler_func = | 425 args->debug_stub_server_port_selected_handler_func = |
| 451 DebugStubPortSelectedHandler; | 426 DebugStubPortSelectedHandler; |
| 452 #endif | 427 #endif |
| 453 #if defined(OS_LINUX) | 428 #if defined(OS_LINUX) |
| 454 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 429 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
| 455 #endif | 430 #endif |
| 456 | 431 |
| 457 NaClFileInfo nexe_file_info; | |
| 458 base::PlatformFile nexe_file = IPC::PlatformFileForTransitToPlatformFile( | 432 base::PlatformFile nexe_file = IPC::PlatformFileForTransitToPlatformFile( |
| 459 params.nexe_file); | 433 params.nexe_file); |
| 434 | |
| 435 // If nexe_file_path is valid, that metadata has to be added to the desc and | |
| 436 // it can be marked safe to mmap (since it came from the browser). | |
| 437 if (!params.nexe_file_path.empty()) { | |
|
Mark Seaborn
2014/10/14 17:37:24
Hmm, if this check were omitted, would this be ins
teravest
2014/10/14 18:15:00
Sounds good, I'll mail out a NaCl change that does
| |
| 438 std::string file_path_str = params.nexe_file_path.AsUTF8Unsafe(); | |
| 439 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file, | |
| 440 file_path_str.c_str()); | |
| 441 } else { | |
| 442 int desc; | |
| 460 #if defined(OS_WIN) | 443 #if defined(OS_WIN) |
| 461 nexe_file_info.desc = | 444 desc = _open_osfhandle(reinterpret_cast<intptr_t>(nexe_file), |
| 462 _open_osfhandle(reinterpret_cast<intptr_t>(nexe_file), | 445 _O_RDONLY | _O_BINARY); |
| 463 _O_RDONLY | _O_BINARY); | |
| 464 #elif defined(OS_POSIX) | 446 #elif defined(OS_POSIX) |
| 465 nexe_file_info.desc = nexe_file; | 447 desc = nexe_file; |
| 466 #else | 448 #else |
| 467 #error Unsupported target platform. | 449 #error Unsupported target platform. |
| 468 #endif | 450 #endif |
| 469 nexe_file_info.file_token.lo = params.nexe_token_lo; | 451 args->nexe_desc = NaClDescIoDescFromDescAllocCtor(desc, NACL_ABI_O_RDONLY); |
| 470 nexe_file_info.file_token.hi = params.nexe_token_hi; | 452 } |
| 471 args->nexe_desc = NaClDescIoFromFileInfo(nexe_file_info, NACL_ABI_O_RDONLY); | |
| 472 | 453 |
| 473 int exit_status; | 454 int exit_status; |
| 474 if (!NaClChromeMainStart(nap, args, &exit_status)) | 455 if (!NaClChromeMainStart(nap, args, &exit_status)) |
| 475 NaClExit(1); | 456 NaClExit(1); |
| 476 | 457 |
| 477 // Report the plugin's exit status if the application started successfully. | 458 // Report the plugin's exit status if the application started successfully. |
| 478 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); | 459 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); |
| 479 NaClExit(exit_status); | 460 NaClExit(exit_status); |
| 480 } | 461 } |
| 481 | 462 |
| 482 void NaClListener::ResolveFileToken( | 463 void NaClListener::ResolveFileToken( |
| 483 uint64_t token_lo, | 464 uint64_t token_lo, |
| 484 uint64_t token_hi, | 465 uint64_t token_hi, |
| 485 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { | 466 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { |
| 486 if (!Send(new NaClProcessMsg_ResolveFileTokenAsync(token_lo, token_hi))) { | 467 if (!Send(new NaClProcessMsg_ResolveFileTokenAsync(token_lo, token_hi))) { |
| 487 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); | 468 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); |
| 488 return; | 469 return; |
| 489 } | 470 } |
| 490 resolved_cb_ = cb; | 471 resolved_cb_ = cb; |
| 491 } | 472 } |
| 492 | 473 |
| 493 void NaClListener::OnFileTokenResolved( | 474 void NaClListener::OnFileTokenResolved( |
| 494 uint64_t token_lo, | 475 uint64_t token_lo, |
| 495 uint64_t token_hi, | 476 uint64_t token_hi, |
| 496 IPC::PlatformFileForTransit ipc_fd, | 477 IPC::PlatformFileForTransit ipc_fd, |
| 497 base::FilePath file_path) { | 478 base::FilePath file_path) { |
| 498 resolved_cb_.Run(ipc_fd, file_path); | 479 resolved_cb_.Run(ipc_fd, file_path); |
| 499 resolved_cb_.Reset(); | 480 resolved_cb_.Reset(); |
| 500 } | 481 } |
| OLD | NEW |