当 brk 减少然后再次增加时,Linux 内核会清除内存吗?
我只是想知道用户程序通过 brk 系统调用释放然后再次返回的内存会发生什么情况。内核是否将其清除或者内容未定义?
我相信内核会在通过 brk 新分配页面时清除它们,但我无法确定如果返回该页面然后再次请求返回,它是否会将它们全部清零。我正在查看 lxr.linux.no 试图找出答案。我还将看看这篇文章中建议的书。
感谢您的回复。
蒂姆
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将获得一个新的归零页面: http:// lxr.linux.no/#linux+v2.6.30.5/mm/memory.c#L2580
必须清除新页面的内容。它可能包含敏感信息,考虑安全性。
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.
IIRC 按需明确。因此,当一个页面被逐出时,内核会保留它,但是当分配给新用户/使用时(其中重新增长的 brk 将被计算在内),它将被清除。有各种技巧可以将新的匿名页面映射到“零页面”,然后将其交换为写入时真正清除的页面。
如果您担心信息泄漏,则不应将未分配的页面推送到交换区,尽管各种冷启动攻击可能会对它们起作用。
有关详细信息,请参阅最近的 LWN 文章:http://lwn.net/Articles/340370/
IIRC it is clear on demand. So when a page is evicted the kernel leaves it alone, however it will get cleared when allocated to a new user/use (of which a re-growing brk would count). There are various hacks to map fresh anonymous pages to "zero page" and then swap it for a real cleared page on write.
Unallocated pages shouldn't get get pushed to swap if you are worrying about information leakage, although various cold boot attacks may work against them.
See the recent LWN article for more info: http://lwn.net/Articles/340370/