Kernel: Appreciate setuid and setgid bits executables

This commit is contained in:
Bananymous 2023-12-06 18:14:27 +02:00
parent 0dc168a8c0
commit 24b71d1170
3 changed files with 12 additions and 0 deletions

View File

@ -203,6 +203,14 @@ namespace LibELF
m_loaded = true;
}
void LoadableELF::update_suid_sgid(Kernel::Credentials& credentials)
{
if (m_inode->mode().mode & +Inode::Mode::ISUID)
credentials.set_euid(m_inode->uid());
if (m_inode->mode().mode & +Inode::Mode::ISGID)
credentials.set_egid(m_inode->gid());
}
BAN::ErrorOr<void> LoadableELF::load_page_to_memory(vaddr_t address)
{
for (const auto& program_header : m_program_headers)

View File

@ -7,6 +7,7 @@
#include <BAN/UniqPtr.h>
#include <BAN/Vector.h>
#include <kernel/Credentials.h>
#include <kernel/FS/Inode.h>
#include <kernel/Memory/PageTable.h>
@ -30,6 +31,8 @@ namespace LibELF
bool is_address_space_free() const;
void reserve_address_space();
void update_suid_sgid(Kernel::Credentials&);
BAN::ErrorOr<void> load_page_to_memory(Kernel::vaddr_t address);
BAN::ErrorOr<BAN::UniqPtr<LoadableELF>> clone(Kernel::PageTable&);

View File

@ -474,6 +474,7 @@ namespace Kernel
MUST(sys_kill(pid(), SIGKILL));
}
m_loadable_elf->reserve_address_space();
m_loadable_elf->update_suid_sgid(m_credentials);
m_userspace_info.entry = m_loadable_elf->entry_point();
for (size_t i = 0; i < sizeof(m_signal_handlers) / sizeof(*m_signal_handlers); i++)