How to access kernel memory from user space

Ryan Stone rysto32 at gmail.com
Thu Feb 23 01:06:22 UTC 2012


On Wed, Feb 22, 2012 at 2:15 PM, Ian Lepore
<freebsd at damnhippie.dyndns.org> wrote:
> I've never done this, but if I needed to, I think the first thing I'd
> try is to use an mmap(2) of /dev/kmem to map the memory you need into
> userspace (of course your userspace app will need to be running with
> root privs to do this).
>
> That leaves the interesting problem of locating what offset within the
> kernel virtual address space you need to map to get at your data.  Two
> things come to mind... have your kernel module export the address in a
> sysctl (that feels kind of hack-ish but it should be quick and easy to
> do), or use libkvm's kvm_nlist() function to locate the symbol within
> your module (I think that should be possible; again I've never actually
> done any of this).

A far easier way to do this is to have the module create its own
device in /dev that exports the memory by implementing the mmap
interface in the cdev.


More information about the freebsd-hackers mailing list