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 "ppapi/proxy/nacl_message_scanner.h" | 5 #include "ppapi/proxy/nacl_message_scanner.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 for (FileIOMap::iterator it = files_.begin(); it != files_.end(); ++it) | 284 for (FileIOMap::iterator it = files_.begin(); it != files_.end(); ++it) |
285 delete it->second; | 285 delete it->second; |
286 } | 286 } |
287 | 287 |
288 // Windows IPC differs from POSIX in that native handles are serialized in the | 288 // Windows IPC differs from POSIX in that native handles are serialized in the |
289 // message body, rather than passed in a separate FileDescriptorSet. Therefore, | 289 // message body, rather than passed in a separate FileDescriptorSet. Therefore, |
290 // on Windows, any message containing handles must be rewritten in the POSIX | 290 // on Windows, any message containing handles must be rewritten in the POSIX |
291 // format before we can send it to the NaCl plugin. | 291 // format before we can send it to the NaCl plugin. |
292 bool NaClMessageScanner::ScanMessage( | 292 bool NaClMessageScanner::ScanMessage( |
293 const IPC::Message& msg, | 293 const IPC::Message& msg, |
294 uint32_t type, | |
dmichael (off chromium)
2014/08/18 20:06:09
This parameter would be pretty confusing I think t
| |
294 std::vector<SerializedHandle>* handles, | 295 std::vector<SerializedHandle>* handles, |
295 scoped_ptr<IPC::Message>* new_msg_ptr) { | 296 scoped_ptr<IPC::Message>* new_msg_ptr) { |
296 DCHECK(handles); | 297 DCHECK(handles); |
297 DCHECK(handles->empty()); | 298 DCHECK(handles->empty()); |
298 DCHECK(new_msg_ptr); | 299 DCHECK(new_msg_ptr); |
299 DCHECK(!new_msg_ptr->get()); | 300 DCHECK(!new_msg_ptr->get()); |
300 | 301 |
301 bool rewrite_msg = | 302 bool rewrite_msg = |
302 #if defined(OS_WIN) | 303 #if defined(OS_WIN) |
303 true; | 304 true; |
304 #else | 305 #else |
305 false; | 306 false; |
306 #endif | 307 #endif |
307 | 308 |
308 // We can't always tell from the message ID if rewriting is needed. Therefore, | 309 // We can't always tell from the message ID if rewriting is needed. Therefore, |
309 // scan any message types that might contain a handle. If we later determine | 310 // scan any message types that might contain a handle. If we later determine |
310 // that there are no handles, we can cancel the rewriting by clearing the | 311 // that there are no handles, we can cancel the rewriting by clearing the |
311 // results.new_msg pointer. | 312 // results.new_msg pointer. |
312 ScanningResults results; | 313 ScanningResults results; |
313 results.nested_msg_callback = | 314 results.nested_msg_callback = |
314 base::Bind(&NaClMessageScanner::AuditNestedMessage, | 315 base::Bind(&NaClMessageScanner::AuditNestedMessage, |
315 base::Unretained(this)); | 316 base::Unretained(this)); |
316 switch (msg.type()) { | 317 switch (type) { |
317 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated) | 318 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated) |
318 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage) | 319 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage) |
319 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply) | 320 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply) |
320 case IPC_REPLY_ID: { | 321 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer) |
321 int id = IPC::SyncMessage::GetMessageId(msg); | 322 CASE_FOR_REPLY(PpapiHostMsg_PPBImageData_CreateSimple) |
322 PendingSyncMsgMap::iterator iter(pending_sync_msgs_.find(id)); | 323 CASE_FOR_REPLY(PpapiHostMsg_ResourceSyncCall) |
323 if (iter == pending_sync_msgs_.end()) { | 324 CASE_FOR_REPLY(PpapiHostMsg_SharedMemory_CreateSharedMemory) |
324 NOTREACHED(); | |
325 return false; | |
326 } | |
327 uint32_t type = iter->second; | |
328 pending_sync_msgs_.erase(iter); | |
329 switch (type) { | |
330 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer) | |
331 CASE_FOR_REPLY(PpapiHostMsg_PPBImageData_CreateSimple) | |
332 CASE_FOR_REPLY(PpapiHostMsg_ResourceSyncCall) | |
333 CASE_FOR_REPLY(PpapiHostMsg_SharedMemory_CreateSharedMemory) | |
334 default: | |
335 // Do nothing for messages we don't know. | |
336 break; | |
337 } | |
338 break; | |
339 } | |
340 default: | 325 default: |
341 // Do nothing for messages we don't know. | 326 // Do nothing for messages we don't know. |
342 break; | 327 break; |
343 } | 328 } |
344 | 329 |
345 // Only messages containing handles need to be rewritten. If no handles are | 330 // Only messages containing handles need to be rewritten. If no handles are |
346 // found, don't return the rewritten message either. This must be changed if | 331 // found, don't return the rewritten message either. This must be changed if |
347 // we ever add new param types that also require rewriting. | 332 // we ever add new param types that also require rewriting. |
348 if (!results.handles.empty()) { | 333 if (!results.handles.empty()) { |
349 handles->swap(results.handles); | 334 handles->swap(results.handles); |
350 *new_msg_ptr = results.new_msg.Pass(); | 335 *new_msg_ptr = results.new_msg.Pass(); |
351 } | 336 } |
352 return true; | 337 return true; |
353 } | 338 } |
354 | 339 |
355 void NaClMessageScanner::ScanUntrustedMessage( | 340 void NaClMessageScanner::ScanUntrustedMessage( |
356 const IPC::Message& untrusted_msg, | 341 const IPC::Message& untrusted_msg, |
357 scoped_ptr<IPC::Message>* new_msg_ptr) { | 342 scoped_ptr<IPC::Message>* new_msg_ptr) { |
358 if (untrusted_msg.is_sync()) | |
359 RegisterSyncMessageForReply(untrusted_msg); | |
360 | |
361 // Audit FileIO and FileSystem messages to ensure that the plugin doesn't | 343 // Audit FileIO and FileSystem messages to ensure that the plugin doesn't |
362 // exceed its file quota. If we find the message is malformed, just pass it | 344 // exceed its file quota. If we find the message is malformed, just pass it |
363 // through - we only care about well formed messages to the host. | 345 // through - we only care about well formed messages to the host. |
364 if (untrusted_msg.type() == PpapiHostMsg_ResourceCall::ID) { | 346 if (untrusted_msg.type() == PpapiHostMsg_ResourceCall::ID) { |
365 ResourceMessageCallParams params; | 347 ResourceMessageCallParams params; |
366 IPC::Message nested_msg; | 348 IPC::Message nested_msg; |
367 if (!UnpackMessage<PpapiHostMsg_ResourceCall>( | 349 if (!UnpackMessage<PpapiHostMsg_ResourceCall>( |
368 untrusted_msg, ¶ms, &nested_msg)) | 350 untrusted_msg, ¶ms, &nested_msg)) |
369 return; | 351 return; |
370 | 352 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 if (fs_it != file_systems_.end()) { | 448 if (fs_it != file_systems_.end()) { |
467 delete fs_it->second; | 449 delete fs_it->second; |
468 file_systems_.erase(fs_it); | 450 file_systems_.erase(fs_it); |
469 } | 451 } |
470 break; | 452 break; |
471 } | 453 } |
472 } | 454 } |
473 } | 455 } |
474 } | 456 } |
475 | 457 |
476 void NaClMessageScanner::RegisterSyncMessageForReply(const IPC::Message& msg) { | |
477 int msg_id = IPC::SyncMessage::GetMessageId(msg); | |
478 DCHECK(pending_sync_msgs_.find(msg_id) == pending_sync_msgs_.end()); | |
479 | |
480 pending_sync_msgs_[msg_id] = msg.type(); | |
481 } | |
482 | |
483 NaClMessageScanner::FileIO* NaClMessageScanner::GetFile( | 458 NaClMessageScanner::FileIO* NaClMessageScanner::GetFile( |
484 PP_Resource file_io) { | 459 PP_Resource file_io) { |
485 FileIOMap::iterator it = files_.find(file_io); | 460 FileIOMap::iterator it = files_.find(file_io); |
486 DCHECK(it != files_.end()); | 461 DCHECK(it != files_.end()); |
487 return it->second; | 462 return it->second; |
488 } | 463 } |
489 | 464 |
490 void NaClMessageScanner::AuditNestedMessage(PP_Resource resource, | 465 void NaClMessageScanner::AuditNestedMessage(PP_Resource resource, |
491 const IPC::Message& msg, | 466 const IPC::Message& msg, |
492 SerializedHandle* handle) { | 467 SerializedHandle* handle) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 fio_it->second->SetMaxWrittenOffset(offset_it->second); | 509 fio_it->second->SetMaxWrittenOffset(offset_it->second); |
535 } | 510 } |
536 } | 511 } |
537 break; | 512 break; |
538 } | 513 } |
539 } | 514 } |
540 } | 515 } |
541 | 516 |
542 } // namespace proxy | 517 } // namespace proxy |
543 } // namespace ppapi | 518 } // namespace ppapi |
OLD | NEW |