Skip to content

Commit

Permalink
Use an enum for IPC tags in sandbox.
Browse files Browse the repository at this point in the history
This converts IPC tags from a mixture of |int| and |unit32_t|
to |class enum IpcTag| with no functional changes.

Change-Id: I4bcece6f92d81851bc9fb8d9c00455012ccc811a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863575
Reviewed-by: Will Harris <wfh@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
Auto-Submit: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708449}
  • Loading branch information
quidity authored and Commit Bot committed Oct 23, 2019
1 parent 863e4f5 commit c8cff7f
Show file tree
Hide file tree
Showing 48 changed files with 402 additions and 360 deletions.
6 changes: 3 additions & 3 deletions sandbox/win/fuzzer/sandbox_ipc_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "sandbox/win/src/crosscall_server.h"
#include "sandbox/win/src/ipc_args.h"
#include "sandbox/win/src/ipc_tags.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
uint32_t output_size = 0;
Expand All @@ -17,9 +18,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (!params.get())
return 0;

uint32_t tag = params->GetTag();
sandbox::IPCParams ipc_params = {0};
ipc_params.ipc_tag = tag;
sandbox::IpcTag tag = params->GetTag();
sandbox::IPCParams ipc_params = {tag};
void* args[sandbox::kMaxIpcParams];
sandbox::GetArgs(params.get(), &ipc_params, args);
sandbox::ReleaseArgs(&ipc_params, args);
Expand Down
16 changes: 9 additions & 7 deletions sandbox/win/src/crosscall_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
// return codes indicate that the IPC transport failed to deliver it.
namespace sandbox {

enum class IpcTag;

// this is the assumed channel size. This can be overridden in a given
// IPC implementation.
const uint32_t kIPCChannelSize = 1024;
Expand Down Expand Up @@ -272,7 +274,7 @@ class CopyHelper<InOutCountedBuffer> {
// CrossCall template with one input parameter
template <typename IPCProvider, typename Par1>
ResultCode CrossCall(IPCProvider& ipc_provider,
uint32_t tag,
IpcTag tag,
const Par1& p1,
CrossCallReturn* answer) {
XCALL_GEN_PARAMS_OBJ(1, call_params);
Expand All @@ -291,7 +293,7 @@ ResultCode CrossCall(IPCProvider& ipc_provider,
// CrossCall template with two input parameters.
template <typename IPCProvider, typename Par1, typename Par2>
ResultCode CrossCall(IPCProvider& ipc_provider,
uint32_t tag,
IpcTag tag,
const Par1& p1,
const Par2& p2,
CrossCallReturn* answer) {
Expand All @@ -312,7 +314,7 @@ ResultCode CrossCall(IPCProvider& ipc_provider,
// CrossCall template with three input parameters.
template <typename IPCProvider, typename Par1, typename Par2, typename Par3>
ResultCode CrossCall(IPCProvider& ipc_provider,
uint32_t tag,
IpcTag tag,
const Par1& p1,
const Par2& p2,
const Par3& p3,
Expand Down Expand Up @@ -340,7 +342,7 @@ template <typename IPCProvider,
typename Par3,
typename Par4>
ResultCode CrossCall(IPCProvider& ipc_provider,
uint32_t tag,
IpcTag tag,
const Par1& p1,
const Par2& p2,
const Par3& p3,
Expand Down Expand Up @@ -372,7 +374,7 @@ template <typename IPCProvider,
typename Par4,
typename Par5>
ResultCode CrossCall(IPCProvider& ipc_provider,
uint32_t tag,
IpcTag tag,
const Par1& p1,
const Par2& p2,
const Par3& p3,
Expand Down Expand Up @@ -408,7 +410,7 @@ template <typename IPCProvider,
typename Par5,
typename Par6>
ResultCode CrossCall(IPCProvider& ipc_provider,
uint32_t tag,
IpcTag tag,
const Par1& p1,
const Par2& p2,
const Par3& p3,
Expand Down Expand Up @@ -448,7 +450,7 @@ template <typename IPCProvider,
typename Par6,
typename Par7>
ResultCode CrossCall(IPCProvider& ipc_provider,
uint32_t tag,
IpcTag tag,
const Par1& p1,
const Par2& p2,
const Par3& p3,
Expand Down
14 changes: 7 additions & 7 deletions sandbox/win/src/crosscall_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#if !defined(SANDBOX_FUZZ_TARGET)
#include "sandbox/win/src/sandbox_nt_types.h"
#endif
#include "sandbox/win/src/ipc_tags.h"
#include "sandbox/win/src/sandbox_types.h"

// This header is part of CrossCall: the sandbox inter-process communication.
Expand Down Expand Up @@ -128,7 +129,7 @@ struct CrossCallReturn {
class CrossCallParams {
public:
// Returns the tag (ipc unique id) associated with this IPC.
uint32_t GetTag() const { return tag_; }
IpcTag GetTag() const { return tag_; }

// Returns the beggining of the buffer where the IPC params can be stored.
// prior to an IPC call
Expand All @@ -153,11 +154,11 @@ class CrossCallParams {

protected:
// constructs the IPC call params. Called only from the derived classes
CrossCallParams(uint32_t tag, uint32_t params_count)
CrossCallParams(IpcTag tag, uint32_t params_count)
: tag_(tag), is_in_out_(0), params_count_(params_count) {}

private:
uint32_t tag_;
IpcTag tag_;
uint32_t is_in_out_;
CrossCallReturn call_return;
const uint32_t params_count_;
Expand Down Expand Up @@ -206,15 +207,14 @@ template <size_t NUMBER_PARAMS, size_t BLOCK_SIZE>
class ActualCallParams : public CrossCallParams {
public:
// constructor. Pass the ipc unique tag as input
explicit ActualCallParams(uint32_t tag)
: CrossCallParams(tag, NUMBER_PARAMS) {
explicit ActualCallParams(IpcTag tag) : CrossCallParams(tag, NUMBER_PARAMS) {
param_info_[0].offset_ =
static_cast<uint32_t>(parameters_ - reinterpret_cast<char*>(this));
}

// Testing-only constructor. Allows setting the |number_params| to a
// wrong value.
ActualCallParams(uint32_t tag, uint32_t number_params)
ActualCallParams(IpcTag tag, uint32_t number_params)
: CrossCallParams(tag, number_params) {
param_info_[0].offset_ =
static_cast<uint32_t>(parameters_ - reinterpret_cast<char*>(this));
Expand Down Expand Up @@ -285,7 +285,7 @@ class ActualCallParams : public CrossCallParams {
uint32_t GetSize() const { return param_info_[NUMBER_PARAMS].offset_; }

protected:
ActualCallParams() : CrossCallParams(0, NUMBER_PARAMS) {}
ActualCallParams() : CrossCallParams(IpcTag::UNUSED, NUMBER_PARAMS) {}

private:
ParamInfo param_info_[NUMBER_PARAMS + 1];
Expand Down
2 changes: 1 addition & 1 deletion sandbox/win/src/crosscall_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool IsSizeWithinRange(uint32_t buffer_size,
return true;
}

CrossCallParamsEx::CrossCallParamsEx() : CrossCallParams(0, 0) {}
CrossCallParamsEx::CrossCallParamsEx() : CrossCallParams(IpcTag::UNUSED, 0) {}

// We override the delete operator because the object's backing memory
// is hand allocated in CreateFromBuffer. We don't override the new operator
Expand Down
7 changes: 4 additions & 3 deletions sandbox/win/src/crosscall_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/macros.h"
#include "base/strings/string16.h"
#include "sandbox/win/src/crosscall_params.h"
#include "sandbox/win/src/ipc_tags.h"

// This is the IPC server interface for CrossCall: The IPC for the Sandbox
// On the server, CrossCall needs two things:
Expand Down Expand Up @@ -152,14 +153,14 @@ struct ClientInfo {

// All IPC-related information to be passed to the IPC handler.
struct IPCInfo {
int ipc_tag;
IpcTag ipc_tag;
const ClientInfo* client_info;
CrossCallReturn return_info;
};

// This structure identifies IPC signatures.
struct IPCParams {
int ipc_tag;
IpcTag ipc_tag;
ArgType args[kMaxIpcParams];

bool Matches(IPCParams* other) const {
Expand Down Expand Up @@ -240,7 +241,7 @@ class Dispatcher {

// Called when a target proces is created, to setup the interceptions related
// with the given service (IPC).
virtual bool SetupService(InterceptionManager* manager, int service) = 0;
virtual bool SetupService(InterceptionManager* manager, IpcTag service) = 0;

Dispatcher();
virtual ~Dispatcher();
Expand Down
32 changes: 16 additions & 16 deletions sandbox/win/src/filesystem_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ namespace sandbox {
FilesystemDispatcher::FilesystemDispatcher(PolicyBase* policy_base)
: policy_base_(policy_base) {
static const IPCCall create_params = {
{IPC_NTCREATEFILE_TAG,
{IpcTag::NTCREATEFILE,
{WCHAR_TYPE, UINT32_TYPE, UINT32_TYPE, UINT32_TYPE, UINT32_TYPE,
UINT32_TYPE, UINT32_TYPE}},
reinterpret_cast<CallbackGeneric>(&FilesystemDispatcher::NtCreateFile)};

static const IPCCall open_file = {
{IPC_NTOPENFILE_TAG,
{IpcTag::NTOPENFILE,
{WCHAR_TYPE, UINT32_TYPE, UINT32_TYPE, UINT32_TYPE, UINT32_TYPE}},
reinterpret_cast<CallbackGeneric>(&FilesystemDispatcher::NtOpenFile)};

static const IPCCall attribs = {
{IPC_NTQUERYATTRIBUTESFILE_TAG, {WCHAR_TYPE, UINT32_TYPE, INOUTPTR_TYPE}},
{IpcTag::NTQUERYATTRIBUTESFILE, {WCHAR_TYPE, UINT32_TYPE, INOUTPTR_TYPE}},
reinterpret_cast<CallbackGeneric>(
&FilesystemDispatcher::NtQueryAttributesFile)};

static const IPCCall full_attribs = {
{IPC_NTQUERYFULLATTRIBUTESFILE_TAG,
{IpcTag::NTQUERYFULLATTRIBUTESFILE,
{WCHAR_TYPE, UINT32_TYPE, INOUTPTR_TYPE}},
reinterpret_cast<CallbackGeneric>(
&FilesystemDispatcher::NtQueryFullAttributesFile)};

static const IPCCall set_info = {
{IPC_NTSETINFO_RENAME_TAG,
{IpcTag::NTSETINFO_RENAME,
{VOIDPTR_TYPE, INOUTPTR_TYPE, INOUTPTR_TYPE, UINT32_TYPE, UINT32_TYPE}},
reinterpret_cast<CallbackGeneric>(
&FilesystemDispatcher::NtSetInformationFile)};
Expand All @@ -57,23 +57,23 @@ FilesystemDispatcher::FilesystemDispatcher(PolicyBase* policy_base)
}

bool FilesystemDispatcher::SetupService(InterceptionManager* manager,
int service) {
IpcTag service) {
switch (service) {
case IPC_NTCREATEFILE_TAG:
case IpcTag::NTCREATEFILE:
return INTERCEPT_NT(manager, NtCreateFile, CREATE_FILE_ID, 48);

case IPC_NTOPENFILE_TAG:
case IpcTag::NTOPENFILE:
return INTERCEPT_NT(manager, NtOpenFile, OPEN_FILE_ID, 28);

case IPC_NTQUERYATTRIBUTESFILE_TAG:
case IpcTag::NTQUERYATTRIBUTESFILE:
return INTERCEPT_NT(manager, NtQueryAttributesFile, QUERY_ATTRIB_FILE_ID,
12);

case IPC_NTQUERYFULLATTRIBUTESFILE_TAG:
case IpcTag::NTQUERYFULLATTRIBUTESFILE:
return INTERCEPT_NT(manager, NtQueryFullAttributesFile,
QUERY_FULL_ATTRIB_FILE_ID, 12);

case IPC_NTSETINFO_RENAME_TAG:
case IpcTag::NTSETINFO_RENAME:
return INTERCEPT_NT(manager, NtSetInformationFile, SET_INFO_FILE_ID, 24);

default:
Expand Down Expand Up @@ -109,7 +109,7 @@ bool FilesystemDispatcher::NtCreateFile(IPCInfo* ipc,
// are just middlemen in the operation since is the FileSystemPolicy which
// knows what to do.
EvalResult result =
policy_base_->EvalPolicy(IPC_NTCREATEFILE_TAG, params.GetBase());
policy_base_->EvalPolicy(IpcTag::NTCREATEFILE, params.GetBase());
HANDLE handle;
ULONG_PTR io_information = 0;
NTSTATUS nt_status;
Expand Down Expand Up @@ -154,7 +154,7 @@ bool FilesystemDispatcher::NtOpenFile(IPCInfo* ipc,
// are just middlemen in the operation since is the FileSystemPolicy which
// knows what to do.
EvalResult result =
policy_base_->EvalPolicy(IPC_NTOPENFILE_TAG, params.GetBase());
policy_base_->EvalPolicy(IpcTag::NTOPENFILE, params.GetBase());
HANDLE handle;
ULONG_PTR io_information = 0;
NTSTATUS nt_status;
Expand Down Expand Up @@ -194,7 +194,7 @@ bool FilesystemDispatcher::NtQueryAttributesFile(IPCInfo* ipc,
// are just middlemen in the operation since is the FileSystemPolicy which
// knows what to do.
EvalResult result =
policy_base_->EvalPolicy(IPC_NTQUERYATTRIBUTESFILE_TAG, params.GetBase());
policy_base_->EvalPolicy(IpcTag::NTQUERYATTRIBUTESFILE, params.GetBase());

FILE_BASIC_INFORMATION* information =
reinterpret_cast<FILE_BASIC_INFORMATION*>(info->Buffer());
Expand Down Expand Up @@ -234,7 +234,7 @@ bool FilesystemDispatcher::NtQueryFullAttributesFile(IPCInfo* ipc,
// are just middlemen in the operation since is the FileSystemPolicy which
// knows what to do.
EvalResult result = policy_base_->EvalPolicy(
IPC_NTQUERYFULLATTRIBUTESFILE_TAG, params.GetBase());
IpcTag::NTQUERYFULLATTRIBUTESFILE, params.GetBase());

FILE_NETWORK_OPEN_INFORMATION* information =
reinterpret_cast<FILE_NETWORK_OPEN_INFORMATION*>(info->Buffer());
Expand Down Expand Up @@ -287,7 +287,7 @@ bool FilesystemDispatcher::NtSetInformationFile(IPCInfo* ipc,
// are just middlemen in the operation since is the FileSystemPolicy which
// knows what to do.
EvalResult result =
policy_base_->EvalPolicy(IPC_NTSETINFO_RENAME_TAG, params.GetBase());
policy_base_->EvalPolicy(IpcTag::NTSETINFO_RENAME, params.GetBase());

IO_STATUS_BLOCK* io_status =
reinterpret_cast<IO_STATUS_BLOCK*>(status->Buffer());
Expand Down
3 changes: 2 additions & 1 deletion sandbox/win/src/filesystem_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/strings/string16.h"
#include "sandbox/win/src/crosscall_server.h"
#include "sandbox/win/src/ipc_tags.h"
#include "sandbox/win/src/sandbox_policy_base.h"

namespace sandbox {
Expand All @@ -21,7 +22,7 @@ class FilesystemDispatcher : public Dispatcher {
~FilesystemDispatcher() override {}

// Dispatcher interface.
bool SetupService(InterceptionManager* manager, int service) override;
bool SetupService(InterceptionManager* manager, IpcTag service) override;

private:
// Processes IPC requests coming from calls to NtCreateFile in the target.
Expand Down
Loading

0 comments on commit c8cff7f

Please sign in to comment.