mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Fix bypass for enabling ptrace
/bpf
PiperOrigin-RevId: 555847265 Change-Id: I671c0650caeefaac590d3d0030ff90e18fda6bbd
This commit is contained in:
parent
3079d2b4e0
commit
01e14e0bb7
|
@ -1106,6 +1106,11 @@ PolicyBuilder& PolicyBuilder::AddPolicyOnSyscalls(
|
||||||
constexpr size_t kMaxShortJump = 255;
|
constexpr size_t kMaxShortJump = 255;
|
||||||
bool last = true;
|
bool last = true;
|
||||||
for (auto it = std::rbegin(nums); it != std::rend(nums); ++it) {
|
for (auto it = std::rbegin(nums); it != std::rend(nums); ++it) {
|
||||||
|
if (*it == __NR_bpf || *it == __NR_ptrace) {
|
||||||
|
SetError(absl::InvalidArgumentError(
|
||||||
|
"cannot add policy for bpf/ptrace syscall"));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
// If syscall is not matched try with the next one.
|
// If syscall is not matched try with the next one.
|
||||||
uint8_t jf = 0;
|
uint8_t jf = 0;
|
||||||
// If last syscall on the list does not match skip the policy by jumping
|
// If last syscall on the list does not match skip the policy by jumping
|
||||||
|
@ -1479,8 +1484,10 @@ PolicyBuilder& PolicyBuilder::AddNetworkProxyHandlerPolicy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
PolicyBuilder& PolicyBuilder::TrapPtrace() {
|
PolicyBuilder& PolicyBuilder::TrapPtrace() {
|
||||||
AddPolicyOnSyscall(__NR_ptrace, {TRAP(0)});
|
if (handled_syscalls_.insert(__NR_ptrace).second) {
|
||||||
user_policy_handles_ptrace_ = true;
|
user_policy_.insert(user_policy_.end(), {SYSCALL(__NR_ptrace, TRAP(0))});
|
||||||
|
user_policy_handles_ptrace_ = true;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -48,12 +49,12 @@ class PolicyBuilderPeer {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using ::sapi::IsOk;
|
||||||
|
using ::sapi::StatusIs;
|
||||||
using ::testing::Eq;
|
using ::testing::Eq;
|
||||||
using ::testing::Lt;
|
using ::testing::Lt;
|
||||||
using ::testing::StartsWith;
|
using ::testing::StartsWith;
|
||||||
using ::testing::StrEq;
|
using ::testing::StrEq;
|
||||||
using ::sapi::IsOk;
|
|
||||||
using ::sapi::StatusIs;
|
|
||||||
|
|
||||||
TEST(PolicyBuilderTest, Testpolicy_size) {
|
TEST(PolicyBuilderTest, Testpolicy_size) {
|
||||||
ssize_t last_size = 0;
|
ssize_t last_size = 0;
|
||||||
|
@ -152,5 +153,12 @@ TEST(PolicyBuilderTest, TestIsCopyable) {
|
||||||
EXPECT_THAT(builder.TryBuild(), IsOk());
|
EXPECT_THAT(builder.TryBuild(), IsOk());
|
||||||
EXPECT_THAT(copy.TryBuild(), IsOk());
|
EXPECT_THAT(copy.TryBuild(), IsOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PolicyBuilderTest, CanBypassPtrace) {
|
||||||
|
PolicyBuilder builder;
|
||||||
|
builder.AddPolicyOnSyscall(__NR_ptrace, {ALLOW})
|
||||||
|
.BlockSyscallWithErrno(__NR_ptrace, ENOENT);
|
||||||
|
EXPECT_THAT(builder.TryBuild(), Not(IsOk()));
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace sandbox2
|
} // namespace sandbox2
|
||||||
|
|
Loading…
Reference in New Issue
Block a user