当 brk 减少然后再次增加时,Linux 内核会清除内存吗?

发布于 2024-08-03 00:53:24 字数 294 浏览 6 评论 0原文

我只是想知道用户程序通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是我以为 2024-08-10 00:53:24

您将获得一个新的归零页面: 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.

似最初 2024-08-10 00:53:24

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文