mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:28:11 +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
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -16,18 +17,26 @@ ErrorOr<void> SysFSSystemBoolean::try_generate(KBufferBuilder& builder)
|
|||
|
||||
ErrorOr<size_t> SysFSSystemBoolean::write_bytes(off_t, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription*)
|
||||
{
|
||||
if (count != 1)
|
||||
return EINVAL;
|
||||
MutexLocker locker(m_refresh_lock);
|
||||
// Note: We do all of this code before taking the spinlock because then we disable
|
||||
// interrupts so page faults will not work.
|
||||
char value = 0;
|
||||
TRY(buffer.read(&value, 1));
|
||||
if (value == '0')
|
||||
set_value(false);
|
||||
else if (value == '1')
|
||||
set_value(true);
|
||||
else
|
||||
return EINVAL;
|
||||
return 1;
|
||||
|
||||
return Process::current().jail().with([&](auto& my_jail) -> ErrorOr<size_t> {
|
||||
// Note: If we are in a jail, don't let the current process to change the variable.
|
||||
if (my_jail)
|
||||
return Error::from_errno(EPERM);
|
||||
if (count != 1)
|
||||
return Error::from_errno(EINVAL);
|
||||
if (value == '0')
|
||||
set_value(false);
|
||||
else if (value == '1')
|
||||
set_value(true);
|
||||
else
|
||||
return Error::from_errno(EINVAL);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<void> SysFSSystemBoolean::truncate(u64 size)
|
||||
|
|
|
@ -22,12 +22,12 @@ UNMAP_AFTER_INIT NonnullLockRefPtr<SysFSCapsLockRemap> SysFSCapsLockRemap::must_
|
|||
|
||||
bool SysFSCapsLockRemap::value() const
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
SpinlockLocker locker(m_lock);
|
||||
return g_caps_lock_remapped_to_ctrl.load();
|
||||
}
|
||||
void SysFSCapsLockRemap::set_value(bool new_value)
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
SpinlockLocker locker(m_lock);
|
||||
g_caps_lock_remapped_to_ctrl.exchange(new_value);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Types.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Locking/Spinlock.h>
|
||||
#include <Kernel/UserOrKernelBuffer.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -24,7 +25,7 @@ private:
|
|||
|
||||
explicit SysFSCapsLockRemap(SysFSDirectory const&);
|
||||
|
||||
mutable Mutex m_lock;
|
||||
mutable Spinlock m_lock { LockRank::None };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ UNMAP_AFTER_INIT NonnullLockRefPtr<SysFSDumpKmallocStacks> SysFSDumpKmallocStack
|
|||
|
||||
bool SysFSDumpKmallocStacks::value() const
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
SpinlockLocker locker(m_lock);
|
||||
return g_dump_kmalloc_stacks;
|
||||
}
|
||||
|
||||
void SysFSDumpKmallocStacks::set_value(bool new_value)
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
SpinlockLocker locker(m_lock);
|
||||
g_dump_kmalloc_stacks = new_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Types.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Locking/Spinlock.h>
|
||||
#include <Kernel/UserOrKernelBuffer.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -24,7 +25,7 @@ private:
|
|||
|
||||
explicit SysFSDumpKmallocStacks(SysFSDirectory const&);
|
||||
|
||||
mutable Mutex m_lock;
|
||||
mutable Spinlock m_lock { LockRank::None };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue