Re: Memory Management Question

Colin Plumb (colin@nyx.net)
Thu, 8 Oct 1998 18:24:59 -0600 (MDT)


On Wed, Oct 07, 1998 at 01:49:15PM -0700, Brian Kress wrote:
> I'm trying to port some kernel code to Linux, and am
> running into one problem. Some of the code has a need to lock
> some pages from a user process into memory and then map that memory
> into the kernel's address space. This way the kernel driver code
> can access those pages directly, instead of through memcpy_from_user
> and friends. Is this possible?

Jamie Lokier replied:
> - If you block the user process, then you can access the user-space data
> safely. Most drivers do this one way or another.

Note that it is *not* safe to assume that if you read user-space data
twice, it will be the same! If you need a data structure to be
consistent for security, copy it to kernel space. There are just too
many ways to update user memory while a thread is running in the kernel.

Most of them involve another process or thread either sharing the memory
or using ptrace() to change it. It might seem safe to assume that
this will only happen if the kernel side blocks and lets a user process
run, but then you'll hit an SMP system.

It *is* reaosnable to say that "if you modify this buffer while the
system call is in progress, you'll get bizarre results", but those
bizarre results better not include crashing the system.

-- 
	-Colin

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/