| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "debug.h" | 5 #include "debug.h" |
| 6 #include "sandbox_impl.h" | 6 #include "sandbox_impl.h" |
| 7 | 7 |
| 8 namespace playground { | 8 namespace playground { |
| 9 | 9 |
| 10 int Sandbox::sandbox_mprotect(const void *addr, size_t len, int prot) { | 10 int Sandbox::sandbox_mprotect(const void *addr, size_t len, int prot) { |
| 11 Debug::syscall(__NR_mprotect, "Executing handler"); | 11 long long tm; |
| 12 Debug::syscall(&tm, __NR_mprotect, "Executing handler"); |
| 12 struct { | 13 struct { |
| 13 int sysnum; | 14 int sysnum; |
| 14 long long cookie; | 15 long long cookie; |
| 15 MProtect mprotect_req; | 16 MProtect mprotect_req; |
| 16 } __attribute__((packed)) request; | 17 } __attribute__((packed)) request; |
| 17 request.sysnum = __NR_mprotect; | 18 request.sysnum = __NR_mprotect; |
| 18 request.cookie = cookie(); | 19 request.cookie = cookie(); |
| 19 request.mprotect_req.addr = addr; | 20 request.mprotect_req.addr = addr; |
| 20 request.mprotect_req.len = len; | 21 request.mprotect_req.len = len; |
| 21 request.mprotect_req.prot = prot; | 22 request.mprotect_req.prot = prot; |
| 22 | 23 |
| 23 long rc; | 24 long rc; |
| 24 SysCalls sys; | 25 SysCalls sys; |
| 25 if (write(sys, processFdPub(), &request, sizeof(request)) != | 26 if (write(sys, processFdPub(), &request, sizeof(request)) != |
| 26 sizeof(request) || | 27 sizeof(request) || |
| 27 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) { | 28 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) { |
| 28 die("Failed to forward mprotect() request [sandbox]"); | 29 die("Failed to forward mprotect() request [sandbox]"); |
| 29 } | 30 } |
| 31 Debug::elapsed(tm, __NR_mprotect); |
| 30 return static_cast<int>(rc); | 32 return static_cast<int>(rc); |
| 31 } | 33 } |
| 32 | 34 |
| 33 bool Sandbox::process_mprotect(int parentMapsFd, int sandboxFd, | 35 bool Sandbox::process_mprotect(int parentMapsFd, int sandboxFd, |
| 34 int threadFdPub, int threadFd, | 36 int threadFdPub, int threadFd, |
| 35 SecureMem::Args* mem) { | 37 SecureMem::Args* mem) { |
| 36 // Read request | 38 // Read request |
| 37 SysCalls sys; | 39 SysCalls sys; |
| 38 MProtect mprotect_req; | 40 MProtect mprotect_req; |
| 39 if (read(sys, sandboxFd, &mprotect_req, sizeof(mprotect_req)) != | 41 if (read(sys, sandboxFd, &mprotect_req, sizeof(mprotect_req)) != |
| (...skipping 22 matching lines...) Expand all Loading... |
| 62 | 64 |
| 63 // Changing permissions on memory regions that were newly mapped inside of | 65 // Changing permissions on memory regions that were newly mapped inside of |
| 64 // the sandbox is OK. | 66 // the sandbox is OK. |
| 65 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_mprotect, | 67 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_mprotect, |
| 66 mprotect_req.addr, mprotect_req.len, | 68 mprotect_req.addr, mprotect_req.len, |
| 67 mprotect_req.prot); | 69 mprotect_req.prot); |
| 68 return true; | 70 return true; |
| 69 } | 71 } |
| 70 | 72 |
| 71 } // namespace | 73 } // namespace |
| OLD | NEW |