#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "sandbox/linux/syscall_broker/broker_host.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stddef.h>
#include <sys/inotify.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <array>
#include <string>
#include <tuple>
#include <utility>
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "sandbox/linux/services/syscall_wrappers.h"
#include "sandbox/linux/syscall_broker/broker_command.h"
#include "sandbox/linux/syscall_broker/broker_permission_list.h"
#include "sandbox/linux/syscall_broker/broker_simple_message.h"
#include "sandbox/linux/system_headers/linux_stat.h"
#include "sandbox/linux/system_headers/linux_syscalls.h"
namespace sandbox {
namespace syscall_broker {
namespace {
const char kProcSelf[] = …;
const size_t kProcSelfNumChars = …;
int sys_open(const char* pathname, int flags) { … }
}
std::optional<std::string> BrokerHost::RewritePathname(const char* pathname) { … }
std::optional<std::pair<const char*, int>> BrokerHost::GetPathAndFlags(
BrokerSimpleMessage* message) { … }
void BrokerHost::AccessFileForIPC(const char* requested_filename,
int mode,
BrokerSimpleMessage* reply) { … }
void BrokerHost::MkdirFileForIPC(const char* requested_filename,
int mode,
BrokerSimpleMessage* reply) { … }
void BrokerHost::OpenFileForIPC(const char* requested_filename,
int flags,
BrokerSimpleMessage* reply,
base::ScopedFD* opened_file) { … }
void BrokerHost::RenameFileForIPC(const char* old_filename,
const char* new_filename,
BrokerSimpleMessage* reply) { … }
void BrokerHost::ReadlinkFileForIPC(const char* requested_filename,
BrokerSimpleMessage* reply) { … }
void BrokerHost::RmdirFileForIPC(const char* requested_filename,
BrokerSimpleMessage* reply) { … }
void BrokerHost::StatFileForIPC(BrokerCommand command_type,
const char* requested_filename,
bool follow_links,
BrokerSimpleMessage* reply) { … }
void BrokerHost::UnlinkFileForIPC(const char* requested_filename,
BrokerSimpleMessage* reply) { … }
void BrokerHost::InotifyAddWatchForIPC(base::ScopedFD inotify_fd,
const char* requested_filename,
uint32_t mask,
BrokerSimpleMessage* message) { … }
bool BrokerHost::HandleRemoteCommand(BrokerSimpleMessage* message,
base::span<base::ScopedFD> recv_fds,
BrokerSimpleMessage* reply,
base::ScopedFD* opened_file) { … }
BrokerHost::BrokerHost(const BrokerSandboxConfig& policy,
BrokerChannel::EndPoint ipc_channel,
pid_t sandboxed_process_pid)
: … { … }
BrokerHost::~BrokerHost() = default;
void BrokerHost::LoopAndHandleRequests() { … }
}
}