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

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 695353005: Non-SFI mode: Use dummy PID for NaCl's IPC channel on Linux platform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « ipc/ipc_channel_posix.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ipc/ipc_channel_posix.h" 5 #include "ipc/ipc_channel_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 #if defined(OS_ANDROID) 169 #if defined(OS_ANDROID)
170 // When we fork for simple tests on Android, we can't 'exec', so we need to 170 // When we fork for simple tests on Android, we can't 'exec', so we need to
171 // reset these entries manually to get the expected testing behavior. 171 // reset these entries manually to get the expected testing behavior.
172 void Channel::NotifyProcessForkedForTesting() { 172 void Channel::NotifyProcessForkedForTesting() {
173 PipeMap::GetInstance()->map_.clear(); 173 PipeMap::GetInstance()->map_.clear();
174 } 174 }
175 #endif 175 #endif
176 176
177 //------------------------------------------------------------------------------ 177 //------------------------------------------------------------------------------
178 178
179 #if defined(OS_LINUX)
180 int ChannelPosix::global_pid_ = 0;
181 #endif // OS_LINUX
182
183 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, 179 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle,
184 Mode mode, Listener* listener) 180 Mode mode, Listener* listener)
185 : ChannelReader(listener), 181 : ChannelReader(listener),
186 mode_(mode), 182 mode_(mode),
187 peer_pid_(base::kNullProcessId), 183 peer_pid_(base::kNullProcessId),
188 is_blocked_on_write_(false), 184 is_blocked_on_write_(false),
189 waiting_connect_(true), 185 waiting_connect_(true),
190 message_send_bytes_written_(0), 186 message_send_bytes_written_(0),
191 pipe_name_(channel_handle.name), 187 pipe_name_(channel_handle.name),
192 must_unlink_(false) { 188 must_unlink_(false) {
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 fds_to_close_.clear(); 634 fds_to_close_.clear();
639 #endif 635 #endif
640 } 636 }
641 637
642 // static 638 // static
643 bool ChannelPosix::IsNamedServerInitialized( 639 bool ChannelPosix::IsNamedServerInitialized(
644 const std::string& channel_id) { 640 const std::string& channel_id) {
645 return base::PathExists(base::FilePath(channel_id)); 641 return base::PathExists(base::FilePath(channel_id));
646 } 642 }
647 643
648 #if defined(OS_LINUX)
649 // static
650 void ChannelPosix::SetGlobalPid(int pid) {
651 global_pid_ = pid;
652 }
653 #endif // OS_LINUX
654
655 // Called by libevent when we can read from the pipe without blocking. 644 // Called by libevent when we can read from the pipe without blocking.
656 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) { 645 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) {
657 if (fd == server_listen_pipe_.get()) { 646 if (fd == server_listen_pipe_.get()) {
658 #if defined(OS_NACL_NONSFI) 647 #if defined(OS_NACL_NONSFI)
659 LOG(FATAL) 648 LOG(FATAL)
660 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode."; 649 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode.";
661 #else 650 #else
662 int new_pipe = 0; 651 int new_pipe = 0;
663 if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) || 652 if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) ||
664 new_pipe < 0) { 653 new_pipe < 0) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 Close(); 753 Close();
765 if (AcceptsConnections()) { 754 if (AcceptsConnections()) {
766 listener()->OnChannelListenError(); 755 listener()->OnChannelListenError();
767 } else { 756 } else {
768 listener()->OnChannelError(); 757 listener()->OnChannelError();
769 } 758 }
770 } 759 }
771 } 760 }
772 761
773 int ChannelPosix::GetHelloMessageProcId() const { 762 int ChannelPosix::GetHelloMessageProcId() const {
774 int pid = base::GetCurrentProcId(); 763 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI)
775 #if defined(OS_LINUX) 764 // On Linux platform, PID does not play any security role.
776 // Our process may be in a sandbox with a separate PID namespace. 765 // In nacl_helper_nonsfi, getpid() invoked by GetCurrentProcId() is not
777 if (global_pid_) { 766 // allowed and would cause a SIGSYS crash because of the seccomp sandbox.
778 pid = global_pid_; 767 // So, for both cases, we provide a dummy PID.
779 } 768 return -1;
769 #else
770 return base::GetCurrentProcId();
780 #endif 771 #endif
781 return pid;
782 } 772 }
783 773
784 void ChannelPosix::QueueHelloMessage() { 774 void ChannelPosix::QueueHelloMessage() {
785 // Create the Hello message 775 // Create the Hello message
786 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, 776 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE,
787 HELLO_MESSAGE_TYPE, 777 HELLO_MESSAGE_TYPE,
788 IPC::Message::PRIORITY_NORMAL)); 778 IPC::Message::PRIORITY_NORMAL));
789 if (!msg->WriteInt(GetHelloMessageProcId())) { 779 if (!msg->WriteInt(GetHelloMessageProcId())) {
790 NOTREACHED() << "Unable to pickle hello message proc id"; 780 NOTREACHED() << "Unable to pickle hello message proc id";
791 } 781 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 1090
1101 return id.append(GenerateUniqueRandomChannelID()); 1091 return id.append(GenerateUniqueRandomChannelID());
1102 } 1092 }
1103 1093
1104 1094
1105 bool Channel::IsNamedServerInitialized( 1095 bool Channel::IsNamedServerInitialized(
1106 const std::string& channel_id) { 1096 const std::string& channel_id) {
1107 return ChannelPosix::IsNamedServerInitialized(channel_id); 1097 return ChannelPosix::IsNamedServerInitialized(channel_id);
1108 } 1098 }
1109 1099
1110 #if defined(OS_LINUX)
1111 // static
1112 void Channel::SetGlobalPid(int pid) {
1113 ChannelPosix::SetGlobalPid(pid);
1114 }
1115 #endif // OS_LINUX
1116
1117 } // namespace IPC 1100 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_posix.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698