--- arch/x86/include/asm/traps.h.orig 2024-01-11 17:27:31.149340916 +0300 +++ arch/x86/include/asm/traps.h 2024-01-11 17:29:36.585340438 +0300 @@ -23,6 +23,9 @@ void handle_invalid_op(struct pt_regs *regs); #endif +void setup_invalid_op_handler(int (*handler)(struct pt_regs *regs)); +void remove_invalid_op_handler(void); + static inline int get_si_code(unsigned long condition) { if (condition & DR_STEP) --- arch/x86/kernel/traps.c.orig 2024-01-05 17:13:40.000000000 +0300 +++ arch/x86/kernel/traps.c 2024-01-11 17:12:24.829344376 +0300 @@ -73,6 +73,21 @@ DECLARE_BITMAP(system_vectors, NR_VECTORS); +static int (*invalid_op_handler)(struct pt_regs *regs); + +void setup_invalid_op_handler(int (*handler)(struct pt_regs *regs)) +{ + invalid_op_handler = handler; +} +EXPORT_SYMBOL_GPL(setup_invalid_op_handler); + +void remove_invalid_op_handler(void) +{ + invalid_op_handler = NULL; +} +EXPORT_SYMBOL_GPL(remove_invalid_op_handler); + + static inline void cond_local_irq_enable(struct pt_regs *regs) { if (regs->flags & X86_EFLAGS_IF) @@ -182,6 +197,7 @@ cond_local_irq_disable(regs); } } +/* EXPORT_SYMBOL_GPL(do_error_trap); */ /* * Posix requires to provide the address of the faulting instruction for @@ -209,15 +225,21 @@ do_error_trap(regs, 0, "overflow", X86_TRAP_OF, SIGSEGV, 0, NULL); } -#ifdef CONFIG_X86_F00F_BUG +#if 1 /* defined CONFIG_X86_F00F_BUG */ void handle_invalid_op(struct pt_regs *regs) #else static inline void handle_invalid_op(struct pt_regs *regs) #endif { + if (invalid_op_handler) + if (invalid_op_handler(regs)) return; + do_error_trap(regs, 0, "invalid opcode", X86_TRAP_UD, SIGILL, ILL_ILLOPN, error_get_trap_addr(regs)); } +#if 1 +EXPORT_SYMBOL_GPL(handle_invalid_op); +#endif static noinstr bool handle_bug(struct pt_regs *regs) { --- kernel/kallsyms.c.orig 2024-01-05 17:13:40.000000000 +0300 +++ kernel/kallsyms.c 2024-01-11 12:48:04.281404912 +0300 @@ -203,6 +203,7 @@ } return module_kallsyms_lookup_name(name); } +EXPORT_SYMBOL_GPL(kallsyms_lookup_name); /* * Iterate over all symbols in vmlinux. For symbols from modules use