]> git.lizzy.rs Git - plan9front.git/commit
kernel: avoid inconsistent reads in /proc/#/fd and /proc/#/ns
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sun, 21 Dec 2014 03:46:22 +0000 (04:46 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sun, 21 Dec 2014 03:46:22 +0000 (04:46 +0100)
commitcb35d1a132f881aac7151174fdb82ec9ff84682e
treea8129e292ecf5cb514ebb2eb9579d9b820b2cf9b
parent8ac28ac11cb9e96329e4d083208b3f13ee8d2b8a
kernel: avoid inconsistent reads in /proc/#/fd and /proc/#/ns

to allow bytewise access to /proc/#/fd, the contents of the file where
recreated on each call. if fd's had been closed or reassigned between
the reads, the offset would be inconsistent and a read could start off
in the middle of a line. this happens when you cat /proc/#/fd file of
a busy process that mutates its filedescriptor table.

to fix this, we now return one line record at a time. if the line
fits in the read size, then this means the next read will always start
at the beginning of the next line record. we remember the consumed
byte count in Chan.mrock and the current record in Chan.nrock. (these
fields are free to usefor non-directory files)

if a read comes in and the offset is the same as c->mrock, we do not
need to regenerate the file and just render the next c->nrock's record.

for reads smaller than the line count, we have to regenerate the content
up to the offset and the race is still possible, but this should not
be the common case.

the same algorithm is now used for /proc/#/ns file, allowing a simpler
reimplementation and getting rid of Mntwalk state strcture.
sys/src/9/port/devdup.c
sys/src/9/port/devproc.c
sys/src/9/port/portdat.h
sys/src/9/port/portfns.h