[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 3/3] libxl: datacopier: Avoid theoretical eof/POLLHUP race



On Thu, 2015-04-02 at 16:04 +0100, Ian Jackson wrote:
> When the bootloader exits, several things change, all at once:
>  (a) The master pty fd (held by libxl) starts to signal POLLHUP
>     and maybe also POLLIN.
>  (b) The child exits (so that the SIGCHLD self-pipe signals POLLIN,
>     which will be handled by the libxl child process code.
>  (c) reads on the master pty fd start to return EOF
> 
> From the point of view of the datacopier these might happen in any
> order.
> 
> (c) can be detected only after a previous POLLIN without POLLHUP and
> that previous POLLIN would be associated with data which was read,
> which must therefore have ended up in the dc's buffer.  But nothing
> stops the dc from writing that data into the output fd and reporting
> eof before it calls poll again.
> 
> This race is unlikely.  Indeed it might be actually 100% precluded, by
> luck, by the current organisation of the fd handling code.  But
> nevertheless it should be fixed.
> 
> We solve the race with a poll of the reading fd, to double-check, when
> we detect eof via read.  (This is only necessary if the caller has
> specified callback_pollhup, as otherwise POLLHUP|POLLIN - and,
> presumably, POLLIN followed perhaps by POLLHUP|POLLIN, is to be
> treated as eof anyway.)
> 
> Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
> CC: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> CC: Roger Pau Monnà <roger.pau@xxxxxxxxxx>

Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.