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

Side by Side Diff: sandbox/linux/seccomp/mprotect.cc

Issue 3225010: Pull seccomp-sandbox in via DEPS rather than using an in-tree copy... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
« no previous file with comments | « sandbox/linux/seccomp/mmap.cc ('k') | sandbox/linux/seccomp/munmap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "debug.h"
6 #include "sandbox_impl.h"
7
8 namespace playground {
9
10 long Sandbox::sandbox_mprotect(const void *addr, size_t len, int prot) {
11 long long tm;
12 Debug::syscall(&tm, __NR_mprotect, "Executing handler");
13 struct {
14 int sysnum;
15 long long cookie;
16 MProtect mprotect_req;
17 } __attribute__((packed)) request;
18 request.sysnum = __NR_mprotect;
19 request.cookie = cookie();
20 request.mprotect_req.addr = addr;
21 request.mprotect_req.len = len;
22 request.mprotect_req.prot = prot;
23
24 long rc;
25 SysCalls sys;
26 if (write(sys, processFdPub(), &request, sizeof(request)) !=
27 sizeof(request) ||
28 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) {
29 die("Failed to forward mprotect() request [sandbox]");
30 }
31 Debug::elapsed(tm, __NR_mprotect);
32 return rc;
33 }
34
35 bool Sandbox::process_mprotect(int parentMapsFd, int sandboxFd,
36 int threadFdPub, int threadFd,
37 SecureMem::Args* mem) {
38 // Read request
39 SysCalls sys;
40 MProtect mprotect_req;
41 if (read(sys, sandboxFd, &mprotect_req, sizeof(mprotect_req)) !=
42 sizeof(mprotect_req)) {
43 die("Failed to read parameters for mprotect() [process]");
44 }
45
46 // Cannot change permissions on any memory region that was part of the
47 // original memory mappings.
48 int rc = -EINVAL;
49 void *stop = reinterpret_cast<void *>(
50 (char *)mprotect_req.addr + mprotect_req.len);
51 ProtectedMap::const_iterator iter = protectedMap_.lower_bound(
52 (void *)mprotect_req.addr);
53 if (iter != protectedMap_.begin()) {
54 --iter;
55 }
56 for (; iter != protectedMap_.end() && iter->first < stop; ++iter) {
57 if (mprotect_req.addr < reinterpret_cast<void *>(
58 reinterpret_cast<char *>(iter->first) + iter->second) &&
59 stop > iter->first) {
60 SecureMem::abandonSystemCall(threadFd, rc);
61 return false;
62 }
63 }
64
65 // Changing permissions on memory regions that were newly mapped inside of
66 // the sandbox is OK.
67 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_mprotect,
68 mprotect_req.addr, mprotect_req.len,
69 mprotect_req.prot);
70 return true;
71 }
72
73 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp/mmap.cc ('k') | sandbox/linux/seccomp/munmap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698