Copying Data Between User and Kernel Memory Safely
A pointer handed to you from a program is just a number in that program's address space: it may be invalid, may point at memory the program is not allowed to touch, or may be swapped out right now. So kernel code never dereferences it directly; it uses copy routines that check the address, handle a fault instead of crashing, and can report failure. Dereferencing it anyway turns a bad user pointer into a kernel crash or a security hole that lets a program read anything.
Questions this Concept answers
- Why can kernel code never dereference a user-supplied pointer directly, even one that looks perfectly reasonable?
Kernel Panic When Accessing User Space Directly? Why copy_to_user()/copy_from_user() Are Essential
This page explains why kernel code must never read or write a user program's memory through the pointer it was handed. That pointer is only a number in another address space: it may be invalid, may p…