From 24b71d1170fe887806ba538398c5c75ae801d96d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 6 Dec 2023 18:14:27 +0200 Subject: [PATCH] Kernel: Appreciate setuid and setgid bits executables --- LibELF/LibELF/LoadableELF.cpp | 8 ++++++++ LibELF/include/LibELF/LoadableELF.h | 3 +++ kernel/kernel/Process.cpp | 1 + 3 files changed, 12 insertions(+) diff --git a/LibELF/LibELF/LoadableELF.cpp b/LibELF/LibELF/LoadableELF.cpp index 20d19b8a07..ebdb037afb 100644 --- a/LibELF/LibELF/LoadableELF.cpp +++ b/LibELF/LibELF/LoadableELF.cpp @@ -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 LoadableELF::load_page_to_memory(vaddr_t address) { for (const auto& program_header : m_program_headers) diff --git a/LibELF/include/LibELF/LoadableELF.h b/LibELF/include/LibELF/LoadableELF.h index d4733fa032..cd1431192b 100644 --- a/LibELF/include/LibELF/LoadableELF.h +++ b/LibELF/include/LibELF/LoadableELF.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -30,6 +31,8 @@ namespace LibELF bool is_address_space_free() const; void reserve_address_space(); + void update_suid_sgid(Kernel::Credentials&); + BAN::ErrorOr load_page_to_memory(Kernel::vaddr_t address); BAN::ErrorOr> clone(Kernel::PageTable&); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 45e420fa46..664459127c 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -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++)