Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if an address is writable in x86 assembly

Using only (32 bits) x86 assembly, is it possible to check if an address is writable, without interacting with the operating system, and without risking a segfault?

The program will run on a Linux system in ring 3. I cannot use the "verw" instruction.

To give an example, I might want to check if the address 0x0804a000 is writable. But if I e.g. do "mov eax, 0x0804a000; mov [eax], eax" then, if the address is not writable, the program will segfault. The only other way I know is to e.g. call sys_read into the address and see if it fails, but this interacts with the operating system.

Is there a way to check if an address is writable given the constraints? If so, how?

like image 427
Chris Avatar asked Dec 29 '25 02:12

Chris


1 Answers

If you have kernel privileges you could probably find that info in the MMU.

But if you don't, you simply do not have access to it and must use OS facilities.

If you mean not calling an OS function, then it is possible at least on Windows by using Structured Exception Handling. It is still OS specific of course, because you need to access the Windows TIB at the FS segment.

like image 113
typ1232 Avatar answered Dec 30 '25 23:12

typ1232