Skip to content

Commit b9b7388

Browse files
cblichmanncopybara-github
authored andcommitted
#Cleanup method/member descriptions, build files
Drive-by: - use `ABSL_DIE_IF_NULL` in `Sandbox2` ctor PiperOrigin-RevId: 735721896 Change-Id: I73baf48b72e151829861b1d2738238ecfb2c92c9
1 parent 0ae63ee commit b9b7388

File tree

6 files changed

+53
-64
lines changed

6 files changed

+53
-64
lines changed

sandboxed_api/sandbox2/BUILD

+2-3
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ cc_library(
327327
# sandbox2::Client objects
328328
cc_library(
329329
name = "sandbox2",
330-
srcs = [
331-
"sandbox2.cc",
332-
],
330+
srcs = ["sandbox2.cc"],
333331
hdrs = [
334332
"client.h",
335333
"executor.h",
@@ -372,6 +370,7 @@ cc_library(
372370
"@com_google_absl//absl/container:flat_hash_set",
373371
"@com_google_absl//absl/log",
374372
"@com_google_absl//absl/log:check",
373+
"@com_google_absl//absl/log:die_if_null",
375374
"@com_google_absl//absl/status",
376375
"@com_google_absl//absl/status:statusor",
377376
"@com_google_absl//absl/strings",

sandboxed_api/sandbox2/CMakeLists.txt

+31-28
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ add_library(sandbox2_sandbox2 ${SAPI_LIB_TYPE}
314314
add_library(sandbox2::sandbox2 ALIAS sandbox2_sandbox2)
315315
target_link_libraries(sandbox2_sandbox2
316316
PRIVATE absl::core_headers
317+
absl::check
317318
absl::flat_hash_set
319+
absl::log
318320
absl::memory
319321
absl::optional
320322
absl::str_format
@@ -323,34 +325,35 @@ target_link_libraries(sandbox2_sandbox2
323325
sandbox2::monitor_ptrace
324326
sandbox2::monitor_unotify
325327
sapi::base
326-
PUBLIC absl::flat_hash_map
327-
absl::status
328-
absl::statusor
329-
absl::time
330-
sapi::config
331-
sapi::fileops
332-
sapi::temp_file
333-
sandbox2::client
334-
sandbox2::comms
335-
sandbox2::executor
336-
sandbox2::fork_client
337-
sandbox2::global_forkserver
338-
sandbox2::ipc
339-
sandbox2::limits
340-
sandbox2::logsink
341-
sandbox2::monitor_base
342-
sandbox2::mounts
343-
sandbox2::mount_tree_proto
344-
sandbox2::namespace
345-
sandbox2::network_proxy_client
346-
sandbox2::network_proxy_server
347-
sandbox2::notify
348-
sandbox2::policy
349-
sandbox2::policybuilder
350-
sandbox2::regs
351-
sandbox2::result
352-
sandbox2::syscall
353-
sandbox2::util
328+
PUBLIC absl::die_if_null
329+
absl::flat_hash_map
330+
absl::status
331+
absl::statusor
332+
absl::time
333+
sapi::config
334+
sapi::fileops
335+
sapi::temp_file
336+
sandbox2::client
337+
sandbox2::comms
338+
sandbox2::executor
339+
sandbox2::fork_client
340+
sandbox2::global_forkserver
341+
sandbox2::ipc
342+
sandbox2::limits
343+
sandbox2::logsink
344+
sandbox2::monitor_base
345+
sandbox2::mounts
346+
sandbox2::mount_tree_proto
347+
sandbox2::namespace
348+
sandbox2::network_proxy_client
349+
sandbox2::network_proxy_server
350+
sandbox2::notify
351+
sandbox2::policy
352+
sandbox2::policybuilder
353+
sandbox2::regs
354+
sandbox2::result
355+
sandbox2::syscall
356+
sandbox2::util
354357
)
355358

356359

sandboxed_api/sandbox2/monitor_base.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ void LogContainer(const std::vector<std::string>& container) {
128128

129129
MonitorBase::MonitorBase(Executor* executor, Policy* policy, Notify* notify)
130130
: executor_(executor),
131-
notify_(notify),
132131
policy_(policy),
132+
notify_(notify),
133133
// NOLINTNEXTLINE clang-diagnostic-deprecated-declarations
134134
comms_(executor_->ipc()->comms()),
135135
ipc_(executor_->ipc()),

sandboxed_api/sandbox2/monitor_base.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,22 @@ class MonitorBase {
8080
virtual void SetWallTimeLimit(absl::Duration limit) = 0;
8181

8282
protected:
83+
// Sends the policy to the client.
84+
// Can be overridden by subclasses to save/modify policy before sending.
85+
// Returns success/failure status.
86+
virtual absl::Status SendPolicy(const std::vector<sock_filter>& policy);
87+
8388
bool wait_for_execveat() const { return wait_for_execveat_; }
8489
void set_wait_for_execveat(bool wait_for_execve) {
8590
wait_for_execveat_ = wait_for_execve;
8691
}
8792

8893
void OnDone();
94+
8995
// Sets basic info status and reason code in the result object.
9096
void SetExitStatusCode(Result::StatusEnum final_status,
9197
uintptr_t reason_code);
98+
9299
// Logs a SANDBOX VIOLATION message based on the registers and additional
93100
// explanation for the reason of the violation.
94101
void LogSyscallViolation(const Syscall& syscall) const;
@@ -108,8 +115,9 @@ class MonitorBase {
108115

109116
// Internal objects, owned by the Sandbox2 object.
110117
Executor* executor_;
111-
Notify* notify_;
112118
Policy* policy_;
119+
Notify* notify_;
120+
113121
// The sandboxee process.
114122
SandboxeeProcess process_;
115123
Result result_;
@@ -124,12 +132,6 @@ class MonitorBase {
124132
// Monitor type
125133
MonitorType type_ = FORKSERVER_MONITOR_PTRACE;
126134

127-
protected:
128-
// Sends Policy to the Client.
129-
// Can be overridden by subclasses to save/modify policy before sending.
130-
// Returns success/failure status.
131-
virtual absl::Status SendPolicy(const std::vector<sock_filter>& policy);
132-
133135
private:
134136
// Instantiates and sends Policy to the Client.
135137
// Returns success/failure status.

sandboxed_api/sandbox2/monitor_unotify.cc

-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ namespace {
5858

5959
using ::sapi::file_util::fileops::FDCloser;
6060

61-
int seccomp(unsigned int operation, unsigned int flags, void* args) {
62-
return syscall(SYS_seccomp, operation, flags, args);
63-
}
64-
6561
absl::Status WaitForFdReadable(int fd, absl::Time deadline) {
6662
pollfd pfds[] = {
6763
{.fd = fd, .events = POLLIN},

sandboxed_api/sandbox2/sandbox2.h

+10-21
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
#ifndef SANDBOXED_API_SANDBOX2_SANDBOX2_H_
1919
#define SANDBOXED_API_SANDBOX2_SANDBOX2_H_
2020

21-
#include <ctime>
2221
#include <memory>
2322
#include <utility>
2423

2524
#include "absl/base/attributes.h"
26-
#include "absl/base/macros.h"
27-
#include "absl/log/check.h"
25+
#include "absl/log/die_if_null.h"
2826
#include "absl/status/status.h"
2927
#include "absl/status/statusor.h"
3028
#include "absl/time/time.h"
@@ -45,12 +43,9 @@ class Sandbox2 final {
4543

4644
Sandbox2(std::unique_ptr<Executor> executor, std::unique_ptr<Policy> policy,
4745
std::unique_ptr<Notify> notify)
48-
: executor_(std::move(executor)),
49-
policy_(std::move(policy)),
50-
notify_(std::move(notify)) {
51-
CHECK(executor_ != nullptr);
52-
CHECK(policy_ != nullptr);
53-
}
46+
: executor_(std::move(ABSL_DIE_IF_NULL(executor))),
47+
policy_(std::move(ABSL_DIE_IF_NULL(policy))),
48+
notify_(std::move(notify)) {}
5449

5550
Sandbox2(const Sandbox2&) = delete;
5651
Sandbox2& operator=(const Sandbox2&) = delete;
@@ -66,6 +61,7 @@ class Sandbox2 final {
6661
// Even if set-up fails AwaitResult can still used to get a more specific
6762
// failure reason.
6863
bool RunAsync();
64+
6965
// Waits for sandbox execution to finish and returns the execution result.
7066
ABSL_MUST_USE_RESULT Result AwaitResult();
7167

@@ -75,8 +71,8 @@ class Sandbox2 final {
7571
absl::StatusOr<Result> AwaitResultWithTimeout(absl::Duration timeout);
7672

7773
// Requests termination of the sandboxee.
78-
// Sandbox should still waited with AwaitResult(), as it may finish for other
79-
// reason before the request is handled.
74+
// The sandbox should still waited on using AwaitResult(), as it may finish
75+
// for other reasons before the request is handled.
8076
void Kill();
8177

8278
// Dumps the main sandboxed process's stack trace to log.
@@ -85,7 +81,7 @@ class Sandbox2 final {
8581
// Returns whether sandboxing task has ended.
8682
bool IsTerminated() const;
8783

88-
// Sets a wall time limit on a running sandboxee, absl::ZeroDuration() to
84+
// Sets a wall time limit on a running sandboxee. Use absl::ZeroDuration() to
8985
// disarm. This can be useful in a persistent sandbox scenario, to impose a
9086
// deadline for responses after each request and reset the deadline in
9187
// between. Sandboxed API can be used to implement persistent sandboxes.
@@ -94,7 +90,7 @@ class Sandbox2 final {
9490
// Returns the process id inside the executor.
9591
pid_t pid() const { return monitor_ != nullptr ? monitor_->pid() : -1; }
9692

97-
// Gets the comms inside the executor.
93+
// Returns the comms object from the executor.
9894
Comms* comms() {
9995
return executor_ != nullptr ? executor_->ipc()->comms() : nullptr;
10096
}
@@ -107,16 +103,9 @@ class Sandbox2 final {
107103

108104
std::unique_ptr<MonitorBase> CreateMonitor();
109105

110-
// Executor set by user - owned by Sandbox2.
111106
std::unique_ptr<Executor> executor_;
112-
113-
// Seccomp policy set by the user - owned by Sandbox2.
114-
std::unique_ptr<Policy> policy_;
115-
116-
// Notify object - owned by Sandbox2.
107+
std::unique_ptr<Policy> policy_; // Seccomp user policy
117108
std::unique_ptr<Notify> notify_;
118-
119-
// Monitor object - owned by Sandbox2.
120109
std::unique_ptr<MonitorBase> monitor_;
121110

122111
bool use_unotify_monitor_ = false;

0 commit comments

Comments
 (0)