Created
March 27, 2021 07:53
-
-
Save kohnakagawa/fb77904fcc44fc5652ef6d338c35a718 to your computer and use it in GitHub Desktop.
Checks whether your cpu supports Intel CET or not (Linux).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} | |
} |
Author
kohnakagawa
commented
Mar 27, 2021
Partial support on my 5950X (if this applies on AMD CPUs as well that is):
$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 25
model : 33
model name : AMD Ryzen 9 5950X 16-Core Processor
stepping : 0
microcode : 0xa201016
cpu MHz : 3400.000
cache size : 512 KB
physical id : 0
siblings : 32
core id : 0
cpu cores : 16
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 16
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca fsrm
bugs : sysret_ss_attrs spectre_v1 spectre_v2 spec_store_bypass
bogomips : 6789.78
TLB size : 2560 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management: ts ttp tm hwpstate cpb eff_freq_ro [13] [14]
$ gcc cet.c && ./a.out
CET Shadow Stack is supported
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment