lkml.org 
[lkml]   [1999]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Fetching a value of control registers from user space
On 4 Jan 1999, Josip Gracin wrote:

> Hi!
>
> When I try to use the following program I get a SEGV fault. Why is this?
> I thought reading a value from control registers isn't supposed to
> generate an exception.
>
> int
> main ()
> {
> unsigned long fa;
> asm ("movl %%cr2, %0": "=r" (fa));
>
> return 0;
> }
>
> Thanks in advance.

Quote: (Intel 26-212)
MOV to/from Special Registers.
#GP(0) if current privilege level is not 0.

This is a general protection violation. No user-mode program would
(should) ever use these instructions.

In principle, a user-mode program should not even be able to do
this:

int
main ()
{
register unsigned long eax asm("%eax");
asm ("movl %ebx, %eax\n");
printf("%08lX\n", eax);
return 0;
}
... reading the value from an uninitialized register. But you can.
The CPU can't protect everything. This came up in a discussion about
having the kernel zero, or predefine, general purpose registers upon
process creation. The problem(s) being screwing up fork(), et al.

If you want to mess with priv level 0 stuff, make a module.

Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.1.131 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.
Wisdom : It's not a Y2K problem. It's a Y2Day problem.


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

\
 
 \ /
  Last update: 2005-03-22 13:49    [from the cache]
©2003-2011 Jasper Spaans