Skip to content

Instantly share code, notes, and snippets.

@CaledoniaProject
Last active July 17, 2023 07:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaledoniaProject/d48f5d65d9a334f702a485a0391b271e to your computer and use it in GitHub Desktop.
Save CaledoniaProject/d48f5d65d9a334f702a485a0391b271e to your computer and use it in GitHub Desktop.
Disable write protection on Linux kernel >= 5.3.0
// https://medium.com/@hadfiabdelmoumene/change-value-of-wp-bit-in-cr0-when-cr0-is-panned-45a12c7e8411
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,3,0)
inline void write_cr0_new(unsigned long cr0)
{
asm volatile("mov %0,%%cr0" : "+r"(cr0), "+m"(__force_order));
}
#else
#define write_cr0_new write_cr0
#endif
#define WPOFF do { write_cr0_new(read_cr0() & (~0x10000)); } while (0);
#define WPON do { write_cr0_new(read_cr0() | 0x10000); } while (0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment