1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

copy-on-write text pages when forking

Discussion in 'FreeBSD Development' started by fluca1978, Sep 13, 2011.

  1. fluca1978

    fluca1978 Member

    Messages:
    735
    Thanks Received:
    68
    Hi all,
    if I get it right, when a fork is performed the pages that contain text code are cloned using a copy-on-write technique, and the reason is that if a debugger is running attached to the cloned process, the text can be modified without affecting the parent of the process.
    Now, I have no idea of what happens when a debugger runs, but I thought that the text area was never ever modifiable under any circumstance, and the above seems to destruct my belief. Anyone can explain me better what happens in such case?
    Thanks
     
  2. trasz@

    trasz@ Member Developer

    Messages:
    200
    Thanks Received:
    46
    After fork, all of the pages (except for shared memory, either SysV or POSIX) are copy-on-write. Debugger uses ptrace(2) to write to the address space of debugged process. Since it's COW, other processes are not affected.
     
  3. fluca1978

    fluca1978 Member

    Messages:
    735
    Thanks Received:
    68
    Fine, searching a bit more I found that ptrace has flags to write inidcate the need to write instruction words and data. But this means that the text area is modifiable why the process is running. Even if this a special case (debugging applications), isn't this a problem with security?
     
  4. xibo

    xibo Member

    Messages:
    384
    Thanks Received:
    72
    You can only attach to a process running with your user ID.
     
  5. trasz@

    trasz@ Member Developer

    Messages:
    200
    Thanks Received:
    46
    Unless you're root. And of course there are additional restrictions due to jails (you cannot attach to a process with your UID running inside some other jail) and MAC.