Skip to content
Advertisement

trying to cause SIGSEGV in mmap

I’m trying to create a memory mapping of length greater than the underlying file. When I access pages of the mapping (which are not correspondingly mapped to a file), a SIGBUS is caused. However when I try to access the memory outside the memory mapping length, it should cause SIGSEGV (but isn’t), why is that?

JavaScript

Advertisement

Answer

Stopping your program and dumping /proc/pid/maps just after the mmap call, I get

JavaScript

So there are several other mappings immediately following the mapping of the file foo. I think your byte is at address 0x7f3fa1468c40 which is in one of the mappings of /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so, the dynamic linker. It’s readable mapped memory, whose contents happen not to be meaningful to you.

It looks from this like Linux’s memory mapping algorithm is to grow downwards, with each mapping placed in virtual memory just below the previous one. So it’s not surprising that when you go a short ways beyond your mapping, you end up at an address that is part of another map.

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