Bug 1685799

Summary: Process with system_u:system_r:svirt_t label cannot read file on cephfs
Product: Red Hat Enterprise Linux 7 Reporter: Han Han <hhan>
Component: selinux-policyAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED DUPLICATE QA Contact: Milos Malik <mmalik>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 7.6CC: bzlotnik, dyuan, ebenahar, fjin, lvrabec, mgrepl, mmalik, mprivozn, plautrba, ssekidde, tnisan, vmojzis, xuzhang, zpytela
Target Milestone: rcKeywords: TestBlocker, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-03-06 12:09:22 UTC Type: Bug
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: 1672178    

Description Han Han 2019-03-06 06:03:49 UTC
Description of problem:
As title

Version-Release number of selected component (if applicable):
qemu-kvm-rhev-2.12.0-19.el7.bz1597621.2.x86_64
libvirt-4.5.0-10.virtcov.el7_6.6.x86_64
selinux-policy-3.13.1-229.el7_6.9.noarch
ceph-common-12.2.8-86.el7cp.x86_64

How reproducible:
100%

Steps to Reproduce:
This bug is found from the vm start based on cephfs(see https://bugzilla.redhat.com/show_bug.cgi?id=1672178#c10)

The steps can simplified as following:

1. Prepare a ceph cluster with cephfs, mount the cephfs on /mnt, create a image on the mounted cephfs.
# mount -t ceph bootp-73-75-128.lab.eng.pek2.redhat.com:/ /mnt -o name=admin,secretfile=ceph.key

# cat ceph.key
AQBRuXNcqcr4MhAA4x2RkdhYozAICV3eLagaSQ==

2. Start a process with srvirt_t type and try to read the file on cephfs
# runcon -u system_u -r system_r -t svirt_t /usr/libexec/qemu-kvm /mnt/cephfs.qcow2 
qemu-kvm: Could not open '/mnt/cephfs.qcow2': Permission denied


Check the audit.log
type=AVC msg=audit(1551851625.686:273): avc:  denied  { read } for  pid=23442 comm="qemu-kvm" name="cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=1
type=AVC msg=audit(1551851625.686:273): avc:  denied  { open } for  pid=23442 comm="qemu-kvm" path="/mnt/cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=1
type=AVC msg=audit(1551851625.686:274): avc:  denied  { getattr } for  pid=23442 comm="qemu-kvm" path="/mnt/cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=1
type=AVC msg=audit(1551851625.686:275): avc:  denied  { write } for  pid=23442 comm="qemu-kvm" name="cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=1
type=AVC msg=audit(1551851625.686:276): avc:  denied  { lock } for  pid=23442 comm="qemu-kvm" path="/mnt/cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=1
type=USER_AVC msg=audit(1551851629.284:278): pid=8692 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc:  received setenforce notice (enforcing=1)  exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?'
type=AVC msg=audit(1551851633.239:279): avc:  denied  { read } for  pid=23489 comm="qemu-kvm" name="cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=0
type=AVC msg=audit(1551851633.239:280): avc:  denied  { getattr } for  pid=23489 comm="qemu-kvm" path="/mnt/cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=0
type=AVC msg=audit(1551851633.239:281): avc:  denied  { read write } for  pid=23489 comm="qemu-kvm" name="cephfs.qcow2" dev="ceph" ino=1099511627776 scontext=system_u:system_r:svirt_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cephfs_t:s0 tclass=file permissive=0


Actual results:
As above

Expected results:
Able to read the file on cephfs.

Additional info:
When selinux is permissive, it works.

When selinux is enforcing and I enabled all virt related selinux boolean, it doesn't works.

Currently, cephfs is not support selinux(see https://tracker.ceph.com/issues/5486):
# ls -alZ /mnt/
drwxr-xr-x  root root ?                                .
dr-xr-xr-x. root root system_u:object_r:root_t:s0      ..
-rw-r--r--  root root ?                                cephfs.qcow2
lrwxrwxrwx  root root ?                                rhev -> /rhev/

The process with system_u:system_r:svirt_t cannot read file on selinux unsupported fs. I am not sure if that is designed. If so, please give the reason. If not, please fix that.

This issue is very important because it will affect the cephfs storage in rhv product.