feat: add SYS_GETCAPS syscall to retrieve process capabilities
This commit is contained in:
1 parent
e641500b40
commit
f95bce01d1
8 files changed
+26
-22
No files matched your search
@@ -12,4 +12,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MONTAUK_BUILD_NUMBER 220
|
#define MONTAUK_BUILD_NUMBER 221
|
||||||
@@ -140,6 +140,16 @@ namespace montauk::abi {
|
|||||||
return childPid;
|
return childPid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The calling process's own capability masks.
|
||||||
|
static int Sys_GetCaps(SpawnCapabilities* out) {
|
||||||
|
auto* proc = Sched::GetCurrentProcessPtr();
|
||||||
|
if (proc == nullptr || out == nullptr) return -1;
|
||||||
|
out->permitted = proc->permittedCaps;
|
||||||
|
out->effective = proc->effectiveCaps;
|
||||||
|
out->delegable = proc->delegableCaps;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the absolute path this process was spawned from (argv[0]).
|
// Copy the absolute path this process was spawned from (argv[0]).
|
||||||
static int Sys_GetExecPath(char* buf, uint64_t maxLen) {
|
static int Sys_GetExecPath(char* buf, uint64_t maxLen) {
|
||||||
auto* proc = Sched::GetCurrentProcessPtr();
|
auto* proc = Sched::GetCurrentProcessPtr();
|
||||||
|
|||||||
@@ -510,6 +510,9 @@ namespace montauk::abi {
|
|||||||
// holds no device capability to spend on it.
|
// holds no device capability to spend on it.
|
||||||
if (!UserMemory::Writable<BatteryInfo>(frame->arg1)) return -1;
|
if (!UserMemory::Writable<BatteryInfo>(frame->arg1)) return -1;
|
||||||
return Sys_BatteryInfo((BatteryInfo*)frame->arg1);
|
return Sys_BatteryInfo((BatteryInfo*)frame->arg1);
|
||||||
|
case SYS_GETCAPS:
|
||||||
|
if (!UserMemory::Writable<SpawnCapabilities>(frame->arg1)) return -1;
|
||||||
|
return Sys_GetCaps((SpawnCapabilities*)frame->arg1);
|
||||||
case SYS_THREAD_SPAWN:
|
case SYS_THREAD_SPAWN:
|
||||||
return Sys_ThreadSpawn(frame->arg1, frame->arg2, frame->arg3);
|
return Sys_ThreadSpawn(frame->arg1, frame->arg2, frame->arg3);
|
||||||
case SYS_THREAD_EXIT:
|
case SYS_THREAD_EXIT:
|
||||||
|
|||||||
@@ -346,6 +346,9 @@ namespace montauk::abi {
|
|||||||
/* Battery.hpp -- ACPI battery status */
|
/* Battery.hpp -- ACPI battery status */
|
||||||
static constexpr uint64_t SYS_BATTERYINFO = 188; // (BatteryInfo*) -> 0, -1 no battery device
|
static constexpr uint64_t SYS_BATTERYINFO = 188; // (BatteryInfo*) -> 0, -1 no battery device
|
||||||
|
|
||||||
|
/* Process.hpp -- the caller's own capability masks. */
|
||||||
|
static constexpr uint64_t SYS_GETCAPS = 189; // (SpawnCapabilities*) -> 0, -1 bad pointer
|
||||||
|
|
||||||
/* Kernel-owned process capabilities. User identities may namespace
|
/* Kernel-owned process capabilities. User identities may namespace
|
||||||
per-user resources, but never participate in authorization decisions. */
|
per-user resources, but never participate in authorization decisions. */
|
||||||
static constexpr uint64_t CAP_PROCESS_ADMIN = 1ULL << 0;
|
static constexpr uint64_t CAP_PROCESS_ADMIN = 1ULL << 0;
|
||||||
|
|||||||
@@ -259,6 +259,9 @@ namespace montauk::abi {
|
|||||||
/* Battery.hpp -- ACPI battery status */
|
/* Battery.hpp -- ACPI battery status */
|
||||||
static constexpr uint64_t SYS_BATTERYINFO = 188; // (BatteryInfo*) -> 0, -1 no battery device
|
static constexpr uint64_t SYS_BATTERYINFO = 188; // (BatteryInfo*) -> 0, -1 no battery device
|
||||||
|
|
||||||
|
// The caller's own capability masks.
|
||||||
|
static constexpr uint64_t SYS_GETCAPS = 189; // (SpawnCapabilities*) -> 0, -1 bad pointer
|
||||||
|
|
||||||
/* Kernel-owned process capabilities. User identities may namespace
|
/* Kernel-owned process capabilities. User identities may namespace
|
||||||
per-user resources, but never participate in authorization decisions. */
|
per-user resources, but never participate in authorization decisions. */
|
||||||
static constexpr uint64_t CAP_PROCESS_ADMIN = 1ULL << 0;
|
static constexpr uint64_t CAP_PROCESS_ADMIN = 1ULL << 0;
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ extern "C" {
|
|||||||
#define MTK_SYS_SPAWN_REDIR_CAPS 186
|
#define MTK_SYS_SPAWN_REDIR_CAPS 186
|
||||||
#define MTK_SYS_ALLOC_EAGER 187
|
#define MTK_SYS_ALLOC_EAGER 187
|
||||||
#define MTK_SYS_BATTERYINFO 188
|
#define MTK_SYS_BATTERYINFO 188
|
||||||
|
#define MTK_SYS_GETCAPS 189
|
||||||
/* @SYSCALLS-END */
|
/* @SYSCALLS-END */
|
||||||
|
|
||||||
#define MTK_SOCK_TCP 1
|
#define MTK_SOCK_TCP 1
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace caps {
|
|||||||
|
|
||||||
inline constexpr const char* GRANT_CONFIG = "capabilities";
|
inline constexpr const char* GRANT_CONFIG = "capabilities";
|
||||||
inline constexpr const char* GRANT_PREFIX = "grant.";
|
inline constexpr const char* GRANT_PREFIX = "grant.";
|
||||||
inline constexpr int MAX_SCAN_PROCS = 256;
|
|
||||||
|
|
||||||
struct CapName {
|
struct CapName {
|
||||||
const char* name;
|
const char* name;
|
||||||
@@ -134,26 +133,7 @@ namespace caps {
|
|||||||
// The calling process's own capability masks.
|
// The calling process's own capability masks.
|
||||||
inline bool self(montauk::abi::SpawnCapabilities& out) {
|
inline bool self(montauk::abi::SpawnCapabilities& out) {
|
||||||
out = {0, 0, 0};
|
out = {0, 0, 0};
|
||||||
|
return montauk::getcaps(&out) == 0;
|
||||||
auto* table = (montauk::abi::ProcInfo*)montauk::malloc(
|
|
||||||
sizeof(montauk::abi::ProcInfo) * MAX_SCAN_PROCS);
|
|
||||||
if (table == nullptr) return false;
|
|
||||||
|
|
||||||
int count = montauk::proclist(table, MAX_SCAN_PROCS);
|
|
||||||
int self_pid = montauk::getpid();
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
if (table[i].pid != self_pid) continue;
|
|
||||||
out.permitted = table[i].permittedCaps;
|
|
||||||
out.effective = table[i].effectiveCaps;
|
|
||||||
out.delegable = table[i].delegableCaps;
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
montauk::mfree(table);
|
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t self_delegable() {
|
inline uint64_t self_delegable() {
|
||||||
|
|||||||
@@ -127,6 +127,10 @@ namespace montauk {
|
|||||||
(uint64_t)args, (uint64_t)user,
|
(uint64_t)args, (uint64_t)user,
|
||||||
(uint64_t)&capabilities);
|
(uint64_t)&capabilities);
|
||||||
}
|
}
|
||||||
|
// The calling process's own capability masks. Returns 0 on success.
|
||||||
|
inline int getcaps(montauk::abi::SpawnCapabilities* out) {
|
||||||
|
return (int)syscall1(montauk::abi::SYS_GETCAPS, (uint64_t)out);
|
||||||
|
}
|
||||||
inline int chdir(const char* path) {
|
inline int chdir(const char* path) {
|
||||||
return (int)syscall1(montauk::abi::SYS_CHDIR, (uint64_t)path);
|
return (int)syscall1(montauk::abi::SYS_CHDIR, (uint64_t)path);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user