/proc/$pid/maps shows pages with no rwx permissions on x86_64 linux

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

/proc/$pid/maps shows pages with no rwx permissions on x86_64 linux. I noticed that when I read /proc/$pid/maps at 64bit linux I have memory pages that have no permissions, but in a 32bit linux, they aren't there.

I’m trying to monitor the memory usage of my process, but Im confused. Why are there pages with no rwx privileges. They are consuming my memory!

This is a snippet of the output of a 64bit linux for ‘top’

% cat /proc/21367/maps  3154200000-315420d000 r-xp 00000000 fd:00 4835776 /lib64/libproc-3.2.7.so 
315420d000-315440d000 **---p** 0000d000 fd:00 4835776 /lib64/libproc-3.2.7.so
315440d000-315440e000 rw-p 0000d000 fd:00 4835776 /lib64/libproc-3.2.7.so

please advise.

回答1:

These mappings are used for shared libraries:

In general for each shared library loaded we will have four mappings:

3b7cc00000-3b7cd86000 r-xp 00000000 fd:00 661350            /lib64/libc-2.12.so 3b7cd86000-3b7cf86000 ---p 00186000 fd:00 661350            /lib64/libc-2.12.so 3b7cf86000-3b7cf8a000 r--p 00186000 fd:00 661350            /lib64/libc-2.12.so 3b7cf8a000-3b7cf8b000 rw-p 0018a000 fd:00 661350            /lib64/libc-2.12.so 

The first one is the code segment with executable permissions, the second one the PROT_NONE (no permissions) mapping, and the last two ones the data segment (read only part and read write).

The PROT_NONE mappings are created to do with keeping libraries efficiently sharable and to mark guard pages so buffer overflows can be catched.

Just keep in mind that these mappings are only using part of the virtual address space but they are not actually consuming the systems memory.

Here you can find a complete explanation:

http://www.greenend.org.uk/rjk/tech/dataseg.html



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!