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

Side by Side Diff: content/common/child_process_host.cc

Issue 7714018: Give plug-in processes an executable heap and disable PIE/ASLR for Native (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/common/child_process_host.h" 5 #include "content/common/child_process_host.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
12 #include "content/common/child_process_info.h" 12 #include "content/common/child_process_info.h"
13 #include "content/common/child_process_messages.h" 13 #include "content/common/child_process_messages.h"
14 #include "content/common/content_paths.h" 14 #include "content/common/content_paths.h"
15 #include "content/common/content_switches.h" 15 #include "content/common/content_switches.h"
16 #include "ipc/ipc_logging.h" 16 #include "ipc/ipc_logging.h"
17 17
18 #if defined(OS_LINUX) 18 #if defined(OS_LINUX)
19 #include "base/linux_util.h" 19 #include "base/linux_util.h"
20 #endif // OS_LINUX 20 #endif // OS_LINUX
21 21
22 #if defined(OS_MACOSX)
23 namespace {
24
25 // Given |path| identifying a Mac-style child process executable path, adjusts
26 // it to correspond to |feature|. For a child process path such as
27 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed
28 // path for feature "NP" would be
29 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new
30 // path is returned.
31 FilePath TransformPathForFeature(const FilePath& path,
32 const std::string& feature) {
33 std::string basename = path.BaseName().value();
34
35 FilePath macos_path = path.DirName();
36 const char kMacOSName[] = "MacOS";
37 CHECK_EQ(kMacOSName, macos_path.BaseName().value());
38
39 FilePath contents_path = macos_path.DirName();
40 const char kContentsName[] = "Contents";
41 CHECK_EQ(kContentsName, contents_path.BaseName().value());
42
43 FilePath helper_app_path = contents_path.DirName();
44 const char kAppExtension[] = ".app";
45 std::string basename_app = basename;
46 basename_app.append(kAppExtension);
47 CHECK_EQ(basename_app, helper_app_path.BaseName().value());
48
49 FilePath root_path = helper_app_path.DirName();
50
51 std::string new_basename = basename;
52 new_basename.append(1, ' ');
53 new_basename.append(feature);
54 std::string new_basename_app = new_basename;
55 new_basename_app.append(kAppExtension);
56
57 FilePath new_path = root_path.Append(new_basename_app)
58 .Append(kContentsName)
59 .Append(kMacOSName)
60 .Append(new_basename);
61
62 return new_path;
63 }
64
65 } // namespace
66 #endif // OS_MACOSX
67
22 ChildProcessHost::ChildProcessHost() 68 ChildProcessHost::ChildProcessHost()
23 : ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)), 69 : ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)),
24 opening_channel_(false) { 70 opening_channel_(false) {
25 } 71 }
26 72
27 ChildProcessHost::~ChildProcessHost() { 73 ChildProcessHost::~ChildProcessHost() {
28 for (size_t i = 0; i < filters_.size(); ++i) { 74 for (size_t i = 0; i < filters_.size(); ++i) {
29 filters_[i]->OnChannelClosing(); 75 filters_[i]->OnChannelClosing();
30 filters_[i]->OnFilterRemoved(); 76 filters_[i]->OnFilterRemoved();
31 } 77 }
32 } 78 }
33 79
34 void ChildProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { 80 void ChildProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
35 filters_.push_back(filter); 81 filters_.push_back(filter);
36 82
37 if (channel_.get()) 83 if (channel_.get())
38 filter->OnFilterAdded(channel_.get()); 84 filter->OnFilterAdded(channel_.get());
39 } 85 }
40 86
41 // static 87 // static
42 FilePath ChildProcessHost::GetChildPath(bool allow_self) { 88 FilePath ChildProcessHost::GetChildPath(int flags) {
43 FilePath child_path; 89 FilePath child_path;
44 90
45 child_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath( 91 child_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
46 switches::kBrowserSubprocessPath); 92 switches::kBrowserSubprocessPath);
47 if (!child_path.empty()) 93 if (!child_path.empty())
48 return child_path; 94 return child_path;
49 95
50 #if defined(OS_LINUX) 96 #if defined(OS_LINUX)
51 // Use /proc/self/exe rather than our known binary path so updates 97 // Use /proc/self/exe rather than our known binary path so updates
52 // can't swap out the binary from underneath us. 98 // can't swap out the binary from underneath us.
53 // When running under Valgrind, forking /proc/self/exe ends up forking the 99 // When running under Valgrind, forking /proc/self/exe ends up forking the
54 // Valgrind executable, which then crashes. However, it's almost safe to 100 // Valgrind executable, which then crashes. However, it's almost safe to
55 // assume that the updates won't happen while testing with Valgrind tools. 101 // assume that the updates won't happen while testing with Valgrind tools.
56 if (allow_self && !RunningOnValgrind()) 102 if (flags & CHILD_ALLOW_SELF && !RunningOnValgrind())
57 return FilePath("/proc/self/exe"); 103 return FilePath("/proc/self/exe");
58 #endif 104 #endif
59 105
60 // On most platforms, the child executable is the same as the current 106 // On most platforms, the child executable is the same as the current
61 // executable. 107 // executable.
62 PathService::Get(content::CHILD_PROCESS_EXE, &child_path); 108 PathService::Get(content::CHILD_PROCESS_EXE, &child_path);
109
110 #if defined(OS_MACOSX)
111 DCHECK(!(flags & CHILD_NO_PIE && flags & CHILD_ALLOW_HEAP_EXECUTION));
112
113 // If needed, choose an executable with special flags set that inform the
114 // kernel to enable or disable specific optional process-wide features.
115 if (flags & CHILD_NO_PIE) {
116 // "NP" is "No PIE".
117 child_path = TransformPathForFeature(child_path, "NP");
118 } else if (flags & CHILD_ALLOW_HEAP_EXECUTION) {
119 // "EH" is "Executable Heap". A non-executable heap is only available to
120 // 32-bit processes on Mac OS X 10.7. Most code can and should run with a
121 // non-executable heap, but the "EH" feature is provided to allow code
122 // intolerant of a non-executable heap to work properly on 10.7.
123 child_path = TransformPathForFeature(child_path, "EH");
124 }
125 #endif
126
63 return child_path; 127 return child_path;
64 } 128 }
65 129
66 #if defined(OS_WIN) 130 #if defined(OS_WIN)
67 // static 131 // static
68 void ChildProcessHost::PreCacheFont(LOGFONT font) { 132 void ChildProcessHost::PreCacheFont(LOGFONT font) {
69 // If a child process is running in a sandbox, GetTextMetrics() 133 // If a child process is running in a sandbox, GetTextMetrics()
70 // can sometimes fail. If a font has not been loaded 134 // can sometimes fail. If a font has not been loaded
71 // previously, GetTextMetrics() will try to load the font 135 // previously, GetTextMetrics() will try to load the font
72 // from the font file. However, the sandboxed process does 136 // from the font file. However, the sandboxed process does
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 for (size_t i = 0; i < host_->filters_.size(); ++i) 286 for (size_t i = 0; i < host_->filters_.size(); ++i)
223 host_->filters_[i]->OnChannelError(); 287 host_->filters_[i]->OnChannelError();
224 288
225 // This will delete host_, which will also destroy this! 289 // This will delete host_, which will also destroy this!
226 host_->OnChildDied(); 290 host_->OnChildDied();
227 } 291 }
228 292
229 void ChildProcessHost::ForceShutdown() { 293 void ChildProcessHost::ForceShutdown() {
230 Send(new ChildProcessMsg_Shutdown()); 294 Send(new ChildProcessMsg_Shutdown());
231 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698