Handling Kernel-Space Faults
Version 2.1 of the Linux kernel introduced a great enhancement in the handling of segmentation faults from kernel space. In this section, I’m going to give a quick overview of the principle. The way source code is affected by the new mechanism has already been described in "Section 17.3.”
As suggested earlier, recent versions of the kernel fully exploit the ELF binary format, in particular with regard to its capability to define user-defined sections in the compiled files. The compiler and linker guarantee that every code fragment belonging to the same section will be consecutive in the executable file and therefore in memory when the file is loaded.
Exception handling is implemented by defining two new sections in the kernel executable image (vmlinux). Each time any source code accesses user space via copy_to_user, put_user, or their reading counterparts, some code is added to both of these sections. Although this might look like a non-negligible amount of overhead, one of the outcomes of the new implementation is that there’s no longer any need to use an expensive verify_area mechanism. Moreover, if the user address being used is a correct one, the computational flow will see no jumps at all.
When the user address being accessed is invalid, the hardware issues a page fault. The fault handler (do_page_fault, in the architecture-specific source tree) identifies the fault as an ``incorrect address'' fault (as opposed to ``page not present'') and takes ...
Get Linux Device Drivers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.