security - Is linux fork insecure -


i reading article

it says fork create copy of , fork man says so

. entire virtual address space of parent replicated in child

does mean child process can read process memory state ?

can child process dump entire parent memory state , can analysed extract parent variable , value. ?

but article says 2 process cannot ready each other data. confused ?

yes, child process can read a pristine copy of of parent process state (but when writing, own address space affected) after fork(2). however, of time, child use execve(2) start new program, , "clear" , replace copy of original parent's address space (by fresh address space). notice execve , mmap(2) (see shared memory in shm_overview(7)...) common ways change address space in virtual memory of process (and how kernel handles page faults).

the kernel uses (and sets mmu for) lazy copy on write machinery make child's address space copy of parent's one, fork quite efficient in practice.

read proc(5), type follow commands:

cat /proc/self/maps cat /proc/$$/maps sudo cat /proc/1/maps 

and understand happening

read wikipage on fork, , advanced linux programming book.

there no insecurity, because if child changing data (e.g. variable, heap or stack location, ...) not affect parent process.

if program doing fork keeping password in virtual memory location, child process able read location long executing same program. once child did successful execve (which common situation, , shell doing) previous address space gone , replaced new one, described in elf executable of exec-ed program.

there no "lie" or "insecurity" in unix model. contrarily several other operating systems, unix & posix have 2 separate system calls creating new process (fork) , executing new program (execve). other systems might have single spawn operation mixing 2 abilities. posix_spawn implemented mixture of fork & execve (and system(3) & popen(3), using waitpid(2) & /bin/sh....).

the advantage of unix approach (having separated fork & execve) after fork , before execve in child can lot of useful things (e.g. closing useless file descriptors, ...). operating systems not separating 2 features may need have quite complex spawning primitive.

there rare occasions fork not followed execve. mpi implementations might that, , might that. know able read parent's address space thru own copy - felt insecurity becoming useful feature. in old days had obsolete vfork blocked parents. there not need use today; actually, fork implemented thru clone(2) should not use directly in practice (see futex(7)...) thru posix pthreads. thinking of fork magical cloner of process might help.

when coding (even in c) don't forget test against failure of fork , of execve. see perror(3)

ps. fork syscall difficult understand multiverse idea. both "forking" time!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -