Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 751725 - virsh detach-device does not change owner and selinux label of USB device if device managed
virsh detach-device does not change owner and selinux label of USB device if ...
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
6.2
All Linux
urgent Severity urgent
: rc
: ---
Assigned To: Michal Privoznik
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2011-11-07 06:08 EST by Miroslav Vadkerti
Modified: 2012-06-20 02:36 EDT (History)
10 users (show)

See Also:
Fixed In Version: libvirt-0.9.9-1.el6
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-06-20 02:36:17 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2012:0748 normal SHIPPED_LIVE Low: libvirt security, bug fix, and enhancement update 2012-06-19 15:31:38 EDT

  None (edit)
Description Miroslav Vadkerti 2011-11-07 06:08:29 EST
Description of problem:
After virsh detach-device the owner and selinux label of USB device is not transitioned back to the host system if the device has managed=yes set. I'm attaching the reproducer.

# ./virsh-detach-usb 
+ Printing usb device details before test
crw-rw-r--. root root system_u:object_r:usb_device_t:SystemLow /dev/bus/usb/003/002
+ Creating image for guest
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00320035 s, 328 MB/s
+ Creating VM xml with given usb device
+ Starting VM
Domain guest1-dynamic created from guest1.xml

+ Printing usb device details
crw-rw-r--. qemu qemu system_u:object_r:svirt_image_t:s0:c273,c627 /dev/bus/usb/003/002
+ Detaching USB device
Device detached successfully

+ Stopping VM
Domain guest1-dynamic destroyed

+ Printing usb device details after detach and destroy
crw-rw-r--. qemu qemu system_u:object_r:svirt_image_t:s0:c273,c627 /dev/bus/usb/003/002
+ Cleanup

Version-Release number of selected component (if applicable):


How reproducible:
100%

Steps to Reproduce:
1. use the attached reproducer
  
Actual results:
usb device has owner/selinux label set to virtual machine

Expected results:
usb device has owner/selinux label set to host machine

Additional info:
Please note that if I do only virsh-destroy the device is transtitioned back
Comment 2 Osier Yang 2011-11-08 22:18:32 EST
This might be DUPLICATE with https://bugzilla.redhat.com/show_bug.cgi?id=730930, as "managed" is just meaningless for USB device currently, it's supported in XML,
but no codes for it actually.
Comment 4 Alex Jia 2011-11-11 04:22:22 EST
There are 2 issues in here:
1. As Osier said, need "managed" mode support for host usb device,
otherwise, can't return this USB to host with managed='yes' after 
shutting down guest.

2. The other is libvirt need to do some clean up work and should 
make sure the detached USB device with original permission and 
selinux context if libvirt has ever modified them.

Of course, also merge the above 2 into 1 as a RFE such as bug 730930.
Comment 5 Michal Privoznik 2011-12-16 10:22:05 EST
commit 13d5a6b83d5252ce323889022e142e797a96d89c
Author:     Michal Privoznik <mprivozn@redhat.com>
AuthorDate: Thu Dec 15 17:51:56 2011 +0100
Commit:     Michal Privoznik <mprivozn@redhat.com>
CommitDate: Fri Dec 16 11:53:03 2011 +0100

    qemu: Don't drop hostdev config until security label restore
    
    Currently, on device detach, we parse given XML, find the device
    in domain object, free it and try to restore security labels.
    However, in some cases (e.g. usb hostdev) parsed XML contains
    less information than freed device. In usb case it is bus & device
    IDs. These are needed during label restoring as a symlink into
    /dev/bus is generated from them. Therefore don't drop device
    configuration until security labels are restored.

v0.9.8-56-g13d5a6b
Comment 7 weizhang 2012-01-10 03:17:53 EST
verify pass on
libvirt-0.9.9-1.el6.x86_64
kernel-2.6.32-225.el6.x86_64
qemu-kvm-0.12.1.2-2.213.el6.x86_64


#ls -Z /dev/bus/usb/002/003
crw-rw-r--. root root system_u:object_r:usb_device_t:s0 /dev/bus/usb/002/003

# virsh attach-device kvm-rhel6u2-x86_64-new usb.xml 
Device attached successfully

# ls -Z /dev/bus/usb/002/003
crw-rw-r--. qemu qemu system_u:object_r:svirt_image_t:s0:c98,c194 /dev/bus/usb/002/003

# virsh detach-device kvm-rhel6u2-x86_64-new usb.xml
Device detached successfully

# virsh destroy kvm-rhel6u2-x86_64-new
Domain kvm-rhel6u2-x86_64-new destroyed

# ls -Z /dev/bus/usb/002/003
crw-rw-r--. root root system_u:object_r:usb_device_t:s0 /dev/bus/usb/002/003
Comment 9 errata-xmlrpc 2012-06-20 02:36:17 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2012-0748.html

Note You need to log in before you can comment on or make changes to this bug.