Skip to content

Commit ea2e519

Browse files
Sandboxed API Teamcopybara-github
Sandboxed API Team
authored andcommitted
Internal change
PiperOrigin-RevId: 752483547 Change-Id: I87b566f42825a885a3a980c6bacae3ec6966cba1
1 parent 380e04e commit ea2e519

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

sandboxed_api/sandbox2/policy.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/seccomp.h>
2424
#include <sched.h>
2525
#include <sys/mman.h>
26+
#include <sys/ptrace.h>
2627
#include <syscall.h>
2728

2829
#include <cerrno>
@@ -188,6 +189,21 @@ std::vector<sock_filter> Policy::GetDefaultPolicy(
188189
policy.insert(policy.end(), {SYSCALL(internal::kMagicSyscallNo,
189190
ERRNO(internal::kMagicSyscallErr))});
190191

192+
// If the user has explicitly allowed unsafe ptrace operations needed for
193+
// collecting core dumps, then we allow these.
194+
if (allow_unsafe_coredump_ptrace_) {
195+
policy.insert(policy.end(), {
196+
JNE32(__NR_ptrace, JUMP(&l, past_ptrace_l)),
197+
ARG_32(0),
198+
JEQ32(PTRACE_DETACH, ALLOW),
199+
JEQ32(PTRACE_PEEKDATA, ALLOW),
200+
JEQ32(PTRACE_ATTACH, ALLOW),
201+
JEQ32(PTRACE_GETREGSET, ALLOW),
202+
JEQ32(PTRACE_PEEKUSER, ALLOW),
203+
LOAD_SYSCALL_NR,
204+
LABEL(&l, past_ptrace_l),
205+
});
206+
}
191207
// Forbid ptrace because it's unsafe or too risky. The user policy can only
192208
// block (i.e. return an error instead of killing the process) but not allow
193209
// ptrace. This uses LOAD_SYSCALL_NR from above.

sandboxed_api/sandbox2/policy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class Policy final {
9999

100100
bool allow_map_exec_ = false;
101101
bool allow_safe_bpf_ = false;
102+
bool allow_unsafe_coredump_ptrace_ = false;
102103
bool allow_speculation_ = false;
103104

104105
// The policy set by the user.

sandboxed_api/sandbox2/policybuilder.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,15 @@ absl::StatusOr<std::unique_ptr<Policy>> PolicyBuilder::TryBuild() {
14721472
allow_mount_propagation_);
14731473
}
14741474

1475+
if (user_policy_handles_ptrace_ && allow_unsafe_coredump_ptrace_) {
1476+
return absl::FailedPreconditionError(
1477+
"Cannot set both user_policy_handles_ptrace_ and "
1478+
"allow_unsafe_coredump_ptrace_.");
1479+
}
1480+
14751481
policy->allow_map_exec_ = allow_map_exec_;
14761482
policy->allow_safe_bpf_ = allow_safe_bpf_;
1483+
policy->allow_unsafe_coredump_ptrace_ = allow_unsafe_coredump_ptrace_;
14771484
policy->allow_speculation_ = allow_speculation_;
14781485
policy->collect_stacktrace_on_signal_ = collect_stacktrace_on_signal_;
14791486
policy->collect_stacktrace_on_violation_ = collect_stacktrace_on_violation_;

sandboxed_api/sandbox2/policybuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class AllowAllSyscalls;
5050
class NamespacesToken;
5151
class LoadUserBpfCodeFromFile;
5252
class MapExec;
53+
class UnsafeCoreDumpPtrace;
5354
class SeccompSpeculation;
5455
class TraceAllSyscalls;
5556
class UnrestrictedNetworking;
@@ -1023,6 +1024,8 @@ class PolicyBuilder final {
10231024
NetNsMode netns_mode_ = NETNS_MODE_UNSPECIFIED;
10241025
bool allow_map_exec_ = true; // Temporary default while we migrate users.
10251026
bool allow_safe_bpf_ = false;
1027+
// Temporary while coredump collection is migrated away from ptrace.
1028+
bool allow_unsafe_coredump_ptrace_ = false;
10261029
bool allow_speculation_ = false;
10271030
bool allow_mount_propagation_ = false;
10281031
std::string hostname_ = std::string(kDefaultHostname);

0 commit comments

Comments
 (0)