Skip to content
Advertisement

Virtual address to physical address and reverse in android linux kernel

I’m trying to transform virtual address to physical address and map this physical address to virtual address with android linux kernel environment.

I can modify kernel code. So I tried next flow.

  1. malloc() in android user space native binary not app
  2. Transform va from malloc() to pa using the guide Is there any API for determining the physical address from virtual address in Linux?
  3. Pass pa to a system call function I made.
  4. Re-map received pa to va in linux kernel space using ioremap()
  5. Read value using readl() or ioread32()

But it’s not working now.

  1. The va to pa logic is in above link; in my native binary, below is the pseudo-code.
JavaScript
  1. system call function
JavaScript

My code has similar logic:

  • I define va in user space and calculate pa from va.
  • I set va to “ttttt”.
  • Pass pa to linux kernel space using syscall.
  • Remap this pa to va in kernel space.
  • Read va in kernel space and expect the value to be “ttttt”

I don’t know the va to pa logic is correct. But it returns an address not failure.

But when syscall is called, kernel panic occur – e.g. “dereference for 0000000 address”, and other kinds of errors. I checked pa in syscall is same with the one in user space.

My purpose of this try is study. I just wonder this implementation is possible if I can modify kernel code too but I met with an obstacle.

Please let me know what is problem or it’s impossible? If needed, I’ll update more detail code or specific error message.


I add detail errors and my debug log.

My user space log

JavaScript

I pass 0xa4a8a000 to syscall.

dmesg

JavaScript

Advertisement

Answer

I found fix. ioremap have a check logic for validation of address. This function is for reserved address but it tring to map address that’s already mapped to a process. So, I modify the check logic in ioreamp and it works well.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement