Commit 88c08169 authored by Tom Sepez's avatar Tom Sepez Committed by Commit Bot

Tidy BrokerProcess::SIGSYS_Handler()

Stop trying to match which syscalls are present based on compiler
flags since we already know this via which symbols are defined in
the system_headers/*_syscalls.h file.

Add a macro for msan poisoning to reduce nesting of ifdefs.
Use early returns to avoid "else considered harmful".

Change-Id: Ic37cd41037bba11ebd25c8326d8e3db115b58254
Reviewed-on: https://chromium-review.googlesource.com/783332Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518411}
parent 414d24f7
......@@ -114,40 +114,44 @@ int BrokerProcess::Open(const char* pathname, int flags) const {
return broker_client_->Open(pathname, flags);
}
#if defined(MEMORY_SANITIZER)
#define BROKER_UNPOISON_STRING(x) __msan_unpoison_string(x)
#else
#define BROKER_UNPOISON_STRING(x)
#endif
// static
intptr_t BrokerProcess::SIGSYS_Handler(const sandbox::arch_seccomp_data& args,
void* aux_broker_process) {
RAW_CHECK(aux_broker_process);
auto* broker_process = static_cast<BrokerProcess*>(aux_broker_process);
switch (args.nr) {
#if !defined(__aarch64__)
#if defined(__NR_access)
case __NR_access:
return broker_process->Access(reinterpret_cast<const char*>(args.args[0]),
static_cast<int>(args.args[1]));
#endif
#if defined(__NR_open)
case __NR_open:
#if defined(MEMORY_SANITIZER)
// http://crbug.com/372840
__msan_unpoison_string(reinterpret_cast<const char*>(args.args[0]));
#endif
BROKER_UNPOISON_STRING(reinterpret_cast<const char*>(args.args[0]));
return broker_process->Open(reinterpret_cast<const char*>(args.args[0]),
static_cast<int>(args.args[1]));
#endif // !defined(__aarch64__)
#endif
#if defined(__NR_faccessat)
case __NR_faccessat:
if (static_cast<int>(args.args[0]) == AT_FDCWD) {
return broker_process->Access(
reinterpret_cast<const char*>(args.args[1]),
static_cast<int>(args.args[2]));
} else {
if (static_cast<int>(args.args[0]) != AT_FDCWD)
return -EPERM;
}
case __NR_openat:
// Allow using openat() as open().
if (static_cast<int>(args.args[0]) == AT_FDCWD) {
return broker_process->Open(reinterpret_cast<const char*>(args.args[1]),
return broker_process->Access(reinterpret_cast<const char*>(args.args[1]),
static_cast<int>(args.args[2]));
} else {
#endif
#if defined(__NR_openat)
case __NR_openat:
if (static_cast<int>(args.args[0]) != AT_FDCWD)
return -EPERM;
}
return broker_process->Open(reinterpret_cast<const char*>(args.args[1]),
static_cast<int>(args.args[2]));
#endif
default:
RAW_CHECK(false);
return -ENOSYS;
......
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