diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-10-03 15:56:51 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-10-03 15:56:51 +0000 |
commit | 55c3138c640967ae82b21feb4c33acb9edcbc75b (patch) | |
tree | 8e91f28df5dd0a78bc516733f6aebd0d16f2768e /sys/src/9/port/pgrp.c | |
parent | b6381141861419f8cf2a11e3c2ff605755a5becc (diff) |
kernel: ensure that all accesses to Mhead.mount is done with Mhead.lock acquired
The Mhead structures have two sources of references to them:
- from Pgrp.mnthash hash-table
- from a channels Chan.umh pointer as returned by namec() for a union directory
Unless one holds the Mhead.lock RWLock, the Mhead.mount chain
can be mutated by eigther cmount(), cunmount() or closepgrp().
Readers, skipping acquiering the lock where:
mountfix(): responsible for rewriting directory entries for
union directory reads; was walking the Mhead.mount chain to
detect if the passed channel itself appears in the mount list.
cmount(): had a check and copy when "new" chan was a union itself
and if the MCREATE flag is set and would copy the mount table.
All this needs to be done with Mhead read-locked while copying
the mount entries.
devproc(): in the handler for reading /proc/n/ns file.
namec(): while checking if the Chan->umh should be initialized.
In addition to this, cmount() is changed to do the mountfree()
of the original mount chain when MREPL is done after releasing
the locks.
Also, some cosmetic changes...
Diffstat (limited to 'sys/src/9/port/pgrp.c')
-rw-r--r-- | sys/src/9/port/pgrp.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/sys/src/9/port/pgrp.c b/sys/src/9/port/pgrp.c index 9f9fb0b65..14bfc9ef5 100644 --- a/sys/src/9/port/pgrp.c +++ b/sys/src/9/port/pgrp.c @@ -62,16 +62,12 @@ closepgrp(Pgrp *p) free(p); } -void +static void pgrpinsert(Mount **order, Mount *m) { Mount *f; m->order = nil; - if(*order == nil) { - *order = m; - return; - } for(f = *order; f != nil; f = f->order) { if(m->mountid < f->mountid) { m->order = f; @@ -90,15 +86,14 @@ void pgrpcpy(Pgrp *to, Pgrp *from) { Mount *n, *m, **link, *order; - Mhead *f, **tom, **l, *mh; + Mhead *f, **l, *mh; int i; wlock(&to->ns); rlock(&from->ns); order = nil; - tom = to->mnthash; for(i = 0; i < MNTHASH; i++) { - l = tom++; + l = &to->mnthash[i]; for(f = from->mnthash[i]; f != nil; f = f->hash) { rlock(&f->lock); mh = newmhead(f->from); @@ -248,7 +243,7 @@ newmount(Chan *to, int flag, char *spec) m->mflag = flag; if(spec != nil) kstrdup(&m->spec, spec); - + setmalloctag(m, getcallerpc(&to)); return m; } |