I implemented a new system call as an intro exercise. All it does is take in a buffer and printk that buffer. I later learned that the correct practice would be to use copy_from_user.
Is this just a precautionary measure to validate the address, or is my system call causing some error (page fault?) that I cannot see?
If it is just a precautionary measure, what is it protecting against?
Thanks!
There are several reasons.
copy_from_user
is essential to actually get the right memory address.copy_from_user
could allow information disclosure if a user passes in a kernel address. Worse, if you are writing to a user-supplied buffer without copy_to_user
, the user could overwrite kernel memory.copy_from_user
protects against faults so e.g. a system call handler can return EFAULT
in response to a bad user pointer.