'Hijacking page fault handler

I have a process PID that access a memory region that it's not allowed to, the CPU creates a trap into the kernel which calls do_page_fault() which will send SIGSEGV to the user process. The user process has a custom signal handler that has some logic and the faulting instruction is resumed. What I want to do is to move this signal handler logic to kernel space and prevent SIGSEGV from being sent. For that could I write a kernel module that hijacks the fault handler for this PID or something? or do I have to add my logic to do_page_fault()? Some guidance would be helpful.



Solution 1:[1]

userfaultfd() could be useful to you. It allows you to handle page faults in usermode.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1