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 void* Sandbox::sandbox_mmap(void *start, size_t length, int prot, int flags, | |
11 int fd, off_t offset) { | |
12 long long tm; | |
13 Debug::syscall(&tm, __NR_mmap, "Executing handler"); | |
14 struct { | |
15 int sysnum; | |
16 long long cookie; | |
17 MMap mmap_req; | |
18 } __attribute__((packed)) request; | |
19 request.sysnum = __NR_MMAP; | |
20 request.cookie = cookie(); | |
21 request.mmap_req.start = start; | |
22 request.mmap_req.length = length; | |
23 request.mmap_req.prot = prot; | |
24 request.mmap_req.flags = flags; | |
25 request.mmap_req.fd = fd; | |
26 request.mmap_req.offset = offset; | |
27 | |
28 void* rc; | |
29 SysCalls sys; | |
30 if (write(sys, processFdPub(), &request, sizeof(request)) != | |
31 sizeof(request) || | |
32 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) { | |
33 die("Failed to forward mmap() request [sandbox]"); | |
34 } | |
35 Debug::elapsed(tm, __NR_mmap); | |
36 return rc; | |
37 } | |
38 | |
39 bool Sandbox::process_mmap(int parentMapsFd, int sandboxFd, int threadFdPub, | |
40 int threadFd, SecureMem::Args* mem) { | |
41 // Read request | |
42 SysCalls sys; | |
43 MMap mmap_req; | |
44 if (read(sys, sandboxFd, &mmap_req, sizeof(mmap_req)) != sizeof(mmap_req)) { | |
45 die("Failed to read parameters for mmap() [process]"); | |
46 } | |
47 | |
48 if (mmap_req.flags & MAP_FIXED) { | |
49 // Cannot map a memory area that was part of the original memory mappings. | |
50 void *stop = reinterpret_cast<void *>( | |
51 (char *)mmap_req.start + mmap_req.length); | |
52 ProtectedMap::const_iterator iter = protectedMap_.lower_bound( | |
53 (void *)mmap_req.start); | |
54 if (iter != protectedMap_.begin()) { | |
55 --iter; | |
56 } | |
57 for (; iter != protectedMap_.end() && iter->first < stop; ++iter) { | |
58 if (mmap_req.start < reinterpret_cast<void *>( | |
59 reinterpret_cast<char *>(iter->first) + iter->second) && | |
60 stop > iter->first) { | |
61 int rc = -EINVAL; | |
62 SecureMem::abandonSystemCall(threadFd, rc); | |
63 return false; | |
64 } | |
65 } | |
66 } | |
67 | |
68 // All other mmap() requests are OK | |
69 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_MMAP, | |
70 mmap_req.start, mmap_req.length, mmap_req.prot, | |
71 mmap_req.flags, mmap_req.fd, mmap_req.offset); | |
72 return true; | |
73 } | |
74 | |
75 } // namespace | |
OLD | NEW |