// SPDX-License-Identifier: GPL-2.0-only /* * sysret_ss_attrs.c - test that syscalls return valid hidden SS attributes * Copyright (c) 2015 Andrew Lutomirski * * On AMD CPUs, SYSRET can return with a valid SS descriptor with with * the hidden attributes set to an unusable state. Make sure the kernel * doesn't let this happen.
*/
int main()
{ /* * Start a busy-looping thread on the same CPU we're on. * For simplicity, just stick everything to CPU 0. This will * fail in some containers, but that's probably okay.
*/
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(0, &cpuset); if (sched_setaffinity(0, sizeof(cpuset), &cpuset) != 0)
printf("[WARN]\tsched_setaffinity failed\n");
printf("[RUN]\tSyscalls followed by SS validation\n");
for (int i = 0; i < 1000; i++) { /* * Go to sleep and return using sysret (if we're 64-bit * or we're 32-bit on AMD on a 64-bit kernel). On AMD CPUs, * SYSRET doesn't fix up the cached SS descriptor, so the * kernel needs some kind of workaround to make sure that we * end the system call with a valid stack segment. This * can be a confusing failure because the SS *selector* * is the same regardless.
*/
usleep(2);
#ifdef __x86_64__ /* * On 32-bit, just doing a syscall through glibc is enough * to cause a crash if our cached SS descriptor is invalid. * On 64-bit, it's not, so try extra hard.
*/
call32_from_64(stack32 + 4088, test_ss); #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.