summaryrefslogtreecommitdiffstats
path: root/base/memory/shared_memory_nacl.cc
diff options
context:
space:
mode:
authorjyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-20 23:41:25 +0000
committerjyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-20 23:41:25 +0000
commit5f58adabae6bfe5694f15f661d3914197097e500 (patch)
tree9cfe12938fd5e4255be28f41439cc6952a98b375 /base/memory/shared_memory_nacl.cc
parent0c9869d382ae30c8d3fd703b1196891b0d6e3bdb (diff)
downloadchromium_src-5f58adabae6bfe5694f15f661d3914197097e500.zip
chromium_src-5f58adabae6bfe5694f15f661d3914197097e500.tar.gz
chromium_src-5f58adabae6bfe5694f15f661d3914197097e500.tar.bz2
Implement SharedMemory::ShareReadOnlyToProcess().
This avoids potential security holes where the renderer could be exploited and then write into space shared by other renderers or even the browser. I've done this on Posix by opening both a read/write and read-only file descriptor to the same file. Then ShareReadOnlyToProcess dup()s the read-only descriptor instead of the read/write one. It's an error to try to ShareReadOnly from a SharedMemory that was created from a single SharedMemoryHandle. The test checks that operations strictly through the file handle can't get write access to the memory. On Linux there's still a hole through /dev/fd in the filesystem, but jln@ assures me that the sandbox prevents the filesystem-based attack. We should eventually write an explicit test for this. Android needs http://crbug.com/320865 figured out. BUG=302724,320865 Review URL: https://codereview.chromium.org/27265002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236347 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory/shared_memory_nacl.cc')
-rw-r--r--base/memory/shared_memory_nacl.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/base/memory/shared_memory_nacl.cc b/base/memory/shared_memory_nacl.cc
index bc2a98d..93c1002 100644
--- a/base/memory/shared_memory_nacl.cc
+++ b/base/memory/shared_memory_nacl.cc
@@ -140,7 +140,13 @@ void SharedMemory::Unlock() {
bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
SharedMemoryHandle *new_handle,
- bool close_self) {
+ bool close_self,
+ ShareMode share_mode) {
+ if (share_mode == SHARE_READONLY) {
+ // Untrusted code can't create descriptors or handles, which is needed to
+ // drop permissions.
+ return false;
+ }
const int new_fd = dup(mapped_file_);
if (new_fd < 0) {
DPLOG(ERROR) << "dup() failed.";