diff --git a/patches/kernel/9998-rdtsc-spoof-hook-0.patch b/patches/kernel/9998-rdtsc-spoof-hook-0.patch new file mode 100644 index 0000000..7679517 --- /dev/null +++ b/patches/kernel/9998-rdtsc-spoof-hook-0.patch @@ -0,0 +1,14 @@ +diff -Naur --no-dereference a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c +--- a/arch/x86/kvm/vmx/vmx.c 2024-07-01 21:03:34.000000000 +0300 ++++ b/arch/x86/kvm/vmx/vmx.c 2024-07-01 20:24:05.000000000 +0300 +@@ -6137,6 +6137,10 @@ + [EXIT_REASON_ENCLS] = handle_encls, + [EXIT_REASON_BUS_LOCK] = handle_bus_lock_vmexit, + [EXIT_REASON_NOTIFY] = handle_notify, ++ [EXIT_REASON_RDTSC] = handle_rdtsc, ++ [EXIT_REASON_RDTSCP] = handle_rdtscp, ++ [EXIT_REASON_UMWAIT] = handle_umwait, ++ [EXIT_REASON_TPAUSE] = handle_tpause, + }; + + static const int kvm_vmx_max_exit_handlers = diff --git a/patches/kernel/9999-rdtsc-spoof-hook-1.patch b/patches/kernel/9999-rdtsc-spoof-hook-1.patch new file mode 100644 index 0000000..ead5885 --- /dev/null +++ b/patches/kernel/9999-rdtsc-spoof-hook-1.patch @@ -0,0 +1,40 @@ +diff -Naur --no-dereference a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c +--- a/arch/x86/kvm/vmx/vmx.c 2024-07-01 21:03:34.000000000 +0300 ++++ b/arch/x86/kvm/vmx/vmx.c 2024-07-01 20:24:05.000000000 +0300 +@@ -6079,6 +6079,36 @@ + return 1; + } + ++static int handle_rdtsc(struct kvm_vcpu *vcpu) ++{ ++ u64 _rdtsc = rdtsc(); ++ printk_once("[HookEntry] hook entry function handle_rdtsc is working, return the rdtsc() if no hook , you can hook here!\n"); ++ vcpu->arch.regs[VCPU_REGS_RAX] = _rdtsc & -1u; ++ vcpu->arch.regs[VCPU_REGS_RDX] = (_rdtsc >> 32) & -1u; ++ return kvm_skip_emulated_instruction(vcpu); ++} ++ ++static int handle_rdtscp(struct kvm_vcpu *vcpu) ++{ ++ u64 _rdtsc = rdtsc(); ++ printk_once("[HookEntry] hook entry function handle_rdtscp is working, return the rdtsc() if no hook , you can hook here!\n"); ++ vcpu->arch.regs[VCPU_REGS_RAX] = _rdtsc & -1u; ++ vcpu->arch.regs[VCPU_REGS_RDX] = (_rdtsc >> 32) & -1u; ++ return kvm_skip_emulated_instruction(vcpu); ++} ++ ++static int handle_umwait(struct kvm_vcpu *vcpu) ++{ ++ kvm_skip_emulated_instruction(vcpu); ++ return 1; ++} ++ ++static int handle_tpause(struct kvm_vcpu *vcpu) ++{ ++ kvm_skip_emulated_instruction(vcpu); ++ return 1; ++} ++ + /* + * The exit handlers return 1 if the exit was handled fully and guest execution + * may resume. Otherwise they set the kvm_run parameter to indicate what needs diff --git a/patches/kernel/9999-rdtsc-spoof-hook.patch b/patches/kernel/9999-rdtsc-spoof-hook.patch deleted file mode 100644 index ab1a32d..0000000 --- a/patches/kernel/9999-rdtsc-spoof-hook.patch +++ /dev/null @@ -1,51 +0,0 @@ -diff -Naur --no-dereference a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c ---- a/arch/x86/kvm/vmx/vmx.c 2024-07-01 21:03:34.000000000 +0300 -+++ b/arch/x86/kvm/vmx/vmx.c 2024-07-01 20:24:05.000000000 +0300 -@@ -6137,6 +6167,10 @@ - [EXIT_REASON_ENCLS] = handle_encls, - [EXIT_REASON_BUS_LOCK] = handle_bus_lock_vmexit, - [EXIT_REASON_NOTIFY] = handle_notify, -+ [EXIT_REASON_RDTSC] = handle_rdtsc, -+ [EXIT_REASON_RDTSCP] = handle_rdtscp, -+ [EXIT_REASON_UMWAIT] = handle_umwait, -+ [EXIT_REASON_TPAUSE] = handle_tpause, - }; - - static const int kvm_vmx_max_exit_handlers = -@@ -6079,6 +6079,36 @@ - return 1; - } - -+static int handle_rdtsc(struct kvm_vcpu *vcpu) -+{ -+ u64 _rdtsc = rdtsc(); -+ printk_once("[HookEntry] hook entry function handle_rdtsc is working, return the rdtsc() if no hook , you can hook here!\n"); -+ vcpu->arch.regs[VCPU_REGS_RAX] = _rdtsc & -1u; -+ vcpu->arch.regs[VCPU_REGS_RDX] = (_rdtsc >> 32) & -1u; -+ return kvm_skip_emulated_instruction(vcpu); -+} -+ -+static int handle_rdtscp(struct kvm_vcpu *vcpu) -+{ -+ u64 _rdtsc = rdtsc(); -+ printk_once("[HookEntry] hook entry function handle_rdtscp is working, return the rdtsc() if no hook , you can hook here!\n"); -+ vcpu->arch.regs[VCPU_REGS_RAX] = _rdtsc & -1u; -+ vcpu->arch.regs[VCPU_REGS_RDX] = (_rdtsc >> 32) & -1u; -+ return kvm_skip_emulated_instruction(vcpu); -+} -+ -+static int handle_umwait(struct kvm_vcpu *vcpu) -+{ -+ kvm_skip_emulated_instruction(vcpu); -+ return 1; -+} -+ -+static int handle_tpause(struct kvm_vcpu *vcpu) -+{ -+ kvm_skip_emulated_instruction(vcpu); -+ return 1; -+} -+ - /* - * The exit handlers return 1 if the exit was handled fully and guest execution - * may resume. Otherwise they set the kvm_run parameter to indicate what needs