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/bind_helpers.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
17 #include "sandbox/linux/services/scoped_process.h" | 18 #include "sandbox/linux/services/scoped_process.h" |
18 #include "sandbox/linux/services/yama.h" | 19 #include "sandbox/linux/services/yama.h" |
19 #include "sandbox/linux/tests/unit_tests.h" | 20 #include "sandbox/linux/tests/unit_tests.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 namespace sandbox { | 23 namespace sandbox { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // However, parent can ptrace process1. | 145 // However, parent can ptrace process1. |
145 ASSERT_TRUE(CanPtrace(process1.GetPid())); | 146 ASSERT_TRUE(CanPtrace(process1.GetPid())); |
146 | 147 |
147 // A sibling can ptrace process2 which disables any Yama protection. | 148 // A sibling can ptrace process2 which disables any Yama protection. |
148 ScopedProcess process2(base::Bind(&SetYamaRestrictions, false)); | 149 ScopedProcess process2(base::Bind(&SetYamaRestrictions, false)); |
149 ASSERT_TRUE(process2.WaitForClosureToRun()); | 150 ASSERT_TRUE(process2.WaitForClosureToRun()); |
150 ASSERT_TRUE(CanSubProcessPtrace(process2.GetPid())); | 151 ASSERT_TRUE(CanSubProcessPtrace(process2.GetPid())); |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 void DoNothing() {} | |
155 | |
156 SANDBOX_TEST(Yama, RestrictPtraceIsDefault) { | 155 SANDBOX_TEST(Yama, RestrictPtraceIsDefault) { |
157 if (!Yama::IsPresent() || HasLinux32Bug()) | 156 if (!Yama::IsPresent() || HasLinux32Bug()) |
158 return; | 157 return; |
159 | 158 |
160 CHECK(Yama::DisableYamaRestrictions()); | 159 CHECK(Yama::DisableYamaRestrictions()); |
161 ScopedProcess process1(base::Bind(&DoNothing)); | 160 ScopedProcess process1(base::Bind(&base::DoNothing)); |
162 | 161 |
163 if (Yama::IsEnforcing()) { | 162 if (Yama::IsEnforcing()) { |
164 // Check that process1 is protected by Yama, even though it has | 163 // Check that process1 is protected by Yama, even though it has |
165 // been created from a process that disabled Yama. | 164 // been created from a process that disabled Yama. |
166 CHECK(!CanSubProcessPtrace(process1.GetPid())); | 165 CHECK(!CanSubProcessPtrace(process1.GetPid())); |
167 } | 166 } |
168 } | 167 } |
169 | 168 |
170 } // namespace | 169 } // namespace |
171 | 170 |
172 } // namespace sandbox | 171 } // namespace sandbox |
OLD | NEW |