| OLD | NEW |
| (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 | |
| OLD | NEW |