Gentoo Archives: gentoo-commits

From: "PaweA Hajdan (phajdan.jr)" <phajdan.jr@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in www-client/chromium/files: chromium-dev-shm-r0.patch
Date: Mon, 30 Jan 2012 07:58:19
Message-Id: 20120130075808.7FCDC2004B@flycatcher.gentoo.org
1 phajdan.jr 12/01/30 07:58:08
2
3 Added: chromium-dev-shm-r0.patch
4 Log:
5 Backport upstream fix for Gentoo bug #389479, and suppress net_unittests failure that doesn't occur in 18.x. Remove old.
6
7 (Portage version: 2.1.10.44/cvs/Linux i686)
8
9 Revision Changes Path
10 1.1 www-client/chromium/files/chromium-dev-shm-r0.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-dev-shm-r0.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-dev-shm-r0.patch?rev=1.1&content-type=text/plain
14
15 Index: chromium-dev-shm-r0.patch
16 ===================================================================
17 Backport http://codereview.chromium.org/8800025 to fix issues with noexec /dev/shm
18 diff --git a/base/file_util.h b/base/file_util.h
19 index 90ec1ae..78827e9 100644
20 --- a/base/file_util.h
21 +++ b/base/file_util.h
22 @@ -259,7 +259,7 @@ BASE_EXPORT bool IsDirectoryEmpty(const FilePath& dir_path);
23 BASE_EXPORT bool GetTempDir(FilePath* path);
24 // Get a temporary directory for shared memory files.
25 // Only useful on POSIX; redirects to GetTempDir() on Windows.
26 -BASE_EXPORT bool GetShmemTempDir(FilePath* path);
27 +BASE_EXPORT bool GetShmemTempDir(FilePath* path, bool executable);
28
29 // Get the home directory. This is more complicated than just getenv("HOME")
30 // as it knows to fall back on getpwent() etc.
31 @@ -279,7 +279,10 @@ BASE_EXPORT bool CreateTemporaryFileInDir(const FilePath& dir,
32 // Returns a handle to the opened file or NULL if an error occured.
33 BASE_EXPORT FILE* CreateAndOpenTemporaryFile(FilePath* path);
34 // Like above but for shmem files. Only useful for POSIX.
35 -BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(FilePath* path);
36 +// The executable flag says the file needs to support using
37 +// mprotect with PROT_EXEC after mapping.
38 +BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(FilePath* path,
39 + bool executable);
40 // Similar to CreateAndOpenTemporaryFile, but the file is created in |dir|.
41 BASE_EXPORT FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir,
42 FilePath* path);
43 diff --git a/base/file_util_android.cc b/base/file_util_android.cc
44 index eff3a46..6807d8d 100644
45 --- a/base/file_util_android.cc
46 +++ b/base/file_util_android.cc
47 @@ -8,7 +8,7 @@
48
49 namespace file_util {
50
51 -bool GetShmemTempDir(FilePath* path) {
52 +bool GetShmemTempDir(FilePath* path, bool executable) {
53 *path = FilePath("/data/local/tmp");
54 return true;
55 }
56 diff --git a/base/file_util_mac.mm b/base/file_util_mac.mm
57 index 95d4f25..bb4975d 100644
58 --- a/base/file_util_mac.mm
59 +++ b/base/file_util_mac.mm
60 @@ -1,4 +1,4 @@
61 -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
62 +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
63 // Use of this source code is governed by a BSD-style license that can be
64 // found in the LICENSE file.
65
66 @@ -22,7 +22,7 @@ bool GetTempDir(FilePath* path) {
67 return true;
68 }
69
70 -bool GetShmemTempDir(FilePath* path) {
71 +bool GetShmemTempDir(FilePath* path, bool executable) {
72 return GetTempDir(path);
73 }
74
75 diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
76 index 582f70e..5c14abd 100644
77 --- a/base/file_util_posix.cc
78 +++ b/base/file_util_posix.cc
79 @@ -481,9 +481,9 @@ bool CreateTemporaryFile(FilePath* path) {
80 return true;
81 }
82
83 -FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) {
84 +FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, bool executable) {
85 FilePath directory;
86 - if (!GetShmemTempDir(&directory))
87 + if (!GetShmemTempDir(&directory, executable))
88 return NULL;
89
90 return CreateAndOpenTemporaryFileInDir(directory, path);
91 @@ -910,15 +910,52 @@ bool GetTempDir(FilePath* path) {
92 }
93
94 #if !defined(OS_ANDROID)
95 -bool GetShmemTempDir(FilePath* path) {
96 +
97 #if defined(OS_LINUX)
98 - *path = FilePath("/dev/shm");
99 - return true;
100 -#else
101 - return GetTempDir(path);
102 -#endif
103 +// Determine if /dev/shm files can be mapped and then mprotect'd PROT_EXEC.
104 +// This depends on the mount options used for /dev/shm, which vary among
105 +// different Linux distributions and possibly local configuration. It also
106 +// depends on details of kernel--ChromeOS uses the noexec option for /dev/shm
107 +// but its kernel allows mprotect with PROT_EXEC anyway.
108 +
109 +namespace {
110 +
111 +bool DetermineDevShmExecutable() {
112 + bool result = false;
113 + FilePath path;
114 + int fd = CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path);
115 + if (fd >= 0) {
116 + ScopedFD shm_fd_closer(&fd);
117 + Delete(path, false);
118 + size_t pagesize = sysconf(_SC_PAGESIZE);
119 + void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
120 + if (mapping != MAP_FAILED) {
121 + if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0)
122 + result = true;
123 + munmap(mapping, pagesize);
124 + }
125 + }
126 + return result;
127 }
128 +
129 +}; // namespace
130 +#endif // defined(OS_LINUX)
131 +
132 +bool GetShmemTempDir(FilePath* path, bool executable) {
133 +#if defined(OS_LINUX)
134 + bool use_dev_shm = true;
135 + if (executable) {
136 + static const bool s_dev_shm_executable = DetermineDevShmExecutable();
137 + use_dev_shm = s_dev_shm_executable;
138 + }
139 + if (use_dev_shm) {
140 + *path = FilePath("/dev/shm");
141 + return true;
142 + }
143 #endif
144 + return GetTempDir(path);
145 +}
146 +#endif // !defined(OS_ANDROID)
147
148 FilePath GetHomeDir() {
149 const char* home_dir = getenv("HOME");
150 diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
151 index 00cacd6..a9f9377 100644
152 --- a/base/file_util_unittest.cc
153 +++ b/base/file_util_unittest.cc
154 @@ -1545,7 +1545,7 @@ TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) {
155
156 TEST_F(FileUtilTest, GetShmemTempDirTest) {
157 FilePath dir;
158 - EXPECT_TRUE(file_util::GetShmemTempDir(&dir));
159 + EXPECT_TRUE(file_util::GetShmemTempDir(&dir, false));
160 EXPECT_TRUE(file_util::DirectoryExists(dir));
161 }
162
163 diff --git a/base/file_util_win.cc b/base/file_util_win.cc
164 index 8d9fbde..a6720a5 100644
165 --- a/base/file_util_win.cc
166 +++ b/base/file_util_win.cc
167 @@ -556,7 +556,7 @@ bool GetTempDir(FilePath* path) {
168 return true;
169 }
170
171 -bool GetShmemTempDir(FilePath* path) {
172 +bool GetShmemTempDir(FilePath* path, bool executable) {
173 return GetTempDir(path);
174 }
175
176 @@ -576,7 +576,7 @@ bool CreateTemporaryFile(FilePath* path) {
177 return false;
178 }
179
180 -FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) {
181 +FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, bool executable) {
182 base::ThreadRestrictions::AssertIOAllowed();
183 return CreateAndOpenTemporaryFile(path);
184 }
185 diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc
186 index 030061a..a66c859 100644
187 --- a/base/shared_memory_posix.cc
188 +++ b/base/shared_memory_posix.cc
189 @@ -123,7 +123,7 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
190 DCHECK(!options.open_existing);
191 // Q: Why not use the shm_open() etc. APIs?
192 // A: Because they're limited to 4mb on OS X. FFFFFFFUUUUUUUUUUU
193 - fp = file_util::CreateAndOpenTemporaryShmemFile(&path);
194 + fp = file_util::CreateAndOpenTemporaryShmemFile(&path, options.executable);
195
196 // Deleting the file prevents anyone else from mapping it in
197 // (making it private), and prevents the need for cleanup (once
198 @@ -317,7 +317,7 @@ bool SharedMemory::FilePathForMemoryName(const std::string& mem_name,
199 DCHECK_EQ(std::string::npos, mem_name.find('\0'));
200
201 FilePath temp_dir;
202 - if (!file_util::GetShmemTempDir(&temp_dir))
203 + if (!file_util::GetShmemTempDir(&temp_dir, false))
204 return false;
205
206 #if !defined(OS_MACOSX)
207 --
208 1.7.6.1