mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
Kernel: Add a basic implementation of unveil()
This syscall is a complement to pledge() and adds the same sort of incremental relinquishing of capabilities for filesystem access. The first call to unveil() will "drop a veil" on the process, and from now on, only unveiled parts of the filesystem are visible to it. Each call to unveil() specifies a path to either a directory or a file along with permissions for that path. The permissions are a combination of the following: - r: Read access (like the "rpath" promise) - w: Write access (like the "wpath" promise) - x: Execute access - c: Create/remove access (like the "cpath" promise) Attempts to open a path that has not been unveiled with fail with ENOENT. If the unveiled path lacks sufficient permissions, it will fail with EACCES. Like pledge(), subsequent calls to unveil() with the same path can only remove permissions, not add them. Once you call unveil(nullptr, nullptr), the veil is locked, and it's no longer possible to unveil any more paths for the process, ever. This concept comes from OpenBSD, and their implementation does various things differently, I'm sure. This is just a first implementation for SerenityOS, and we'll keep improving on it as we go. :^)
This commit is contained in:
parent
e711936c78
commit
0569123ad7
7 changed files with 188 additions and 3 deletions
|
@ -82,6 +82,24 @@ enum class Pledge : u32 {
|
|||
#undef __ENUMERATE_PLEDGE_PROMISE
|
||||
};
|
||||
|
||||
enum class UnveilState {
|
||||
None,
|
||||
VeilDropped,
|
||||
VeilLocked,
|
||||
};
|
||||
|
||||
struct UnveiledPath {
|
||||
enum Access {
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
Execute = 4,
|
||||
CreateOrRemove = 8,
|
||||
};
|
||||
|
||||
String path;
|
||||
unsigned permissions { 0 };
|
||||
};
|
||||
|
||||
class Process : public InlineLinkedListNode<Process>
|
||||
, public Weakable<Process> {
|
||||
friend class InlineLinkedListNode<Process>;
|
||||
|
@ -282,6 +300,7 @@ public:
|
|||
int sys$set_process_boost(pid_t, int amount);
|
||||
int sys$chroot(const char* path, size_t path_length, int mount_flags);
|
||||
int sys$pledge(const Syscall::SC_pledge_params*);
|
||||
int sys$unveil(const Syscall::SC_unveil_params*);
|
||||
|
||||
static void initialize();
|
||||
|
||||
|
@ -380,6 +399,9 @@ public:
|
|||
bool has_promises() const { return m_promises; }
|
||||
bool has_promised(Pledge pledge) const { return m_promises & (1u << (u32)pledge); }
|
||||
|
||||
UnveilState unveil_state() const { return m_unveil_state; }
|
||||
const Vector<UnveiledPath>& unveiled_paths() const { return m_unveiled_paths; }
|
||||
|
||||
private:
|
||||
friend class MemoryManager;
|
||||
friend class Scheduler;
|
||||
|
@ -481,6 +503,9 @@ private:
|
|||
u32 m_promises { 0 };
|
||||
u32 m_execpromises { 0 };
|
||||
|
||||
UnveilState m_unveil_state { UnveilState::None };
|
||||
Vector<UnveiledPath> m_unveiled_paths;
|
||||
|
||||
WaitQueue& futex_queue(i32*);
|
||||
HashMap<u32, OwnPtr<WaitQueue>> m_futex_queues;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue