Search code examples
memory-managementlinux-kernelsystem-callsbrk

Is memory cleared by the Linux kernel when brk is reduced then increased again?


I'm just wondering about what happens to memory that a user program releases through a brk system call, then gets back again. Does the kernel clear it out or is the contents left undefined?

I believe that the kernel clears out pages when they are newly allocated via brk, but I can't work out if it zeros them all if that page is returned, then requested back again. I'm looking through lxr.linux.no to try to find out. I'll also have a look at the book suggested in this post.

Thanks for your replies.

Tim


Solution

  • You get a fresh zeroed page: http://lxr.linux.no/#linux+v2.6.30.5/mm/memory.c#L2580

    The content of a fresh page has to be cleared out. It could contain sensitive information, think about security.