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

Unified Diff: sandbox/win/src/process_mitigations_test.cc

Issue 1856993003: Implement sandbox hooks to forward OPM related GDI system calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replaced shared memory implementation. 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 side-by-side diff with in-line comments
Download patch
Index: sandbox/win/src/process_mitigations_test.cc
diff --git a/sandbox/win/src/process_mitigations_test.cc b/sandbox/win/src/process_mitigations_test.cc
index 783cc68e869aee7fc8b7ae4864fbffc0cbb27e7a..9ffdf2672fe185bc360d5c1cef4a7c34b700768f 100644
--- a/sandbox/win/src/process_mitigations_test.cc
+++ b/sandbox/win/src/process_mitigations_test.cc
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <map>
+#include <string>
+
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
@@ -200,6 +203,38 @@ void TestWin10ImageLoadLowLabel(bool is_success_test) {
runner.RunTest(test.c_str()));
}
+BOOL CALLBACK MonitorEnumCallback(HMONITOR monitor,
+ HDC hdc_monitor,
+ LPRECT rect_monitor,
+ LPARAM data) {
+ std::map<HMONITOR, base::string16>& monitors =
+ *reinterpret_cast<std::map<HMONITOR, base::string16>*>(data);
+ MONITORINFOEXW monitor_info = {};
+ monitor_info.cbSize = sizeof(monitor_info);
+
+ if (!GetMonitorInfoW(monitor, reinterpret_cast<MONITORINFO*>(&monitor_info)))
+ return FALSE;
+ monitors[monitor] = monitor_info.szDevice;
+ return TRUE;
+}
+
+std::map<HMONITOR, std::wstring> EnumerateMonitors() {
+ std::map<HMONITOR, std::wstring> result;
+ ::EnumDisplayMonitors(nullptr, nullptr, MonitorEnumCallback,
+ reinterpret_cast<LPARAM>(&result));
+ return result;
+}
+
+std::wstring MonitorListToString(
+ const std::map<HMONITOR, std::wstring>& monitors) {
+ std::wstring monitors_string;
+ for (const auto& monitor : monitors) {
+ base::StringAppendF(&monitors_string, L" %p %s", monitor.first,
+ monitor.second.c_str());
+ }
+ return monitors_string;
+}
+
} // namespace
namespace sandbox {
@@ -380,6 +415,32 @@ SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t **argv) {
return SBOX_TEST_SUCCEEDED;
}
+SBOX_TESTS_COMMAND int CheckOPMGetDisplayMonitors(int argc, wchar_t** argv) {
+ if (argc == 0 || (argc & 1) != 0)
+ return SBOX_TEST_FIRST_ERROR;
+
+ std::map<HMONITOR, base::string16> monitors = EnumerateMonitors();
+ std::map<HMONITOR, base::string16> monitors_to_test;
+
+ for (int index = 0; index < argc; index += 2) {
+ HMONITOR monitor =
+ reinterpret_cast<HMONITOR>(wcstoull(argv[index], nullptr, 16));
+ monitors_to_test[monitor] = argv[index + 1];
+ }
+
+ if (monitors.size() != monitors_to_test.size())
+ return SBOX_TEST_SECOND_ERROR;
+
+ for (auto it = monitors.begin(); it != monitors.end(); ++it) {
+ auto result = monitors_to_test.find(it->first);
+ if (result == monitors_to_test.end())
+ return SBOX_TEST_THIRD_ERROR;
+ if (result->second != it->second)
+ return SBOX_TEST_FOURTH_ERROR;
+ }
+ return SBOX_TEST_SUCCEEDED;
+}
+
// This test validates that setting the MITIGATION_WIN32K_DISABLE mitigation on
// the target process causes the launch to fail in process initialization.
// The test process itself links against user32/gdi32.
@@ -412,6 +473,36 @@ TEST(ProcessMitigationsTest, CheckWin8Win32KLockDownSuccess) {
sandbox::TargetPolicy::FAKE_USER_GDI_INIT, NULL),
sandbox::SBOX_ALL_OK);
EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown"));
+
+ // Also check that we can't access redirected APIs.
+ std::map<HMONITOR, std::wstring> monitors = EnumerateMonitors();
+ std::wstring test_command =
+ L"CheckOPMGetDisplayMonitors" + MonitorListToString(monitors);
+ EXPECT_NE(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str()));
+}
+
+// This test validates the even though we're running under win32k lockdown
+// we can use the IPC redirection to enumerate the list of monitors.
+TEST(ProcessMitigationsTest, CheckWin8OpmRedirectionSuccess) {
+ if (base::win::GetVersion() < base::win::VERSION_WIN8)
+ return;
+
+ TestRunner runner;
+ sandbox::TargetPolicy* policy = runner.GetPolicy();
+
+ EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_WIN32K_DISABLE),
+ SBOX_ALL_OK);
+ EXPECT_EQ(policy->AddRule(sandbox::TargetPolicy::SUBSYS_WIN32K_LOCKDOWN,
+ sandbox::TargetPolicy::IMPLEMENT_OPM_APIS, NULL),
+ sandbox::SBOX_ALL_OK);
+ policy->SetEnableOPMRedirection();
+ EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown"));
+
+ std::map<HMONITOR, std::wstring> monitors = EnumerateMonitors();
+ std::wstring test_command =
+ L"CheckOPMGetDisplayMonitors" + MonitorListToString(monitors);
+ printf("%ls\n", test_command.c_str());
+ EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str()));
}
//------------------------------------------------------------------------------

Powered by Google App Engine
This is Rietveld 408576698