1
$\begingroup$

I don't how this works. According to me if the physical memory is not cleared then there is some security risk as there may be some sensitive information in it from the other processes. How does the kernel take care of this?

$\endgroup$

1 Answer 1

2
$\begingroup$

Yes, the kernel zeroes out pages before allocating them to a user-level process. The details depend on the specific operating system; some may zero it out when the page is needed, others might run a separate thread that periodically zeroes out pages in anticipation that they'll be allocated.

$\endgroup$
4
  • $\begingroup$ Might be zeroing, might be filling with all bits set, or filling with random data: It just has to be something that makes it impossible for your process to gain any information about other processes. $\endgroup$
    – gnasher729
    Apr 30, 2020 at 23:12
  • $\begingroup$ If the pages are zeroed out, then why do the uninitialized variables contain garbage values instead of zero? $\endgroup$
    – Athul P
    May 1, 2020 at 7:26
  • $\begingroup$ @AthulP, because sometimes the program reuses deallocated memory without returning it to the OS and without zeroing it. But if it is returned to the OS, the OS will zero it. $\endgroup$
    – D.W.
    May 1, 2020 at 7:31
  • $\begingroup$ @AthulP, we often don’t care what a variable contains, but what we can guarantee. If there is no guarantee given by the programming language then we consider the contents to be garbage - even if sometimes it will be zeroes. And very, very often uninitialised variables contain leftovers if previously used variables. $\endgroup$
    – gnasher729
    May 1, 2020 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.