]> git.pond.sub.org Git - empserver/commit
Fix race in io_output() that can lead to double-free
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 4 Jul 2010 15:30:33 +0000 (17:30 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 25 Jul 2010 16:24:00 +0000 (18:24 +0200)
commitd28fbbb186b9b6e8572f89d0e3f3ab5f0c783bc5
treeddd2bff83ac3a2b8e21645be30f52436756189cf
parent25115f4997294ab16c7ddd427e4fc67a89bd73cd
Fix race in io_output() that can lead to double-free

Move call of ioq_makeiov() to its use, because calling it before
empth_select() is racy, as follows.

Player thread flushes output by calling io_output(player->iop, 1).
io_output() sets up iov[] to point to queued output.  empth_select()
blocks on output.

Another thread sends a C_FLASH or C_INFORM message to this player.
This calls io_output(p->iop, 0).  The output file descriptor has
become writable since the player thread blocked on it, so some output
gets written and dequeued.

The player thread resumes, writes out iov[] and dequeues.  Any output
already written by the other thread gets duplicated.  If the other
thread's dequeue operation freed struct io buffers, there's use after
free followed by double-free.
src/lib/empthread/io.c