mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
Kernel: Add support for jails
Our implementation for Jails resembles much of how FreeBSD jails are working - it's essentially only a matter of using a RefPtr in the Process class to a Jail object. Then, when we iterate over all processes in various cases, we could ensure if either the current process is in jail and therefore should be restricted what is visible in terms of PID isolation, and also to be able to expose metadata about Jails in /sys/kernel/jails node (which does not reveal anything to a process which is in jail). A lifetime model for the Jail object is currently plain simple - there's simpy no way to manually delete a Jail object once it was created. Such feature should be carefully designed to allow safe destruction of a Jail without the possibility of releasing a process which is in Jail from the actual jail. Each process which is attached into a Jail cannot leave it until the end of a Process (i.e. when finalizing a Process). All jails are kept being referenced in the JailManagement. When a last attached process is finalized, the Jail is automatically destroyed.
This commit is contained in:
parent
d69a0380e1
commit
5e062414c1
35 changed files with 609 additions and 160 deletions
|
@ -206,14 +206,12 @@ ErrorOr<void> ProcFSRootDirectory::traverse_as_directory(FileSystemID fsid, Func
|
|||
TRY(callback({ component.name(), identifier, 0 }));
|
||||
}
|
||||
|
||||
return Process::all_instances().with([&](auto& list) -> ErrorOr<void> {
|
||||
for (auto& process : list) {
|
||||
VERIFY(!(process.pid() < 0));
|
||||
u64 process_id = (u64)process.pid().value();
|
||||
InodeIdentifier identifier = { fsid, static_cast<InodeIndex>(process_id << 36) };
|
||||
auto process_id_string = TRY(KString::formatted("{:d}", process_id));
|
||||
TRY(callback({ process_id_string->view(), identifier, 0 }));
|
||||
}
|
||||
return Process::for_each_in_same_jail([&](Process& process) -> ErrorOr<void> {
|
||||
VERIFY(!(process.pid() < 0));
|
||||
u64 process_id = (u64)process.pid().value();
|
||||
InodeIdentifier identifier = { fsid, static_cast<InodeIndex>(process_id << 36) };
|
||||
auto process_id_string = TRY(KString::formatted("{:d}", process_id));
|
||||
TRY(callback({ process_id_string->view(), identifier, 0 }));
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
@ -234,7 +232,7 @@ ErrorOr<NonnullLockRefPtr<ProcFSExposedComponent>> ProcFSRootDirectory::lookup(S
|
|||
return ESRCH;
|
||||
auto actual_pid = pid.value();
|
||||
|
||||
if (auto maybe_process = Process::from_pid(actual_pid))
|
||||
if (auto maybe_process = Process::from_pid_in_same_jail(actual_pid))
|
||||
return maybe_process->procfs_traits();
|
||||
|
||||
return ENOENT;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue