Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: sandbox/win/src/process_mitigations_test.cc

Issue 1847213002: Make second param for TestChildProcess optional. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/process/launch.h" 9 #include "base/process/launch.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 EXPECT_EQ((is_success_test ? sandbox::SBOX_TEST_SUCCEEDED 198 EXPECT_EQ((is_success_test ? sandbox::SBOX_TEST_SUCCEEDED
199 : sandbox::SBOX_TEST_FAILED), 199 : sandbox::SBOX_TEST_FAILED),
200 runner.RunTest(test.c_str())); 200 runner.RunTest(test.c_str()));
201 } 201 }
202 202
203 } // namespace 203 } // namespace
204 204
205 namespace sandbox { 205 namespace sandbox {
206 206
207 // A shared helper test command that will attempt to CreateProcess 207 // A shared helper test command that will attempt to CreateProcess
208 // with a given command line. The second parameter, if set to non-zero 208 // with a given command line. The second optional parameter, if set to non-zero
penny 2016/04/01 17:20:30 <whisper>comma after 'non-zero'?</whisper> :)
Will Harris 2016/04/01 18:23:52 actually it had a comma but it went over 80chars s
penny 2016/04/01 18:35:36 ROFL
209 // will cause the child process to return exit code STATUS_ACCESS_VIOLATION. 209 // will cause the child process to return exit code STATUS_ACCESS_VIOLATION.
210 // 210 //
211 // ***Make sure you've enabled basic process creation in the 211 // ***Make sure you've enabled basic process creation in the
212 // test sandbox settings via: 212 // test sandbox settings via:
213 // sandbox::TargetPolicy::SetJobLevel(), 213 // sandbox::TargetPolicy::SetJobLevel(),
214 // sandbox::TargetPolicy::SetTokenLevel(), 214 // sandbox::TargetPolicy::SetTokenLevel(),
215 // and TestRunner::SetDisableCsrss(). 215 // and TestRunner::SetDisableCsrss().
216 SBOX_TESTS_COMMAND int TestChildProcess(int argc, wchar_t** argv) { 216 SBOX_TESTS_COMMAND int TestChildProcess(int argc, wchar_t** argv) {
217 if (argc < 2) 217 if (argc < 1)
218 return SBOX_TEST_INVALID_PARAMETER; 218 return SBOX_TEST_INVALID_PARAMETER;
219 219
220 int desired_exit_code = _wtoi(argv[1]); 220 int desired_exit_code = 0;
221 if (desired_exit_code) 221
222 if (argc == 2) {
223 desired_exit_code = _wtoi(argv[1]);
224 if (desired_exit_code)
222 desired_exit_code = STATUS_ACCESS_VIOLATION; 225 desired_exit_code = STATUS_ACCESS_VIOLATION;
226 }
223 227
224 std::wstring cmd = argv[0]; 228 std::wstring cmd = argv[0];
225 base::LaunchOptions options = base::LaunchOptionsForTest(); 229 base::LaunchOptions options = base::LaunchOptionsForTest();
226 base::Process setup_proc = base::LaunchProcess(cmd.c_str(), options); 230 base::Process setup_proc = base::LaunchProcess(cmd.c_str(), options);
227 231
228 if (setup_proc.IsValid()) { 232 if (setup_proc.IsValid()) {
229 setup_proc.Terminate(desired_exit_code, false); 233 setup_proc.Terminate(desired_exit_code, false);
230 return SBOX_TEST_SUCCEEDED; 234 return SBOX_TEST_SUCCEEDED;
231 } 235 }
232 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED". 236 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED".
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 test_command += cmd.value().c_str(); 707 test_command += cmd.value().c_str();
704 test_command += L" 0"; 708 test_command += L" 0";
705 709
706 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(test_command.c_str())); 710 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(test_command.c_str()));
707 } 711 }
708 712
709 // This test validates that we can spawn a child process if 713 // This test validates that we can spawn a child process if
710 // MITIGATION_CHILD_PROCESS_CREATION_RESTRICTED mitigation is 714 // MITIGATION_CHILD_PROCESS_CREATION_RESTRICTED mitigation is
711 // not set. This also tests that a crashing child process is correctly handled 715 // not set. This also tests that a crashing child process is correctly handled
712 // by the broker. 716 // by the broker.
713 TEST(ProcessMitigationsTest, CheckChildProcessSuccessAbnormalExit) { 717 TEST(ProcessMitigationsTest, CheckChildProcessSuccessAbnormalExit) {
penny 2016/04/01 17:20:30 In terms of process_mitigations_test.cc, this new
Will Harris 2016/04/01 18:23:52 yes good point this should maybe go into job tests
714 TestRunner runner; 718 TestRunner runner;
715 sandbox::TargetPolicy* policy = runner.GetPolicy(); 719 sandbox::TargetPolicy* policy = runner.GetPolicy();
716 720
717 // Set a policy that would normally allow for process creation. 721 // Set a policy that would normally allow for process creation.
718 policy->SetJobLevel(JOB_INTERACTIVE, 0); 722 policy->SetJobLevel(JOB_INTERACTIVE, 0);
719 policy->SetTokenLevel(USER_UNPROTECTED, USER_UNPROTECTED); 723 policy->SetTokenLevel(USER_UNPROTECTED, USER_UNPROTECTED);
720 runner.SetDisableCsrss(false); 724 runner.SetDisableCsrss(false);
721 725
722 base::FilePath cmd; 726 base::FilePath cmd;
723 EXPECT_TRUE(base::PathService::Get(base::DIR_SYSTEM, &cmd)); 727 EXPECT_TRUE(base::PathService::Get(base::DIR_SYSTEM, &cmd));
724 cmd = cmd.Append(L"calc.exe"); 728 cmd = cmd.Append(L"calc.exe");
725 729
726 std::wstring test_command = L"TestChildProcess "; 730 std::wstring test_command = L"TestChildProcess ";
727 test_command += cmd.value().c_str(); 731 test_command += cmd.value().c_str();
728 test_command += L" 1"; 732 test_command += L" 1";
729 733
730 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str())); 734 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str()));
731 } 735 }
732 736
733 // This test validates that setting the 737 // This test validates that setting the
734 // MITIGATION_CHILD_PROCESS_CREATION_RESTRICTED mitigation prevents 738 // MITIGATION_CHILD_PROCESS_CREATION_RESTRICTED mitigation prevents
735 // the spawning of child processes. This also tests that a crashing child 739 // the spawning of child processes. This also tests that a crashing child
736 // process is correctly handled by the broker. 740 // process is correctly handled by the broker.
737 TEST(ProcessMitigationsTest, CheckChildProcessFailureAbnormalExit) { 741 TEST(ProcessMitigationsTest, CheckChildProcessFailureAbnormalExit) {
penny 2016/04/01 17:20:30 I'm fairly sure this new test has the exact same r
Will Harris 2016/04/01 18:23:52 Done. Removed.
738 TestRunner runner; 742 TestRunner runner;
739 sandbox::TargetPolicy* policy = runner.GetPolicy(); 743 sandbox::TargetPolicy* policy = runner.GetPolicy();
740 744
741 // Now set the job level to be <= JOB_LIMITED_USER 745 // Now set the job level to be <= JOB_LIMITED_USER
742 // and ensure we can no longer create a child process. 746 // and ensure we can no longer create a child process.
743 policy->SetJobLevel(JOB_LIMITED_USER, 0); 747 policy->SetJobLevel(JOB_LIMITED_USER, 0);
744 policy->SetTokenLevel(USER_UNPROTECTED, USER_UNPROTECTED); 748 policy->SetTokenLevel(USER_UNPROTECTED, USER_UNPROTECTED);
745 runner.SetDisableCsrss(false); 749 runner.SetDisableCsrss(false);
746 750
747 base::FilePath cmd; 751 base::FilePath cmd;
748 EXPECT_TRUE(base::PathService::Get(base::DIR_SYSTEM, &cmd)); 752 EXPECT_TRUE(base::PathService::Get(base::DIR_SYSTEM, &cmd));
749 cmd = cmd.Append(L"calc.exe"); 753 cmd = cmd.Append(L"calc.exe");
750 754
751 std::wstring test_command = L"TestChildProcess "; 755 std::wstring test_command = L"TestChildProcess ";
752 test_command += cmd.value().c_str(); 756 test_command += cmd.value().c_str();
753 test_command += L" 1"; 757 test_command += L" 1";
754 758
755 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(test_command.c_str())); 759 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(test_command.c_str()));
756 } 760 }
757 761
758 } // namespace sandbox 762 } // namespace sandbox
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698