Kernel: Always inline stac(), clac() and SmapDisabler
Let's not be paying the function call overhead for these tiny ops. Maybe there's an argument for having fewer gadgets in the kernel but for now we're actually seeing stac() in profiles so let's put that above theoretical security issues.
This commit is contained in:
parent
e10183a6c5
commit
81d35c6891
Notes:
sideshowbarker
2024-07-19 06:19:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/81d35c68919
2 changed files with 17 additions and 20 deletions
|
@ -734,22 +734,6 @@ void cpu_detect()
|
|||
g_cpu_supports_umip = (extended_features.ecx() & (1 << 2));
|
||||
}
|
||||
|
||||
void stac()
|
||||
{
|
||||
if (!g_cpu_supports_smap)
|
||||
return;
|
||||
asm volatile("stac" ::
|
||||
: "cc");
|
||||
}
|
||||
|
||||
void clac()
|
||||
{
|
||||
if (!g_cpu_supports_smap)
|
||||
return;
|
||||
asm volatile("clac" ::
|
||||
: "cc");
|
||||
}
|
||||
|
||||
void cpu_setup()
|
||||
{
|
||||
cpu_detect();
|
||||
|
|
|
@ -584,18 +584,31 @@ extern bool g_cpu_supports_sse;
|
|||
extern bool g_cpu_supports_tsc;
|
||||
extern bool g_cpu_supports_umip;
|
||||
|
||||
void stac();
|
||||
void clac();
|
||||
ALWAYS_INLINE void stac()
|
||||
{
|
||||
if (!g_cpu_supports_smap)
|
||||
return;
|
||||
asm volatile("stac" ::
|
||||
: "cc");
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void clac()
|
||||
{
|
||||
if (!g_cpu_supports_smap)
|
||||
return;
|
||||
asm volatile("clac" ::
|
||||
: "cc");
|
||||
}
|
||||
|
||||
class SmapDisabler {
|
||||
public:
|
||||
SmapDisabler()
|
||||
ALWAYS_INLINE SmapDisabler()
|
||||
{
|
||||
m_flags = cpu_flags();
|
||||
stac();
|
||||
}
|
||||
|
||||
~SmapDisabler()
|
||||
ALWAYS_INLINE ~SmapDisabler()
|
||||
{
|
||||
if (!(m_flags & 0x40000))
|
||||
clac();
|
||||
|
|
Loading…
Add table
Reference in a new issue