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

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 14750007: NaCl: enable meta-based validation for shared libraries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment Created 7 years, 7 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
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 "chrome/browser/nacl_host/nacl_process_host.h" 5 #include "chrome/browser/nacl_host/nacl_process_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 return true; 616 return true;
617 } 617 }
618 618
619 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { 619 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) {
620 bool handled = true; 620 bool handled = true;
621 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) 621 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg)
622 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, 622 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate,
623 OnQueryKnownToValidate) 623 OnQueryKnownToValidate)
624 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, 624 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate,
625 OnSetKnownToValidate) 625 OnSetKnownToValidate)
626 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken,
627 OnResolveFileToken)
626 #if defined(OS_WIN) 628 #if defined(OS_WIN)
627 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, 629 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler,
628 OnAttachDebugExceptionHandler) 630 OnAttachDebugExceptionHandler)
629 #endif 631 #endif
630 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated, 632 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated,
631 OnPpapiChannelCreated) 633 OnPpapiChannelCreated)
632 IPC_MESSAGE_UNHANDLED(handled = false) 634 IPC_MESSAGE_UNHANDLED(handled = false)
633 IPC_END_MESSAGE_MAP() 635 IPC_END_MESSAGE_MAP()
634 return handled; 636 return handled;
635 } 637 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 const ChildProcessData& data = process_->GetData(); 756 const ChildProcessData& data = process_->GetData();
755 if (!ShareHandleToSelLdr(data.handle, 757 if (!ShareHandleToSelLdr(data.handle,
756 internal_->socket_for_sel_ldr, true, 758 internal_->socket_for_sel_ldr, true,
757 &params.handles)) { 759 &params.handles)) {
758 return false; 760 return false;
759 } 761 }
760 762
761 if (params.uses_irt) { 763 if (params.uses_irt) {
762 base::PlatformFile irt_file = nacl_browser->IrtFile(); 764 base::PlatformFile irt_file = nacl_browser->IrtFile();
763 CHECK_NE(irt_file, base::kInvalidPlatformFileValue); 765 CHECK_NE(irt_file, base::kInvalidPlatformFileValue);
764
765 // Send over the IRT file handle. We don't close our own copy! 766 // Send over the IRT file handle. We don't close our own copy!
766 if (!ShareHandleToSelLdr(data.handle, irt_file, false, &params.handles)) 767 if (!ShareHandleToSelLdr(data.handle, irt_file, false, &params.handles))
767 return false; 768 return false;
768 } 769 }
769 770
770 #if defined(OS_MACOSX) 771 #if defined(OS_MACOSX)
771 // For dynamic loading support, NaCl requires a file descriptor that 772 // For dynamic loading support, NaCl requires a file descriptor that
772 // was created in /tmp, since those created with shm_open() are not 773 // was created in /tmp, since those created with shm_open() are not
773 // mappable with PROT_EXEC. Rather than requiring an extra IPC 774 // mappable with PROT_EXEC. Rather than requiring an extra IPC
774 // round trip out of the sandbox, we create an FD here. 775 // round trip out of the sandbox, we create an FD here.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature, 924 void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature,
924 bool* result) { 925 bool* result) {
925 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); 926 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
926 *result = nacl_browser->QueryKnownToValidate(signature, off_the_record_); 927 *result = nacl_browser->QueryKnownToValidate(signature, off_the_record_);
927 } 928 }
928 929
929 void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) { 930 void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) {
930 NaClBrowser::GetInstance()->SetKnownToValidate(signature, off_the_record_); 931 NaClBrowser::GetInstance()->SetKnownToValidate(signature, off_the_record_);
931 } 932 }
932 933
934 void NaClProcessHost::FileResolved(
935 base::PlatformFile* file,
936 const base::FilePath& file_path,
937 IPC::Message* reply_msg) {
938 if (*file != base::kInvalidPlatformFileValue) {
939 IPC::PlatformFileForTransit handle = IPC::GetFileHandleForProcess(
940 *file,
941 process_->GetData().handle,
942 true /* close_source */);
943 NaClProcessMsg_ResolveFileToken::WriteReplyParams(
944 reply_msg,
945 handle,
946 file_path);
947 } else {
948 NaClProcessMsg_ResolveFileToken::WriteReplyParams(
949 reply_msg,
950 IPC::InvalidPlatformFileForTransit(),
951 base::FilePath(FILE_PATH_LITERAL("")));
952 }
953 Send(reply_msg);
954 }
955
956 void NaClProcessHost::OnResolveFileToken(uint64 file_token_lo,
957 uint64 file_token_hi,
958 IPC::Message* reply_msg) {
959 // Was the file registered?
Mark Seaborn 2013/05/24 20:21:58 Nit: add empty line after each comment paragraph f
960 // Note that the file path cache is of bounded size, and old entries can get
961 // evicted. If a large number of NaCl modules are being launched at once,
962 // resolving the file_token may fail because the path cache was thrashed
963 // while the file_token was in flight. In this case the query fails, and we
964 // need to fall back to the slower path.
965 // However: each NaCl process will consume 2-3 entries as it starts up, this
Mark Seaborn 2013/05/24 20:21:58 Why 2-3? Explain more in comment, perhaps?
Nick Bray (chromium) 2013/05/24 21:35:24 Done.
966 // means that eviction will not happen unless you start up 33+ NaCl processes
967 // at the same time, and this still requires worst-case timing. As a
968 // practical matter, no entries should be evicted prematurely.
969 // The cache itself should take ~ (150 characters * 2 bytes/char + ~60 bytes
970 // data structure overhead) * 100 = 35k when full, so making it bigger should
971 // not be a problem, if needed.
972 // TODO(ncbray): track behavior with UMA. If entries are getting evicted or
973 // bogus keys are getting queried, this would be good to know.
974 base::FilePath file_path;
975 if (!NaClBrowser::GetInstance()->GetFilePath(file_token_lo, file_token_hi,
976 &file_path)) {
977 NaClProcessMsg_ResolveFileToken::WriteReplyParams(
978 reply_msg,
979 IPC::InvalidPlatformFileForTransit(),
980 base::FilePath(FILE_PATH_LITERAL("")));
981 Send(reply_msg);
982 return;
983 }
984
985 // Scratch space to share between the callbacks.
986 base::PlatformFile* data = new base::PlatformFile();
987
988 // Open the file.
989 if (!content::BrowserThread::PostBlockingPoolTaskAndReply(
990 FROM_HERE,
Mark Seaborn 2013/05/24 20:21:58 Indent arguments properly. i.e.: // Wrong if (so
Nick Bray (chromium) 2013/05/24 21:35:24 Done.
991 base::Bind(nacl::OpenNaClExecutableImpl,
992 file_path, data),
993 base::Bind(&NaClProcessHost::FileResolved,
994 weak_factory_.GetWeakPtr(),
995 base::Owned(data),
996 file_path,
997 reply_msg))) {
998 NaClProcessMsg_ResolveFileToken::WriteReplyParams(
999 reply_msg,
1000 IPC::InvalidPlatformFileForTransit(),
1001 base::FilePath(FILE_PATH_LITERAL("")));
1002 Send(reply_msg);
1003 }
1004 }
1005
933 #if defined(OS_WIN) 1006 #if defined(OS_WIN)
934 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info, 1007 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info,
935 IPC::Message* reply_msg) { 1008 IPC::Message* reply_msg) {
936 if (!AttachDebugExceptionHandler(info, reply_msg)) { 1009 if (!AttachDebugExceptionHandler(info, reply_msg)) {
937 // Send failure message. 1010 // Send failure message.
938 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg, 1011 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg,
939 false); 1012 false);
940 Send(reply_msg); 1013 Send(reply_msg);
941 } 1014 }
942 } 1015 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 } else { 1064 } else {
992 NaClStartDebugExceptionHandlerThread( 1065 NaClStartDebugExceptionHandlerThread(
993 process_handle.Take(), info, 1066 process_handle.Take(), info,
994 base::MessageLoopProxy::current(), 1067 base::MessageLoopProxy::current(),
995 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1068 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
996 weak_factory_.GetWeakPtr())); 1069 weak_factory_.GetWeakPtr()));
997 return true; 1070 return true;
998 } 1071 }
999 } 1072 }
1000 #endif 1073 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698