summaryrefslogtreecommitdiff
path: root/sys/src/9/port/sysproc.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-02-23 18:00:21 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-02-23 18:00:21 +0100
commit4a80d9d029891e056a7badeeea8e3b588efd694b (patch)
tree2f37c2e83416f47df87d40eae2e2120cd8bcb049 /sys/src/9/port/sysproc.c
parentf7c60230669e8e00bc794f07726070d577d5aa3f (diff)
kernel: fix multiple devproc bugs and pid reuse issues
devproc assumes that when we hold the Proc.debug qlock, the process will be prevented from exiting. but there is another race where the process has already exited and the Proc* slot gets reused. to solve this, on process creation we also have to acquire the debug qlock while initializing the fields of the process. this also means newproc() should only initialize fields *not* protected by the debug qlock. always acquire the Proc.debug qlock when changing strings in the proc structure to avoid doublefree on concurrent update. for changing the user string, we add a procsetuser() function that does this for auth.c and devcap. remove pgrpnote() from pgrp.c and replace by static postnotepg() in devproc. avoid the assumption that the Proc* entries returned by proctab() are continuous. fixed devproc permission issues: - make sure only eve can access /proc/trace - none should only be allowed to read its own /proc/n/text - move Proc.kp checks into procopen() pid reuse was not handled correctly, as we where only checking if a pid had a living process, but there still could be processes expecting a particular parentpid or noteid. this is now addressed with reference counted Pid structures which are organized in a hash table. read access to the hash table does not require locks which will be usefull for dtracy later.
Diffstat (limited to 'sys/src/9/port/sysproc.c')
-rw-r--r--sys/src/9/port/sysproc.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c
index ad9386b9e..075fdbd43 100644
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -80,12 +80,14 @@ sysrfork(va_list list)
closeegrp(oeg);
}
if(flag & RFNOTEG)
- up->noteid = pidalloc(nil);
+ setnoteid(up, 0);
return 0;
}
p = newproc();
+ qlock(&p->debug);
+
p->scallnr = up->scallnr;
p->s = up->s;
p->slash = up->slash;
@@ -96,16 +98,18 @@ sysrfork(va_list list)
p->nnote = up->nnote;
p->notify = up->notify;
p->notified = 0;
+ p->notepending = 0;
p->lastnote = up->lastnote;
+ if((flag & RFNOTEG) == 0)
+ p->noteid = up->noteid;
- p->noteid = up->noteid;
- p->parentpid = up->pid;
p->procmode = up->procmode;
p->privatemem = up->privatemem;
p->noswap = up->noswap;
p->hang = up->hang;
if(up->procctl == Proc_tracesyscall)
p->procctl = Proc_tracesyscall;
+ p->kp = 0;
/* Craft a return frame which will cause the child to pop out of
* the scheduler in user mode with the return register zero
@@ -115,6 +119,8 @@ sysrfork(va_list list)
kstrdup(&p->text, up->text);
kstrdup(&p->user, up->user);
kstrdup(&p->args, "");
+ p->nargs = 0;
+ p->setargs = 0;
p->insyscall = 0;
memset(p->time, 0, sizeof(p->time));
@@ -122,6 +128,8 @@ sysrfork(va_list list)
pid = pidalloc(p);
+ qunlock(&p->debug);
+
/* Abort the child process on error */
if(waserror()){
p->kp = 1;
@@ -189,9 +197,6 @@ sysrfork(va_list list)
incref(p->egrp);
}
- if(flag & RFNOTEG)
- p->noteid = pid;
-
procfork(p);
poperror(); /* abortion */