Kernel: If userspace sets fs or gs, dont overwrite it
Current cpu index is stored at either segment. If userspace sets that segment, kernel will not overwrite it on every reschedule. This is fine as long as user program does not use anything that relies on it :)
This commit is contained in:
@@ -177,7 +177,9 @@ namespace Kernel
|
||||
bool m_is_userspace { false };
|
||||
bool m_delete_process { false };
|
||||
|
||||
bool m_has_custom_fsbase { false };
|
||||
vaddr_t m_fsbase { 0 };
|
||||
bool m_has_custom_gsbase { false };
|
||||
vaddr_t m_gsbase { 0 };
|
||||
|
||||
SchedulerQueue::Node* m_scheduler_node { nullptr };
|
||||
|
||||
@@ -3302,7 +3302,9 @@ namespace Kernel
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_set_fsbase(void* addr)
|
||||
{
|
||||
Thread::current().set_fsbase(reinterpret_cast<vaddr_t>(addr));
|
||||
auto& thread = Thread::current();
|
||||
thread.m_has_custom_fsbase = true;
|
||||
thread.set_fsbase(reinterpret_cast<vaddr_t>(addr));
|
||||
Processor::load_fsbase();
|
||||
return 0;
|
||||
}
|
||||
@@ -3314,7 +3316,9 @@ namespace Kernel
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_set_gsbase(void* addr)
|
||||
{
|
||||
Thread::current().set_gsbase(reinterpret_cast<vaddr_t>(addr));
|
||||
auto& thread = Thread::current();
|
||||
thread.m_has_custom_gsbase = true;
|
||||
thread.set_gsbase(reinterpret_cast<vaddr_t>(addr));
|
||||
Processor::load_gsbase();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -305,6 +305,14 @@ namespace Kernel
|
||||
if (!is_userspace() || !has_process())
|
||||
return;
|
||||
|
||||
#if ARCH(x86_64)
|
||||
if (m_has_custom_gsbase)
|
||||
return;
|
||||
#elif ARCH(i686)
|
||||
if (m_has_custom_fsbase)
|
||||
return;
|
||||
#endif
|
||||
|
||||
const vaddr_t vaddr = process().shared_page_vaddr() + Processor::current_index();
|
||||
|
||||
#if ARCH(x86_64)
|
||||
|
||||
Reference in New Issue
Block a user