Skip to content

Instantly share code, notes, and snippets.

@mbs0221
Forked from kohnakagawa/check_cet_supported.c
Created May 12, 2022 11:28
Show Gist options
  • Save mbs0221/e8f39f93f4ca5e0caec51c5059ce9150 to your computer and use it in GitHub Desktop.
Save mbs0221/e8f39f93f4ca5e0caec51c5059ce9150 to your computer and use it in GitHub Desktop.
Checks whether your cpu supports Intel CET or not (Linux).
#include <stdio.h>
#include <cpuid.h>
#include <stdint.h>
int cpu_supports_cet_shadow_stack() {
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
__cpuid_count(7, 0, eax, ebx, ecx, edx);
return (ecx & (1 << 7)) != 0;
}
int cpu_supports_cet_ibt() {
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
__cpuid_count(7, 0, eax, ebx, ecx, edx);
return (edx & (1 << 20)) != 0;
}
int main() {
if (cpu_supports_cet_shadow_stack()) {
puts("CET Shadow Stack is supported");
}
if (cpu_supports_cet_ibt()) {
puts("CET IBT is supported");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment