Commit 45e371a2 authored by rickyz's avatar rickyz Committed by Commit bot

Correct PROCESS_BASIC_INFORMATION for 64 bit Windows.

Based on the structure given at https://msdn.microsoft.com/en-us/library/windows/desktop/ms684280(v=vs.85).aspx.

BUG=528450

Review URL: https://codereview.chromium.org/1328703003

Cr-Commit-Position: refs/heads/master@{#347842}
parent 2d8d0e8d
...@@ -246,6 +246,7 @@ test("sbox_unittests") { ...@@ -246,6 +246,7 @@ test("sbox_unittests") {
"src/policy_low_level_unittest.cc", "src/policy_low_level_unittest.cc",
"src/policy_opcodes_unittest.cc", "src/policy_opcodes_unittest.cc",
"src/restricted_token_unittest.cc", "src/restricted_token_unittest.cc",
"src/sandbox_nt_util_unittest.cc",
"src/service_resolver_unittest.cc", "src/service_resolver_unittest.cc",
"src/sid_unittest.cc", "src/sid_unittest.cc",
"src/threadpool_unittest.cc", "src/threadpool_unittest.cc",
......
...@@ -276,6 +276,7 @@ ...@@ -276,6 +276,7 @@
'src/policy_low_level_unittest.cc', 'src/policy_low_level_unittest.cc',
'src/policy_opcodes_unittest.cc', 'src/policy_opcodes_unittest.cc',
'src/ipc_unittest.cc', 'src/ipc_unittest.cc',
'src/sandbox_nt_util_unittest.cc',
'src/threadpool_unittest.cc', 'src/threadpool_unittest.cc',
'src/win_utils_unittest.cc', 'src/win_utils_unittest.cc',
'tests/common/test_utils.cc', 'tests/common/test_utils.cc',
......
...@@ -308,15 +308,27 @@ typedef enum _PROCESSINFOCLASS { ...@@ -308,15 +308,27 @@ typedef enum _PROCESSINFOCLASS {
} PROCESSINFOCLASS; } PROCESSINFOCLASS;
typedef PVOID PPEB; typedef PVOID PPEB;
typedef PVOID KPRIORITY; typedef LONG KPRIORITY;
typedef struct _PROCESS_BASIC_INFORMATION { typedef struct _PROCESS_BASIC_INFORMATION {
NTSTATUS ExitStatus; union {
NTSTATUS ExitStatus;
PVOID padding_for_x64_0;
};
PPEB PebBaseAddress; PPEB PebBaseAddress;
KAFFINITY AffinityMask; KAFFINITY AffinityMask;
KPRIORITY BasePriority; union {
ULONG UniqueProcessId; KPRIORITY BasePriority;
ULONG InheritedFromUniqueProcessId; PVOID padding_for_x64_1;
};
union {
DWORD UniqueProcessId;
PVOID padding_for_x64_2;
};
union {
DWORD InheritedFromUniqueProcessId;
PVOID padding_for_x64_3;
};
} PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION; } PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION;
typedef NTSTATUS (WINAPI *NtQueryInformationProcessFunction)( typedef NTSTATUS (WINAPI *NtQueryInformationProcessFunction)(
......
...@@ -38,7 +38,7 @@ SANDBOX_INTERCEPT NtExports g_nt; ...@@ -38,7 +38,7 @@ SANDBOX_INTERCEPT NtExports g_nt;
if (NULL == g_nt.member) \ if (NULL == g_nt.member) \
return false return false
bool SetupNtdllImports(TargetProcess *child) { bool InitGlobalNt() {
HMODULE ntdll = ::GetModuleHandle(kNtdllName); HMODULE ntdll = ::GetModuleHandle(kNtdllName);
base::win::PEImage ntdll_image(ntdll); base::win::PEImage ntdll_image(ntdll);
...@@ -75,6 +75,14 @@ bool SetupNtdllImports(TargetProcess *child) { ...@@ -75,6 +75,14 @@ bool SetupNtdllImports(TargetProcess *child) {
INIT_GLOBAL_RTL(wcslen); INIT_GLOBAL_RTL(wcslen);
INIT_GLOBAL_RTL(memcpy); INIT_GLOBAL_RTL(memcpy);
return true;
}
bool SetupNtdllImports(TargetProcess *child) {
if (!InitGlobalNt()) {
return false;
}
#ifndef NDEBUG #ifndef NDEBUG
// Verify that the structure is fully initialized. // Verify that the structure is fully initialized.
for (size_t i = 0; i < sizeof(g_nt)/sizeof(void*); i++) for (size_t i = 0; i < sizeof(g_nt)/sizeof(void*); i++)
......
...@@ -11,6 +11,9 @@ namespace sandbox { ...@@ -11,6 +11,9 @@ namespace sandbox {
class TargetProcess; class TargetProcess;
// Initializes global imported symbols from ntdll.
bool InitGlobalNt();
// Sets up interceptions not controlled by explicit policies. // Sets up interceptions not controlled by explicit policies.
bool SetupBasicInterceptions(InterceptionManager* manager); bool SetupBasicInterceptions(InterceptionManager* manager);
......
...@@ -337,7 +337,7 @@ NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, ...@@ -337,7 +337,7 @@ NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object,
return ret; return ret;
} }
NTSTATUS GetProcessId(HANDLE process, ULONG *process_id) { NTSTATUS GetProcessId(HANDLE process, DWORD *process_id) {
PROCESS_BASIC_INFORMATION proc_info; PROCESS_BASIC_INFORMATION proc_info;
ULONG bytes_returned; ULONG bytes_returned;
...@@ -355,7 +355,7 @@ bool IsSameProcess(HANDLE process) { ...@@ -355,7 +355,7 @@ bool IsSameProcess(HANDLE process) {
if (NtCurrentProcess == process) if (NtCurrentProcess == process)
return true; return true;
static ULONG s_process_id = 0; static DWORD s_process_id = 0;
if (!s_process_id) { if (!s_process_id) {
NTSTATUS ret = GetProcessId(NtCurrentProcess, &s_process_id); NTSTATUS ret = GetProcessId(NtCurrentProcess, &s_process_id);
...@@ -363,7 +363,7 @@ bool IsSameProcess(HANDLE process) { ...@@ -363,7 +363,7 @@ bool IsSameProcess(HANDLE process) {
return false; return false;
} }
ULONG process_id; DWORD process_id;
NTSTATUS ret = GetProcessId(process, &process_id); NTSTATUS ret = GetProcessId(process, &process_id);
if (!NT_SUCCESS(ret)) if (!NT_SUCCESS(ret))
return false; return false;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <windows.h>
#include "base/win/scoped_handle.h"
#include "base/win/scoped_process_information.h"
#include "sandbox/win/src/policy_broker.h"
#include "sandbox/win/src/sandbox_nt_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sandbox {
namespace {
TEST(SandboxNtUtil, IsSameProcessPseudoHandle) {
InitGlobalNt();
HANDLE current_process_pseudo = GetCurrentProcess();
EXPECT_TRUE(IsSameProcess(current_process_pseudo));
}
TEST(SandboxNtUtil, IsSameProcessNonPseudoHandle) {
InitGlobalNt();
base::win::ScopedHandle current_process(
OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()));
ASSERT_TRUE(current_process.IsValid());
EXPECT_TRUE(IsSameProcess(current_process.Get()));
}
TEST(SandboxNtUtil, IsSameProcessDifferentProcess) {
InitGlobalNt();
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi = {};
wchar_t notepad[] = L"notepad";
ASSERT_TRUE(CreateProcessW(nullptr, notepad, nullptr, nullptr, FALSE, 0,
nullptr, nullptr, &si, &pi));
base::win::ScopedProcessInformation process_info(pi);
EXPECT_FALSE(IsSameProcess(process_info.process_handle()));
EXPECT_TRUE(TerminateProcess(process_info.process_handle(), 0));
}
} // namespace
} // namespace sandbox
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment