Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if an address is readable in linux userspace app

Tags:

For debugging purposes I need to test a pointer to see if it points to a valid readable page. Currently I am parsing /proc/[pid]/maps to see if the address is mapped ok, but this seems a bit long-winded. Is there a better way? Thanks.

like image 735
gimmeamilk Avatar asked Aug 20 '11 20:08

gimmeamilk


People also ask

What is process address space in Linux?

The address space of a process consists of all linear addresses that the process is allowed to use. Each process sees a different set of linear addresses; the address used by one process bears no relation to the address used by another.

How does copy_ from_ user work?

The copy_from_user function copies a block of data from user space into a kernel buffer. it accepts a destination buffer (in kernel space), a source buffer (from user space), and a length defined in bytes.


1 Answers

The canonical way is to use the write() system call to read from the page (writing to a dummy pipe() file descriptor). Instead of faulting, it will return -1 with errno == EFAULT if the buffer passed to write() is unreadable.

like image 156
caf Avatar answered Sep 20 '22 18:09

caf