Bug 641854 - Fail to change media on the fly when host is in enforcing mode.
Summary: Fail to change media on the fly when host is in enforcing mode.
Keywords:
Status: CLOSED DUPLICATE of bug 586173
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: libvirt
Version: 5.6
Hardware: All
OS: Linux
low
medium
Target Milestone: rc
: ---
Assignee: Daniel Veillard
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-10-11 10:11 UTC by Johnny Liu
Modified: 2011-07-19 09:02 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Previously, when a CD image with a read-only flag set was ejected from a drive on a guest, the read-only flag was preserved. Consequently, the image could not be re-attached to the drive. A patch has been provided to address this issue, and the read-write flag is now set correctly when an image is ejected from a drive, allowing CD images to be changed on-the-fly.
Clone Of:
Environment:
Last Closed: 2010-10-22 13:11:58 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Johnny Liu 2010-10-11 10:11:02 UTC
Description of problem:
When host is in enforcing mode, try to attach a disk to guest, failed to attach with the following error:
# virsh attach-disk rhel5u5 /var/lib/libvirt/images/temp2.iso hdc --driver qemu --subdriver raw --type cdrom --mode readonly --sourcetype file
error: Failed to attach disk
error: operation failed: could not change media on ide1-cd0: Could not open '/var/lib/libvirt/images/temp2.iso'

Version-Release number of selected component (if applicable):
kvm-83-200.el5
kmod-kvm-83-200.el5
kernel-2.6.18-225.el5
libvirt-0.8.2-6.el5
selinux-policy-targeted-2.4.6-285.el5
selinux-policy-2.4.6-285.el5


How reproducible:
Always

Steps to Reproduce:
1. Start a guest which has a cdrom device.
2. Make a new ISO file.
# mkisofs -o /var/lib/libvirt/images/temp2.iso /tmp
3. Try to change the media on the fly in enforcing mode.
# getenforce 
Enforcing
# virsh attach-disk rhel5u5 /var/lib/libvirt/images/temp2.iso hdc --driver qemu --subdriver raw --type cdrom --mode readonly --sourcetype file
  
Actual results:
Fail to change the media on the fly in enforcing mode.
# virsh attach-disk rhel5u5 /var/lib/libvirt/images/temp2.iso hdc --driver qemu --subdriver raw --type cdrom --mode readonly --sourcetype file
error: Failed to attach disk
error: operation failed: could not change media on ide1-cd0: Could not open '/var/lib/libvirt/images/temp2.iso'

In permissive mode, the above virsh command works fine.
# setenforce 0
# getenforce 
Permissive
# virsh attach-disk rhel5u5 /var/lib/libvirt/images/temp2.iso hdc --driver qemu --subdriver raw --type cdrom --mode readonly --sourcetype file
Disk attached successfully

There is no any selinux log in /var/log/audit/audit.log.

Expected results:
In enforcing mode, virsh command should work fine.

Additional info:

Comment 1 Jiri Denemark 2010-10-14 10:09:02 UTC
It works in permissive mode and doesn't work in enforcing mode so it has to be selinux issue and you should see something about it in /var/log/audit/audit.log or even /var/log/messages. Could you check that once more?

Also, could you check how it worked on 5.5, i.e. with 0.6.3-based libvirt?

Comment 2 Johnny Liu 2010-10-15 06:40:31 UTC
(In reply to comment #1)
> It works in permissive mode and doesn't work in enforcing mode so it has to be
> selinux issue and you should see something about it in /var/log/audit/audit.log
> or even /var/log/messages. Could you check that once more?

There is no any selinux log in /var/log/audit/audit.log and /var/log/messages. Only the following line is seen in /var/log/messages:
....
Oct 15 00:40:25 localhost libvirtd: 00:40:25.295: error : qemuMonitorTextChangeMedia:924 : operation failed: could not change media on ide1-cd0: Could not open '/var/lib/libvirt/images/temp2.iso'


> Also, could you check how it worked on 5.5, i.e. with 0.6.3-based libvirt?
Yes, I tested it on rhel5u5 with libvirt-0.6.3-37.el5, it works fine.

Comment 3 Jiri Denemark 2010-10-22 11:15:37 UTC
OK, I had to turn off dontaudit rules (using semodule -DB) to see what's going on:

avc:  denied  { write } for  pid=5889 comm="qemu-kvm" name="cdrom.iso" dev=dm-1 ino=16793604 scontext=system_u:system_r:svirt_t:s0:c633,c980 tcontext=system_u:object_r:virt_content_t:s0 tclass=file

Comment 4 Jiri Denemark 2010-10-22 11:28:12 UTC
*** Bug 644763 has been marked as a duplicate of this bug. ***

Comment 5 Jiri Denemark 2010-10-22 13:10:45 UTC
qemu is trying to open the cdrom image in read-write mode even though it was supposed to open it as read-only. This is actually a dub of qemu bug 586173.

Comment 6 Jiri Denemark 2010-10-22 13:11:58 UTC

*** This bug has been marked as a duplicate of bug 586173 ***

Comment 7 Tomas Capek 2011-07-19 09:02:56 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Previously, when a CD image with a read-only flag set was ejected from a drive on a guest, the read-only flag was preserved. Consequently, the image could not be re-attached to the drive. A patch has been provided to address this issue, and the read-write flag is now set correctly when an image is ejected from a drive, allowing CD images to be changed on-the-fly.


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