copy-on-write text pages when forking

Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

copy-on-write text pages when forking

Postby fluca1978 » 13 Sep 2011, 06:36

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
fluca1978
Member
 
Posts: 726
Joined: 20 May 2010, 08:53

Postby trasz@ » 13 Sep 2011, 11:27

After fork, all of the pages (except for shared memory, either SysV or POSIX) are copy-on-write. Debugger uses [man=2]ptrace[/man] to write to the address space of debugged process. Since it's COW, other processes are not affected.
trasz@
Member
 
Posts: 182
Joined: 20 Feb 2008, 22:44
Location: Warszawa, Poland

Postby fluca1978 » 15 Sep 2011, 10:40

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?
fluca1978
Member
 
Posts: 726
Joined: 20 May 2010, 08:53

Postby xibo » 15 Sep 2011, 11:38

You can only attach to a process running with your user ID.
xibo
Member
 
Posts: 373
Joined: 03 Dec 2010, 07:49
Location: Germany

Postby trasz@ » 19 Sep 2011, 14:05

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.
trasz@
Member
 
Posts: 182
Joined: 20 Feb 2008, 22:44
Location: Warszawa, Poland


Return to FreeBSD Development

Who is online

Users browsing this forum: No registered users and 0 guests