diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-05-02 19:34:00 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-05-02 19:34:00 +0000 |
commit | 9126ee3eea90d639f4e877c01400248581d10f65 (patch) | |
tree | 5547155701251322c90854249e5fcee0c3828ad5 /sys/src/9/port/sysproc.c | |
parent | 641bd4512ff02b1b86157263ab604bc790f0c89d (diff) |
kernel: fix noteid change race condition from devproc while forking (thanks joe7)
devproc allows changing the noteid of another process
which opens a race condition in sysrfork(), when deciding
to inherit the noteid of "up" to the child and calling
pidalloc() later to take the reference, the noteid could
have been changed and the childs noteid could have been
freed already in the process.
this bug can only happen when one writes the /proc/n/noteid
file of a another process than your own that is in the
process of forking.
the noteid changing functionality of devproc seems questinable
and seems to be only used by ape's setpgrid() implementation.
Diffstat (limited to 'sys/src/9/port/sysproc.c')
-rw-r--r-- | sys/src/9/port/sysproc.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c index f451e047d..b3b7a0439 100644 --- a/sys/src/9/port/sysproc.c +++ b/sys/src/9/port/sysproc.c @@ -79,14 +79,18 @@ sysrfork(va_list list) envcpy(up->egrp, oeg); closeegrp(oeg); } - if(flag & RFNOTEG) - setnoteid(up, 0); + if(flag & RFNOTEG){ + qlock(&up->debug); + setnoteid(up, 0); /* can't error() with 0 argument */ + qunlock(&up->debug); + } return 0; } if((p = newproc()) == nil) error("no procs"); + qlock(&up->debug); qlock(&p->debug); p->scallnr = up->scallnr; @@ -112,7 +116,8 @@ sysrfork(va_list list) p->procctl = Proc_tracesyscall; p->kp = 0; - /* Craft a return frame which will cause the child to pop out of + /* + * Craft a return frame which will cause the child to pop out of * the scheduler in user mode with the return register zero */ forkchild(p, up->dbgreg); @@ -132,6 +137,7 @@ sysrfork(va_list list) pid = pidalloc(p); qunlock(&p->debug); + qunlock(&up->debug); /* Abort the child process on error */ if(waserror()){ |