Bug 664406

Summary: qemu process is spawned with no supplementary groups
Product: Red Hat Enterprise Linux 6 Reporter: Dan Kenigsberg <danken>
Component: libvirtAssignee: Laine Stump <laine>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: urgent    
Version: 6.0CC: bazulay, berrange, cpelland, dallan, dyuan, eblake, gren, hateya, jialiu, jyang, mgoldboi, plyons, vbian, xen-maint, ykaul, yoyzhang
Target Milestone: rcKeywords: TestBlocker, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-0.8.7-1.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-05-19 13:25:06 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 602640, 668692    

Description Dan Kenigsberg 2010-12-20 10:37:07 UTC
Description of problem:
By default, libvirt spawns qemu with qemu:qemu uid:gid. However, on RHEL6, qemu user has a default supplementary group ('kvm'). Without libvirt calling initgroups(), qemu process cannot enjoy the credentials of 'kvm' group.

We need this in order for qemu to access group-readable ISO images with gid=kvm.

Version-Release number of selected component (if applicable):
libvirt-0.8.1-27.el6_0.2.x86_64

Upstream discussion under
https://www.redhat.com/archives/libvir-list/2010-December/msg00756.html

Comment 2 Laine Stump 2010-12-21 20:50:04 UTC
Fix posted upstream. Once it's ACKed, this will be in the next libvirt release / rebase.

https://www.redhat.com/archives/libvir-list/2010-December/msg00846.html

Comment 5 Laine Stump 2011-01-05 16:33:42 UTC
BTW, the patches mentioned in Comment 2 were pushed upstream prior to the recent libvirt-0.8.7 release, so the fix will be in the upcoming rebase:

commit f42cf7cb7902196382a65e5316c974a5c2106401
Author: Laine Stump <laine>
Date:   Tue Dec 21 15:34:41 2010 -0500

    Replace setuid/setgid/initgroups with virSetUIDGID()
    
    This patch fixes https://bugzilla.redhat.com/show_bug.cgi?id=664406
    
    If qemu is run as a different uid, it has been unable to access mode
    0660 files that are owned by a different user, but with a group that
    the qemu is a member of (aside from the one group listed in the passwd
    file), because initgroups() is not being called prior to the
    exec. initgroups will change the group membership of the process (and
    its children) to match the new uid.
    
    To make this happen, the setregid()/setreuid() code in
    qemuSecurityDACSetProcessLabel has been replaced with a call to
    virSetUIDGID(), which does both of those, plus calls initgroups.
    
    Similar, but not identical, code in qemudOpenAsUID() has been replaced
    with virSetUIDGID(). This not only consolidates the functionality to a
    single location, but also potentially fixes some as-yet unreported
    bugs.

commit d596c6dc9b64ca0c910a87127de72ed2ef47b692
Author: Laine Stump <laine>
Date:   Thu Dec 23 01:44:02 2010 -0500

    new virSetUIDGID() utility function
    
    virSetUIDGID() sets both the real and effective group and user of the
    process, and additionally calls initgroups() to assure that the
    process joins all the auxiliary groups that the given uid is a member
    of.

Comment 6 Eric Blake 2011-01-05 17:21:05 UTC
And one other related patch also made it into 0.8.7:

commit c685993d71c1cf561af2cf34a5077781566aa0e0
Author: Eric Blake <eblake>
Date:   Mon Jan 3 15:26:33 2011 -0700

    build: avoid compilation warnings
    
    Detected on cygwin:
    util/util.c: In function 'virSetUIDGID':
    util/util.c:2824: warning: format '%d' expects type 'int', but argument 7 has type 'gid_t' [-Wformat]s)
    
    * src/util/util.c (virSetUIDGID): Cast, as is done elsewhere in
    this file, to avoid printf type mismatch warnings.

Comment 7 Jiri Denemark 2011-01-09 23:58:17 UTC
Built into libvirt-0.8.7-1.el6

Comment 10 Gunannan Ren 2011-01-11 09:50:58 UTC
The bug has been tested in libvirt-0.8.7-1.el6.

1, setup a NFS server with exports configuration as follows
/tmp/nfstest  *(rw,root_squash)

2, copy a guest image file into the shared fold. Using chmod to set the ownership and groupship of the image file to (otheruser):kvm, the other user shouldn't be qemu.
# chown 500:36 rhel6.img 

3, In the client server, mount the NFS shared folder, then, try to boot up a guest which use the image file as its OS disk.

For the libvirt-0.8.7-1.el6, the guest started successfully, but libvirt-0.8.6-1.el6 failed.

Comment 12 Vivian Bian 2011-02-16 07:19:10 UTC
retested this bug with 
libvirt-0.8.7-6.el6.x86_64  --- verification pkg
libvirt-0.8.1-27.el6.x86_64 --- reproducer pkg

steps:

1, setup a NFS server with exports configuration as follows
/tmp/nfstest  *(rw,root_squash)

2, copy a guest image file into the shared fold. Using chmod+chown to set the access right ,ownership and groupship of the image file to (otheruser):kvm, the other user
shouldn't be qemu.

# chown 500:36 rhel6.img 
# chmod 755 rhel6.img

3, In the client machine, mount the NFS shared folder, then, try to boot up a
guest which use the image file as its OS disk.


[reproducer]
error: Failed to start domain test1
error: internal error Process exited while reading console log output: char device redirected to /dev/pts/3
qemu: could not open disk image /var/lib/libvirt/migration/rhel6.img: Permission denied


[verification]

# virsh start test1
Domain test1 started

# ll /var/lib/libvirt/migration/rhel6.img
-rwxrwxrwx. 1 xguest kvm 8589934592 Feb 16 07:09 /var/lib/libvirt/migration/rhel6.img

the ownership wasn't changed by qemu , and it kept kvm group . 

So set bug status to VERIFIED

Comment 15 errata-xmlrpc 2011-05-19 13:25:06 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0596.html