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
@@ -15,7 +15,6 @@ namespace caps {
|
||||
|
||||
inline constexpr const char* GRANT_CONFIG = "capabilities";
|
||||
inline constexpr const char* GRANT_PREFIX = "grant.";
|
||||
inline constexpr int MAX_SCAN_PROCS = 256;
|
||||
|
||||
struct CapName {
|
||||
const char* name;
|
||||
@@ -134,26 +133,7 @@ namespace caps {
|
||||
// The calling process's own capability masks.
|
||||
inline bool self(montauk::abi::SpawnCapabilities& out) {
|
||||
out = {0, 0, 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;
|
||||
return montauk::getcaps(&out) == 0;
|
||||
}
|
||||
|
||||
inline uint64_t self_delegable() {
|
||||
|
||||
@@ -127,6 +127,10 @@ namespace montauk {
|
||||
(uint64_t)args, (uint64_t)user,
|
||||
(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) {
|
||||
return (int)syscall1(montauk::abi::SYS_CHDIR, (uint64_t)path);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user