| 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_open(const char *pathname, int flags, mode_t mode) { | 10 int Sandbox::sandbox_open(const char *pathname, int flags, mode_t mode) { |
| 11 Debug::syscall(__NR_open, "Executing handler"); | 11 long long tm; |
| 12 Debug::syscall(&tm, __NR_open, "Executing handler"); |
| 12 size_t len = strlen(pathname); | 13 size_t len = strlen(pathname); |
| 13 struct Request { | 14 struct Request { |
| 14 int sysnum; | 15 int sysnum; |
| 15 long long cookie; | 16 long long cookie; |
| 16 Open open_req; | 17 Open open_req; |
| 17 char pathname[0]; | 18 char pathname[0]; |
| 18 } __attribute__((packed)) *request; | 19 } __attribute__((packed)) *request; |
| 19 char data[sizeof(struct Request) + len]; | 20 char data[sizeof(struct Request) + len]; |
| 20 request = reinterpret_cast<struct Request*>(data); | 21 request = reinterpret_cast<struct Request*>(data); |
| 21 request->sysnum = __NR_open; | 22 request->sysnum = __NR_open; |
| 22 request->cookie = cookie(); | 23 request->cookie = cookie(); |
| 23 request->open_req.path_length = len; | 24 request->open_req.path_length = len; |
| 24 request->open_req.flags = flags; | 25 request->open_req.flags = flags; |
| 25 request->open_req.mode = mode; | 26 request->open_req.mode = mode; |
| 26 memcpy(request->pathname, pathname, len); | 27 memcpy(request->pathname, pathname, len); |
| 27 | 28 |
| 28 long rc; | 29 long rc; |
| 29 SysCalls sys; | 30 SysCalls sys; |
| 30 if (write(sys, processFdPub(), request, sizeof(data)) != (int)sizeof(data) || | 31 if (write(sys, processFdPub(), request, sizeof(data)) != (int)sizeof(data) || |
| 31 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) { | 32 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) { |
| 32 die("Failed to forward open() request [sandbox]"); | 33 die("Failed to forward open() request [sandbox]"); |
| 33 } | 34 } |
| 35 Debug::elapsed(tm, __NR_open); |
| 34 return static_cast<int>(rc); | 36 return static_cast<int>(rc); |
| 35 } | 37 } |
| 36 | 38 |
| 37 bool Sandbox::process_open(int parentMapsFd, int sandboxFd, int threadFdPub, | 39 bool Sandbox::process_open(int parentMapsFd, int sandboxFd, int threadFdPub, |
| 38 int threadFd, SecureMem::Args* mem) { | 40 int threadFd, SecureMem::Args* mem) { |
| 39 // Read request | 41 // Read request |
| 40 SysCalls sys; | 42 SysCalls sys; |
| 41 Open open_req; | 43 Open open_req; |
| 42 if (read(sys, sandboxFd, &open_req, sizeof(open_req)) != sizeof(open_req)) { | 44 if (read(sys, sandboxFd, &open_req, sizeof(open_req)) != sizeof(open_req)) { |
| 43 read_parm_failed: | 45 read_parm_failed: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 "\"").c_str()); | 89 "\"").c_str()); |
| 88 | 90 |
| 89 // Tell trusted thread to open the file. | 91 // Tell trusted thread to open the file. |
| 90 SecureMem::sendSystemCall(threadFdPub, true, parentMapsFd, mem, __NR_open, | 92 SecureMem::sendSystemCall(threadFdPub, true, parentMapsFd, mem, __NR_open, |
| 91 mem->pathname - (char*)mem + (char*)mem->self, | 93 mem->pathname - (char*)mem + (char*)mem->self, |
| 92 open_req.flags, open_req.mode); | 94 open_req.flags, open_req.mode); |
| 93 return true; | 95 return true; |
| 94 } | 96 } |
| 95 | 97 |
| 96 } // namespace | 98 } // namespace |
| OLD | NEW |