2020-01-17 21:05:03 +08:00
|
|
|
// Copyright 2019 Google LLC
|
2019-03-19 00:21:48 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
2022-01-28 17:38:27 +08:00
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2019-03-19 00:21:48 +08:00
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "sandboxed_api/sandbox2/syscall.h"
|
|
|
|
|
|
|
|
#include <linux/audit.h>
|
2020-09-10 20:47:32 +08:00
|
|
|
|
2023-08-24 21:23:03 +08:00
|
|
|
#include <cstdint>
|
2019-03-19 00:21:48 +08:00
|
|
|
#include <string>
|
2023-08-24 21:23:03 +08:00
|
|
|
#include <vector>
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
#include "absl/strings/str_format.h"
|
|
|
|
#include "absl/strings/str_join.h"
|
2023-08-24 21:23:03 +08:00
|
|
|
#include "absl/strings/string_view.h"
|
2021-01-14 01:25:25 +08:00
|
|
|
#include "sandboxed_api/config.h"
|
2019-03-19 00:21:48 +08:00
|
|
|
#include "sandboxed_api/sandbox2/syscall_defs.h"
|
|
|
|
|
|
|
|
#ifndef AUDIT_ARCH_PPC64LE
|
|
|
|
#define AUDIT_ARCH_PPC64LE (EM_PPC64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace sandbox2 {
|
|
|
|
|
2021-01-14 01:25:25 +08:00
|
|
|
std::string Syscall::GetArchDescription(sapi::cpu::Architecture arch) {
|
2019-03-19 00:21:48 +08:00
|
|
|
switch (arch) {
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kX8664:
|
2019-03-19 00:21:48 +08:00
|
|
|
return "[X86-64]";
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kX86:
|
2019-03-19 00:21:48 +08:00
|
|
|
return "[X86-32]";
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kPPC64LE:
|
2019-03-19 00:21:48 +08:00
|
|
|
return "[PPC-64]";
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kArm64:
|
2020-09-11 21:33:57 +08:00
|
|
|
return "[Arm-64]";
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kArm:
|
2020-12-17 01:17:53 +08:00
|
|
|
return "[Arm-32]";
|
2019-03-19 00:21:48 +08:00
|
|
|
default:
|
|
|
|
return absl::StrFormat("[UNKNOWN_ARCH:%d]", arch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Syscall::GetHostAuditArch() {
|
2021-01-14 01:25:25 +08:00
|
|
|
switch (sapi::host_cpu::Architecture()) {
|
|
|
|
case sapi::cpu::kX8664:
|
2020-09-10 20:47:32 +08:00
|
|
|
return AUDIT_ARCH_X86_64;
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kPPC64LE:
|
2020-09-10 20:47:32 +08:00
|
|
|
return AUDIT_ARCH_PPC64LE;
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kArm64:
|
2020-09-11 21:33:57 +08:00
|
|
|
return AUDIT_ARCH_AARCH64;
|
2021-01-14 01:25:25 +08:00
|
|
|
case sapi::cpu::kArm:
|
2020-12-17 01:17:53 +08:00
|
|
|
return AUDIT_ARCH_ARM;
|
2020-09-10 20:47:32 +08:00
|
|
|
default:
|
|
|
|
// The static_assert() in config.h should prevent us from ever getting
|
|
|
|
// here.
|
|
|
|
return 0; // Not reached
|
|
|
|
}
|
2019-03-19 00:21:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Syscall::GetName() const {
|
2020-09-10 20:47:32 +08:00
|
|
|
if (absl::string_view name = SyscallTable::get(arch_).GetName(nr_);
|
|
|
|
!name.empty()) {
|
|
|
|
return std::string(name);
|
2019-03-19 00:21:48 +08:00
|
|
|
}
|
2020-09-10 20:47:32 +08:00
|
|
|
return absl::StrFormat("UNKNOWN[%d/0x%x]", nr_, nr_);
|
2019-03-19 00:21:48 +08:00
|
|
|
}
|
|
|
|
|
2024-03-06 03:06:15 +08:00
|
|
|
std::vector<syscalls::ArgData> Syscall::GetArgumentsData() const {
|
|
|
|
return SyscallTable::get(arch_).GetArgumentsData(nr_, args_.data(), pid_);
|
|
|
|
}
|
|
|
|
|
2019-03-19 00:21:48 +08:00
|
|
|
std::vector<std::string> Syscall::GetArgumentsDescription() const {
|
2020-01-07 21:26:10 +08:00
|
|
|
return SyscallTable::get(arch_).GetArgumentsDescription(nr_, args_.data(),
|
|
|
|
pid_);
|
2019-03-19 00:21:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Syscall::GetDescription() const {
|
2020-07-14 16:41:41 +08:00
|
|
|
const std::string arch = GetArchDescription(arch_);
|
2019-03-19 00:21:48 +08:00
|
|
|
const std::string args = absl::StrJoin(GetArgumentsDescription(), ", ");
|
|
|
|
return absl::StrFormat("%s %s [%d](%s) IP: %#x, STACK: %#x", arch, GetName(),
|
|
|
|
nr_, args, ip_, sp_);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sandbox2
|