Re: Why system call need to copy the date from the userspace before using it

Theodore Ts'o
2005-04-13T18:39:06Z

On Wed, Apr 13, 2005 at 08:40:05AM -0400, Richard B. Johnson wrote:
> The kernel does NOT have to copy data from user-space before
> using it.

Incorrect. It must, or the kernel code in question is by definition
buggy.

> In fact, user-mode pointers are valid in kernel-space
> when the kernel is performing a function on behalf of the user-
> mode code.

On some architectures, this is true. But not all architectures, and
not in all circumstances. For example, even on the x86 architecture,
in the 4G/4G mode, a user-mode pointer is *not* valid when kernel code
is running. You must use copy_to_user()/copy_from_user(). Simply
dereferencing a user-mode pointer is a BUG. It might work sometimes,
on some architectures, but not everywhere. Therefore, for correctly
written kernel code, you must not do it.

- Ted