1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:07:46 +00:00

Kernel: Disable x86 RDTSC instruction in userspace

It's still possible to read the TSC via the read_tsc() syscall, but we
will now clear some of the bottom bits for unprivileged users.
This commit is contained in:
Andreas Kling 2020-01-01 18:18:02 +01:00
parent dfd759f75a
commit 38f93ef13b
6 changed files with 25 additions and 1 deletions

View file

@ -11,7 +11,7 @@
static void print_usage_and_exit()
{
printf("usage: crash -[AsdiamfMFTtSxyXUI]\n");
printf("usage: crash -[AsdiamfMFTtSxyXUIc]\n");
exit(0);
}
@ -101,6 +101,7 @@ int main(int argc, char** argv)
ExecuteNonExecutableMemory,
TriggerUserModeInstructionPrevention,
UseIOInstruction,
ReadTimestampCounter,
};
Mode mode = SegmentationViolation;
@ -143,6 +144,8 @@ int main(int argc, char** argv)
mode = TriggerUserModeInstructionPrevention;
else if (String(argv[1]) == "-I")
mode = UseIOInstruction;
else if (String(argv[1]) == "-c")
mode = ReadTimestampCounter;
else
print_usage_and_exit();
@ -342,5 +345,12 @@ int main(int argc, char** argv)
}).run(run_type);
}
if (mode == ReadTimestampCounter || mode == TestAllCrashTypes) {
Crash("Read the CPU timestamp counter", [] {
asm volatile("rdtsc");
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
return 0;
}