Kernel: Support pledge() with empty promises

This tells the kernel that the process wants to use pledge, but without
pledging anything - effectively restricting it to syscalls that don't
require a certain promise. This is part of OpenBSD's pledge() as well,
which served as basis for Serenity's.
This commit is contained in:
Linus Groh 2021-01-25 22:42:36 +01:00 committed by Andreas Kling
parent b580c005f1
commit 629180b7d8
Notes: sideshowbarker 2024-07-18 22:51:10 +09:00
2 changed files with 5 additions and 9 deletions

View File

@ -467,7 +467,7 @@ public:
bool has_promises() const
{
return m_promises;
return m_has_promises;
}
bool has_promised(Pledge pledge) const
{
@ -637,6 +637,7 @@ private:
RefPtr<Timer> m_alarm_timer;
bool m_has_promises { false };
u32 m_promises { 0 };
u32 m_execpromises { 0 };

View File

@ -67,29 +67,24 @@ int Process::sys$pledge(Userspace<const Syscall::SC_pledge_params*> user_params)
return true;
};
u32 new_promises;
u32 new_execpromises;
u32 new_promises = 0;
u32 new_execpromises = 0;
if (!promises.is_null()) {
new_promises = 0;
if (!parse_pledge(promises, new_promises))
return -EINVAL;
if (m_promises && (!new_promises || new_promises & ~m_promises))
return -EPERM;
} else {
new_promises = m_promises;
}
if (!execpromises.is_null()) {
new_execpromises = 0;
if (!parse_pledge(execpromises, new_execpromises))
return -EINVAL;
if (m_execpromises && (!new_execpromises || new_execpromises & ~m_execpromises))
return -EPERM;
} else {
new_execpromises = m_execpromises;
}
m_has_promises = true;
m_promises = new_promises;
m_execpromises = new_execpromises;