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:
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?
(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.
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
*** Bug 644763 has been marked as a duplicate of this bug. ***
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.
*** This bug has been marked as a duplicate of bug 586173 ***
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.