Re: copy_from_user/copy_to_user question

Robert Hancock
2005-12-03T02:47:18Z

Vinay Venkataraghavan wrote:
> But this is not always the case right. The point that
> you mention above is specifically why I posted this
> question. It could well be the case that the user
> space page could be swapped out when the user space
> process is blocked. So when the ioctl is serviced in
> kernel space, there is no guarantee that the page is
> still mapped. This could cause a page fault.
> I think this is why we need to do a
> copy_to_user/copy_from_user.

I don't think this is actually the case. I'm not entirely sure, but I
believe that if memcpy from user space works at all on a platform, then
if the page is swapped out it will still get swapped in when needed. In
any case, this is not the main reason for using these functions. The
main reason is that memory addresses passed from userspace might not be
valid at all, and reading these addresses directly would cause a kernel
oops in that case. These functions set up an exception handler so that
invalid address reads/writes return failure instead of crashing the system.

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/