OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <errno.h> | 5 #include <errno.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <sys/ptrace.h> | 7 #include <sys/ptrace.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 15 #include "base/strings/string_util.h" |
| 16 #include "base/sys_info.h" |
15 #include "sandbox/linux/services/scoped_process.h" | 17 #include "sandbox/linux/services/scoped_process.h" |
16 #include "sandbox/linux/services/yama.h" | 18 #include "sandbox/linux/services/yama.h" |
17 #include "sandbox/linux/tests/unit_tests.h" | 19 #include "sandbox/linux/tests/unit_tests.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 namespace sandbox { | 22 namespace sandbox { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
| 26 bool HasLinux32Bug() { |
| 27 #if defined(__i386__) |
| 28 // On 3.2 kernels, yama doesn't work for 32-bit binaries on 64-bit kernels. |
| 29 // This is fixed in 3.4. |
| 30 bool is_kernel_64bit = |
| 31 base::SysInfo::OperatingSystemArchitecture() == "x86_64"; |
| 32 bool is_linux = base::SysInfo::OperatingSystemName() == "Linux"; |
| 33 bool is_3_dot_2 = StartsWithASCII( |
| 34 base::SysInfo::OperatingSystemVersion(), "3.2", /*case_sensitive=*/false); |
| 35 if (is_kernel_64bit && is_linux && is_3_dot_2) |
| 36 return true; |
| 37 #endif // defined(__i386__) |
| 38 return false; |
| 39 } |
| 40 |
24 bool CanPtrace(pid_t pid) { | 41 bool CanPtrace(pid_t pid) { |
25 int ret; | 42 int ret; |
26 ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL); | 43 ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL); |
27 if (ret == -1) { | 44 if (ret == -1) { |
28 CHECK_EQ(EPERM, errno); | 45 CHECK_EQ(EPERM, errno); |
29 return false; | 46 return false; |
30 } | 47 } |
31 // Wait for the process to be stopped so that it can be detached. | 48 // Wait for the process to be stopped so that it can be detached. |
32 siginfo_t process_info; | 49 siginfo_t process_info; |
33 int wait_ret = HANDLE_EINTR(waitid(P_PID, pid, &process_info, WSTOPPED)); | 50 int wait_ret = HANDLE_EINTR(waitid(P_PID, pid, &process_info, WSTOPPED)); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 if (Yama::IsEnforcing()) { | 160 if (Yama::IsEnforcing()) { |
144 // Check that process1 is protected by Yama, even though it has | 161 // Check that process1 is protected by Yama, even though it has |
145 // been created from a process that disabled Yama. | 162 // been created from a process that disabled Yama. |
146 CHECK(!CanSubProcessPtrace(process1.GetPid())); | 163 CHECK(!CanSubProcessPtrace(process1.GetPid())); |
147 } | 164 } |
148 } | 165 } |
149 | 166 |
150 } // namespace | 167 } // namespace |
151 | 168 |
152 } // namespace sandbox | 169 } // namespace sandbox |
OLD | NEW |