WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] PATCH: Set close-on-exec flag for QEMU disks

To: Anthony Liguori <aliguori@xxxxxxxxxx>
Subject: Re: [Xen-devel] PATCH: Set close-on-exec flag for QEMU disks
From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
Date: Tue, 6 Mar 2007 16:34:15 +0000
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, Keir Fraser <keir@xxxxxxxxxxxxx>
Delivery-date: Tue, 06 Mar 2007 08:33:29 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <45EC8A5F.3020308@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <C211CAC3.A969%keir@xxxxxxxxxxxxx> <45EC8A5F.3020308@xxxxxxxxxx>
Reply-to: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.4.1i
On Mon, Mar 05, 2007 at 03:23:43PM -0600, Anthony Liguori wrote:
> Keir Fraser wrote:
> >On 2/3/07 21:40, "Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
> >
> >  
> >>QEMU does not currently set the close-on-exec flag after opening its 
> >>virtual
> >>disk images. This causes problems when it later runs the 
> >>/etc/xen/qemu-ifup
> >>script because the file descriptors get propagated to networking commands
> >>like brctl / ifconfig. The SELinux policy quite rightly does not allow the
> >>networking scripts to access the virtual disk images, so these inherited
> >>file descriptors for AVC denials to be logged.
> >>
> >>The attached patch modifies all the QEMU disk driver backends to make sure
> >>the close-on-exec flag is turned on
> >>    
> >
> >It would be nicer to implement an open_cloexec() function in e.g., vl.c to
> >do the open() and fcntl() in one go and in one place.
> >  
> 
> There are few areas where scripts are executed.  Why not just introduce 
> an exec() wrapper that closes file descriptors appropriately.

Looking at the QEMU code in Xen there are only two places where exec is
used, and one of those is for the vncviewer spawning which isn't upstream.
One of them uses execlp() while the other uses execv(). So rather than 
doing a refactoring of code which will lead to even more divergance with
upstream, the attached patch just fixes up those 2 locations to close all
file handles upto sysconf(_SC_OPEN_MAX), with exception of STDIN/OUT/ERR
and the TAP deevice handle.

   Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>

I've tested against Xen 3.0.4 in Fedora to validate neither the qemu-ifup
or vncviewer processes receive any extraneous file handles. The attached
patch applies cleanly to xen-unstable.hg too

Regards,
Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 

Attachment: xen-qemu-close-fds-2.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>