Re: Strangest bug

Alexander Viro (viro@math.psu.edu)
Fri, 23 Jul 1999 17:00:50 -0400 (EDT)


On Fri, 23 Jul 1999, Stanislav Krasilovskiy wrote:

> Hi,
>
> I am fairly new to kernel hacking, so forgive my stupidity. I have
> encountered a very strange bug and need help from someone who knows
> a lot about the kernel.
>
> Description of the problem: A process passes a pointer allocated in the
> user space to the kernel through a custom system call. This pointer is
> then saved for future reference.
>
> Upon an interrupt, a kernel routine uses this saved pointer with
> copy_from_user() to obtain a copy of that structure. The problem is,
> every now and then the values in the structure are bogus!

And interrupt happens in the context of another process. So? What did you
expect? Interrupts. Can. Not. Access. User. Address. Space. On any UNIX.

> This is not due to memory corruption (in the user process, I
> continuously print out the values, and they are fine). When I use
> mlock() on the structure, then the problem no longer occurs (the copy
> reflects accurate values). So the problem has something to do with
> virtual addressing and paging...

If you are translating it to the kernel space address - you'ld better tell
the kernel to keep whatever is mapped there in place. Which mlock() does.

You should not do that. Really. Use mmap() instead of those tricks. Let
the driver allocate a page and modify it. Let the process ask for this
page being mapped to its address space. No problems, no mlock(), no
playing with address translation.

-
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/