blob: b1ddcd92ec847b5b8c52238228fa6fe5b9d092f7 [file] [log] [blame]
pennymac4e0b5f22016-07-19 19:15:451// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome_elf/chrome_elf_security.h"
6
7#include <assert.h>
8#include <windows.h>
9#include <versionhelpers.h> // windows.h must be before
10
11#include "chrome_elf/chrome_elf_constants.h"
12#include "chrome_elf/nt_registry/nt_registry.h"
13
14void EarlyBrowserSecurity() {
15 typedef decltype(SetProcessMitigationPolicy)* SetProcessMitigationPolicyFunc;
16
17 // This function is called from within DllMain.
18 // Don't do anything naughty while we have the loader lock.
19 NTSTATUS ret_val = STATUS_SUCCESS;
20 HANDLE handle = INVALID_HANDLE_VALUE;
21
22 // Check for kRegistrySecurityFinchPath. If it exists,
23 // we do NOT disable extension points. (Emergency off flag.)
24 if (nt::OpenRegKey(nt::HKCU, elf_sec::kRegSecurityFinchPath, KEY_QUERY_VALUE,
25 &handle, &ret_val)) {
26 nt::CloseRegKey(handle);
27 return;
28 }
29#ifdef _DEBUG
30 // The only failure expected is for the path not existing.
31 if (ret_val != STATUS_OBJECT_NAME_NOT_FOUND)
32 assert(false);
33#endif
34
35 if (::IsWindows8OrGreater()) {
36 SetProcessMitigationPolicyFunc set_process_mitigation_policy =
37 reinterpret_cast<SetProcessMitigationPolicyFunc>(::GetProcAddress(
38 ::GetModuleHandleW(L"kernel32.dll"), "SetProcessMitigationPolicy"));
39 if (set_process_mitigation_policy) {
40 // Disable extension points in this process.
41 // (Legacy hooking.)
42 PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {};
43 policy.DisableExtensionPoints = true;
44 set_process_mitigation_policy(ProcessExtensionPointDisablePolicy, &policy,
45 sizeof(policy));
46 }
47 }
48 return;
49}