写入MAP_PRIVATE mmaped文件 [英] Writing to MAP_PRIVATE mmaped file

查看:65
本文介绍了写入MAP_PRIVATE mmaped文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解这种肮脏的CoW概念证明: https://github.com/dirtycow/dirtycow...ter/dirtyc0w.c .

I am trying to understand this dirty CoW proof of concept: https://github.com/dirtycow/dirtycow...ter/dirtyc0w.c.

当子线程(上面链接中的 procselfmemThread)写入被父线程映射为 MAP_PRIVATE 和 PROT_READ 的内存时会发生什么?具体来说,内核是否将现有映射修改为匿名且可写?何时进行写时复制?假设另一个子线程(上面链接中的madviseThread)没有运行.

What happens when a child thread (procselfmemThread in the link above) writes to memory that is mapped as MAP_PRIVATE and PROT_READ by the parent? Specifically, does the kernel modify the existing mapping to be anonymous and writeable? And when does copy-on-write take place? Let's assume that the other child thread (madviseThread in the link above) is not running.

推荐答案

要精确回答您的问题,请分两部分进行回答1.内存映射一个只读文件由于您已经使用PROT_READ和MAP_PRIVATE映射了文件,这将为您的文件创建VMA(虚拟内存区域).VMA只是元数据结构,用于管理您的过程区域,例如文本,数据和mmap区域.VMA将具有起始地址和结束地址,这些起始地址和结束地址基本上是用于文件映射的内存映射区域和仅红色区域(自PROT_READ起)的进程虚拟地址.

To answer your question precisely, answer in two parts 1. memory map a read only file since you already mapped a file with PROT_READ and MAP_PRIVATE , this will create the VMA (virtual memory area)for your file. VMA is nothing but a metadata structure to mange your process region like text, data and mmap regions. VMA will have start and end address, these start and end address basically your process virtual addresses for memory mapped region which is file backed and a red only region (since PROT_READ).

  1. 写入/proc/self/mem
    /proc/self/mem是一个特殊的文件,它允许访问进程虚拟地址空间,因为在u提到的程序中,它会向内存映射区域(MAP_PRIVATE)查找文件描述符.它基本上是在写入较早映射文件的内存映射区域,因为它在写入时是只读映射,因此会创建页面副本并在写入时进行复制.注意:此处/proc/self/mem文件正在写入,而不是文件的内存映射区域.

这篇关于写入MAP_PRIVATE mmaped文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆