| 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_ioctl(int d, int req, void *arg) { | 10 int Sandbox::sandbox_ioctl(int d, int req, void *arg) { |
| 11 Debug::syscall(__NR_ioctl, "Executing handler"); | 11 long long tm; |
| 12 Debug::syscall(&tm, __NR_ioctl, "Executing handler"); |
| 12 struct { | 13 struct { |
| 13 int sysnum; | 14 int sysnum; |
| 14 long long cookie; | 15 long long cookie; |
| 15 IOCtl ioctl_req; | 16 IOCtl ioctl_req; |
| 16 } __attribute__((packed)) request; | 17 } __attribute__((packed)) request; |
| 17 request.sysnum = __NR_ioctl; | 18 request.sysnum = __NR_ioctl; |
| 18 request.cookie = cookie(); | 19 request.cookie = cookie(); |
| 19 request.ioctl_req.d = d; | 20 request.ioctl_req.d = d; |
| 20 request.ioctl_req.req = req; | 21 request.ioctl_req.req = req; |
| 21 request.ioctl_req.arg = arg; | 22 request.ioctl_req.arg = arg; |
| 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 ioctl() request [sandbox]"); | 29 die("Failed to forward ioctl() request [sandbox]"); |
| 29 } | 30 } |
| 31 Debug::elapsed(tm, __NR_ioctl); |
| 30 return static_cast<int>(rc); | 32 return static_cast<int>(rc); |
| 31 } | 33 } |
| 32 | 34 |
| 33 bool Sandbox::process_ioctl(int parentMapsFd, int sandboxFd, int threadFdPub, | 35 bool Sandbox::process_ioctl(int parentMapsFd, int sandboxFd, int threadFdPub, |
| 34 int threadFd, SecureMem::Args* mem) { | 36 int threadFd, SecureMem::Args* mem) { |
| 35 // Read request | 37 // Read request |
| 36 IOCtl ioctl_req; | 38 IOCtl ioctl_req; |
| 37 SysCalls sys; | 39 SysCalls sys; |
| 38 if (read(sys, sandboxFd, &ioctl_req, sizeof(ioctl_req)) !=sizeof(ioctl_req)){ | 40 if (read(sys, sandboxFd, &ioctl_req, sizeof(ioctl_req)) !=sizeof(ioctl_req)){ |
| 39 die("Failed to read parameters for ioctl() [process]"); | 41 die("Failed to read parameters for ioctl() [process]"); |
| 40 } | 42 } |
| 41 int rc = -EINVAL; | 43 int rc = -EINVAL; |
| 42 switch (ioctl_req.req) { | 44 switch (ioctl_req.req) { |
| 43 case TCGETS: | 45 case TCGETS: |
| 44 case TIOCGWINSZ: | 46 case TIOCGWINSZ: |
| 45 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_ioctl, | 47 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_ioctl, |
| 46 ioctl_req.d, ioctl_req.req, ioctl_req.arg); | 48 ioctl_req.d, ioctl_req.req, ioctl_req.arg); |
| 47 return true; | 49 return true; |
| 48 default: | 50 default: |
| 49 std::cerr << "Unsupported ioctl: 0x" << std::hex << ioctl_req.req << | 51 std::cerr << "Unsupported ioctl: 0x" << std::hex << ioctl_req.req << |
| 50 std::endl; | 52 std::endl; |
| 51 SecureMem::abandonSystemCall(threadFd, rc); | 53 SecureMem::abandonSystemCall(threadFd, rc); |
| 52 return false; | 54 return false; |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 } // namespace | 58 } // namespace |
| OLD | NEW |