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_munmap(void* start, size_t length) { | |
11 long long tm; | |
12 Debug::syscall(&tm, __NR_munmap, "Executing handler"); | |
13 struct { | |
14 int sysnum; | |
15 long long cookie; | |
16 MUnmap munmap_req; | |
17 } __attribute__((packed)) request; | |
18 request.sysnum = __NR_munmap; | |
19 request.cookie = cookie(); | |
20 request.munmap_req.start = start; | |
21 request.munmap_req.length = length; | |
22 | |
23 long rc; | |
24 SysCalls sys; | |
25 if (write(sys, processFdPub(), &request, sizeof(request)) != | |
26 sizeof(request) || | |
27 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) { | |
28 die("Failed to forward munmap() request [sandbox]"); | |
29 } | |
30 Debug::elapsed(tm, __NR_munmap); | |
31 return rc; | |
32 } | |
33 | |
34 bool Sandbox::process_munmap(int parentMapsFd, int sandboxFd, int threadFdPub, | |
35 int threadFd, SecureMem::Args* mem) { | |
36 // Read request | |
37 SysCalls sys; | |
38 MUnmap munmap_req; | |
39 if (read(sys, sandboxFd, &munmap_req, sizeof(munmap_req)) != | |
40 sizeof(munmap_req)) { | |
41 die("Failed to read parameters for munmap() [process]"); | |
42 } | |
43 | |
44 // Cannot unmap any memory region that was part of the original memory | |
45 // mappings. | |
46 int rc = -EINVAL; | |
47 void *stop = reinterpret_cast<void *>( | |
48 reinterpret_cast<char *>(munmap_req.start) + munmap_req.length); | |
49 ProtectedMap::const_iterator iter = protectedMap_.lower_bound( | |
50 munmap_req.start); | |
51 if (iter != protectedMap_.begin()) { | |
52 --iter; | |
53 } | |
54 for (; iter != protectedMap_.end() && iter->first < stop; ++iter) { | |
55 if (munmap_req.start < reinterpret_cast<void *>( | |
56 reinterpret_cast<char *>(iter->first) + iter->second) && | |
57 stop > iter->first) { | |
58 SecureMem::abandonSystemCall(threadFd, rc); | |
59 return false; | |
60 } | |
61 } | |
62 | |
63 // Unmapping memory regions that were newly mapped inside of the sandbox | |
64 // is OK. | |
65 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_munmap, | |
66 munmap_req.start, munmap_req.length); | |
67 return true; | |
68 } | |
69 | |
70 } // namespace | |
OLD | NEW |