I have a pre-existing C with inline assembly embedded code which tries to update WP bit of CR0 register. After upgrading to Linux kernel 6.8.0 in Ubuntu 22.04, this code triggers a crash.
The same code runs perfectly fine in a virtual environment. It crashes only when it is running on a physical machine with an AMD processor.
This is my sample code.
inline void modify_wp_flag(unsigned long cr0){# if defined(__FORCE_ORDER) asm volatile("mov %0,%%cr0" : "+r"(cr0) : __FORCE_ORDER);# else asm volatile("mov %0,%%cr0" : "+r"(cr0), "+m"(__force_order));# endif}static int sampledriver_init(void){ //reset WP flag modify_wp_flag((unsigned long)(read_cr0() & (~ X86_CR0_WP))); //set WP flag modify_wp_flag((unsigned long)(read_cr0() | X86_CR0_WP)); return 0;}
Do you have any idea what has changed in Linux kernel 6.8.0 which is causing this? This code was working correctly with the previous kernel.