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

Side by Side Diff: components/nacl/loader/nacl_ipc_adapter.cc

Issue 1010183002: SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip: test fix 1 Created 5 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
OLDNEW
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_ipc_adapter.h" 5 #include "components/nacl/loader/nacl_ipc_adapter.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
15 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
16 #include "base/tuple.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "ipc/ipc_channel.h" 18 #include "ipc/ipc_channel.h"
18 #include "ipc/ipc_platform_file.h" 19 #include "ipc/ipc_platform_file.h"
19 #include "native_client/src/public/nacl_desc.h" 20 #include "native_client/src/public/nacl_desc.h"
20 #include "native_client/src/trusted/desc/nacl_desc_base.h" 21 #include "native_client/src/trusted/desc/nacl_desc_base.h"
21 #include "native_client/src/trusted/desc/nacl_desc_custom.h" 22 #include "native_client/src/trusted/desc/nacl_desc_custom.h"
22 #include "native_client/src/trusted/desc/nacl_desc_imc_shm.h" 23 #include "native_client/src/trusted/desc/nacl_desc_imc_shm.h"
23 #include "native_client/src/trusted/desc/nacl_desc_io.h" 24 #include "native_client/src/trusted/desc/nacl_desc_io.h"
24 #include "native_client/src/trusted/desc/nacl_desc_quota.h" 25 #include "native_client/src/trusted/desc/nacl_desc_quota.h"
25 #include "native_client/src/trusted/desc/nacl_desc_quota_interface.h" 26 #include "native_client/src/trusted/desc/nacl_desc_quota_interface.h"
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 // descriptor received, we send the file token to the browser in 496 // descriptor received, we send the file token to the browser in
496 // exchange for a new file descriptor and file path information. 497 // exchange for a new file descriptor and file path information.
497 // That file descriptor can be used to construct a NaClDesc with 498 // That file descriptor can be used to construct a NaClDesc with
498 // identity-based validation caching. 499 // identity-based validation caching.
499 // 500 //
500 // We do not use file descriptors from the renderer with validation 501 // We do not use file descriptors from the renderer with validation
501 // caching; a compromised renderer should not be able to run 502 // caching; a compromised renderer should not be able to run
502 // arbitrary code in a plugin process. 503 // arbitrary code in a plugin process.
503 DCHECK(!resolve_file_token_cb_.is_null()); 504 DCHECK(!resolve_file_token_cb_.is_null());
504 505
505 // resolve_file_token_cb_ must be invoked from the main thread. 506 // resolve_file_token_cb_ must be invoked from the I/O thread.
506 resolve_file_token_cb_.Run( 507 resolve_file_token_cb_.Run(
507 token_lo, 508 token_lo,
508 token_hi, 509 token_hi,
509 base::Bind(&NaClIPCAdapter::OnFileTokenResolved, 510 base::Bind(&NaClIPCAdapter::SaveOpenResourceMessage,
510 this, 511 this,
511 msg)); 512 msg));
512 513
513 // In this case, we don't release the message to NaCl untrusted code 514 // In this case, we don't release the message to NaCl untrusted code
514 // immediately. We defer it until we get an async message back from the 515 // immediately. We defer it until we get an async message back from the
515 // browser process. 516 // browser process.
516 return true; 517 return true;
517 } 518 }
518 } 519 }
519 return RewriteMessage(msg, type); 520 return RewriteMessage(msg, type);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 // The file descriptor is at index 0. There's only ever one file 618 // The file descriptor is at index 0. There's only ever one file
618 // descriptor provided for this message type, so this will be correct. 619 // descriptor provided for this message type, so this will be correct.
619 new_msg->WriteInt(0); 620 new_msg->WriteInt(0);
620 621
621 // Write empty file tokens. 622 // Write empty file tokens.
622 new_msg->WriteUInt64(0); // token_lo 623 new_msg->WriteUInt64(0); // token_lo
623 new_msg->WriteUInt64(0); // token_hi 624 new_msg->WriteUInt64(0); // token_hi
624 return new_msg.Pass(); 625 return new_msg.Pass();
625 } 626 }
626 627
627 void NaClIPCAdapter::OnFileTokenResolved(const IPC::Message& orig_msg, 628 void NaClIPCAdapter::SaveOpenResourceMessage(
628 IPC::PlatformFileForTransit ipc_fd, 629 const IPC::Message& orig_msg,
629 base::FilePath file_path) { 630 IPC::PlatformFileForTransit ipc_fd,
631 base::FilePath file_path) {
630 // The path where an invalid ipc_fd is returned isn't currently 632 // The path where an invalid ipc_fd is returned isn't currently
631 // covered by any tests. 633 // covered by any tests.
632 if (ipc_fd == IPC::InvalidPlatformFileForTransit()) { 634 if (ipc_fd == IPC::InvalidPlatformFileForTransit()) {
633 // The file token didn't resolve successfully, so we give the 635 // The file token didn't resolve successfully, so we give the
634 // original FD to the client without making a validated NaClDesc. 636 // original FD to the client without making a validated NaClDesc.
635 // However, we must rewrite the message to clear the file tokens. 637 // However, we must rewrite the message to clear the file tokens.
636 PickleIterator iter = IPC::SyncMessage::GetDataIterator(&orig_msg); 638 PickleIterator iter = IPC::SyncMessage::GetDataIterator(&orig_msg);
637 ppapi::proxy::SerializedHandle sh; 639 ppapi::proxy::SerializedHandle sh;
638 640
639 // We know that this can be read safely; see the original read in 641 // We know that this can be read safely; see the original read in
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 782
781 void NaClIPCAdapter::CloseChannelOnIOThread() { 783 void NaClIPCAdapter::CloseChannelOnIOThread() {
782 io_thread_data_.channel_->Close(); 784 io_thread_data_.channel_->Close();
783 } 785 }
784 786
785 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) { 787 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) {
786 int id = IPC::SyncMessage::GetMessageId(*message.get()); 788 int id = IPC::SyncMessage::GetMessageId(*message.get());
787 DCHECK(io_thread_data_.pending_sync_msgs_.find(id) == 789 DCHECK(io_thread_data_.pending_sync_msgs_.find(id) ==
788 io_thread_data_.pending_sync_msgs_.end()); 790 io_thread_data_.pending_sync_msgs_.end());
789 791
792 // Handle PpapiHostMsg_OpenResource locally without sending an IPC to the
793 // renderer when possible.
794 PpapiHostMsg_OpenResource::Schema::SendParam send_params;
795 if (!open_resource_cb_.is_null() &&
796 message->type() == PpapiHostMsg_OpenResource::ID &&
797 PpapiHostMsg_OpenResource::ReadSendParam(message.get(), &send_params)) {
798 const std::string key = get<0>(send_params);
799 // Both open_resource_cb_ and SaveOpenResourceMessage must be invoked
800 // from the I/O thread.
801 if (open_resource_cb_.Run(
802 *message.get(), key,
803 base::Bind(&NaClIPCAdapter::SaveOpenResourceMessage, this))) {
804 // The callback sent a reply to the untrusted side.
805 return;
806 }
807 }
808
790 if (message->is_sync()) 809 if (message->is_sync())
791 io_thread_data_.pending_sync_msgs_[id] = message->type(); 810 io_thread_data_.pending_sync_msgs_[id] = message->type();
792 io_thread_data_.channel_->Send(message.release()); 811 io_thread_data_.channel_->Send(message.release());
793 } 812 }
794 813
795 void NaClIPCAdapter::SaveMessage(const IPC::Message& msg, 814 void NaClIPCAdapter::SaveMessage(const IPC::Message& msg,
796 RewrittenMessage* rewritten_msg) { 815 RewrittenMessage* rewritten_msg) {
797 lock_.AssertAcquired(); 816 lock_.AssertAcquired();
798 // There is some padding in this structure (the "padding" member is 16 817 // There is some padding in this structure (the "padding" member is 16
799 // bits but this then gets padded to 32 bits). We want to be sure not to 818 // bits but this then gets padded to 32 bits). We want to be sure not to
800 // leak data to the untrusted plugin, so zero everything out first. 819 // leak data to the untrusted plugin, so zero everything out first.
801 NaClMessageHeader header; 820 NaClMessageHeader header;
802 memset(&header, 0, sizeof(NaClMessageHeader)); 821 memset(&header, 0, sizeof(NaClMessageHeader));
803 822
804 header.payload_size = static_cast<uint32>(msg.payload_size()); 823 header.payload_size = static_cast<uint32>(msg.payload_size());
805 header.routing = msg.routing_id(); 824 header.routing = msg.routing_id();
806 header.type = msg.type(); 825 header.type = msg.type();
807 header.flags = msg.flags(); 826 header.flags = msg.flags();
808 header.num_fds = static_cast<uint16>(rewritten_msg->desc_count()); 827 header.num_fds = static_cast<uint16>(rewritten_msg->desc_count());
809 828
810 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); 829 rewritten_msg->SetData(header, msg.payload(), msg.payload_size());
811 locked_data_.to_be_received_.push(rewritten_msg); 830 locked_data_.to_be_received_.push(rewritten_msg);
812 } 831 }
813 832
814 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { 833 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) {
815 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); 834 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags);
816 } 835 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698