Skip to content

Instantly share code, notes, and snippets.

@ldmsys
Created April 19, 2025 20:23
Show Gist options
  • Select an option

  • Save ldmsys/7b1bd0647af6312584be7d0f21b25d83 to your computer and use it in GitHub Desktop.

Select an option

Save ldmsys/7b1bd0647af6312584be7d0f21b25d83 to your computer and use it in GitHub Desktop.
SMAP Checker
#include <linux/module.h>
#include <linux/kernel.h>
static int __init smap_check_init(void) {
unsigned int eax, ebx, ecx, edx;
eax = 7;
ecx = 0;
asm volatile(
"cpuid"
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
: "a"(eax), "c"(ecx)
);
if (ebx & (1 << 20))
pr_info("✅ This CPU supports SMAP!\n");
else
pr_info("❌ This CPU does NOT support SMAP.\n");
return 0;
}
static void __exit smap_check_exit(void) {
pr_info("SMAP check module unloaded.\n");
}
module_init(smap_check_init);
module_exit(smap_check_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Minimal SMAP check kernel module");
obj-m += check_smap.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment