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

Re: [Xen-devel] [PATCH v2] xl: close nullfd after dup2'ing it to stdin



On Wed, 2016-02-17 at 10:39 +0000, Ian Campbell wrote:
> We assert that nullfd if not std{in,out,err} since that would result
> in closing one of the just dup2'd fds. For this to happen
> std{in,out,err} would have needed to be closed, at which point all
> sorts of other things could go wrong.
> 
> CID: 1130519
> 
> It was previously hypothesised[0] that fixing 1130516 would solve this
> too, but that appears to not have been the case.
> 
> Compile tested only.
> 
> [0] http://lists.xenproject.org/archives/html/xen-devel/2013-11/msg02931.
> html
> 
> Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
> Cc: andrew.cooper3@xxxxxxxxxx

ping?

> ---
> v2: Assert logfile and nullfd are not stdio fds
> ---
> Âtools/libxl/xl_cmdimpl.c | 5 +++++
> Â1 file changed, 5 insertions(+)
> 
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 9958d8a..a377de1 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -499,12 +499,17 @@ static int do_daemonize(char *name, const char
> *pidfile)
> Â
> ÂÂÂÂÂCHK_SYSCALL(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND,
> 0644));
> ÂÂÂÂÂfree(fullname);
> +ÂÂÂÂassert(logfile >= 3);
> Â
> ÂÂÂÂÂCHK_SYSCALL(nullfd = open("/dev/null", O_RDONLY));
> +ÂÂÂÂassert(nullfd >= 3);
> +
> ÂÂÂÂÂdup2(nullfd, 0);
> ÂÂÂÂÂdup2(logfile, 1);
> ÂÂÂÂÂdup2(logfile, 2);
> Â
> +ÂÂÂÂclose(nullfd);
> +
> ÂÂÂÂÂCHK_SYSCALL(daemon(0, 1));
> Â
> ÂÂÂÂÂif (pidfile) {

_______________________________________________
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®.