| 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" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 17 #include "sandbox/linux/services/scoped_process.h" | 17 #include "sandbox/linux/services/scoped_process.h" |
| 18 #include "sandbox/linux/services/yama.h" | 18 #include "sandbox/linux/services/yama.h" |
| 19 #include "sandbox/linux/tests/unit_tests.h" | 19 #include "sandbox/linux/tests/unit_tests.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 namespace sandbox { | 22 namespace sandbox { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 bool HasLinux32Bug() { | 26 bool HasLinux32Bug() { |
| 27 #if defined(__i386__) | |
| 28 // On 3.2 kernels, yama doesn't work for 32-bit binaries on 64-bit kernels. | 27 // On 3.2 kernels, yama doesn't work for 32-bit binaries on 64-bit kernels. |
| 29 // This is fixed in 3.4. | 28 // This is fixed in 3.4. |
| 30 bool is_kernel_64bit = | 29 return prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0) < 0 && |
| 31 base::SysInfo::OperatingSystemArchitecture() == "x86_64"; | 30 errno == EINVAL; |
| 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 } | 31 } |
| 40 | 32 |
| 41 bool CanPtrace(pid_t pid) { | 33 bool CanPtrace(pid_t pid) { |
| 42 int ret; | 34 int ret; |
| 43 ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL); | 35 ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL); |
| 44 if (ret == -1) { | 36 if (ret == -1) { |
| 45 CHECK_EQ(EPERM, errno); | 37 CHECK_EQ(EPERM, errno); |
| 46 return false; | 38 return false; |
| 47 } | 39 } |
| 48 // Wait for the process to be stopped so that it can be detached. | 40 // Wait for the process to be stopped so that it can be detached. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (Yama::IsEnforcing()) { | 155 if (Yama::IsEnforcing()) { |
| 164 // Check that process1 is protected by Yama, even though it has | 156 // Check that process1 is protected by Yama, even though it has |
| 165 // been created from a process that disabled Yama. | 157 // been created from a process that disabled Yama. |
| 166 CHECK(!CanSubProcessPtrace(process1.GetPid())); | 158 CHECK(!CanSubProcessPtrace(process1.GetPid())); |
| 167 } | 159 } |
| 168 } | 160 } |
| 169 | 161 |
| 170 } // namespace | 162 } // namespace |
| 171 | 163 |
| 172 } // namespace sandbox | 164 } // namespace sandbox |
| OLD | NEW |