Bug 1941464

Summary: SELinux is preventing /usr/sbin/virtlockd from create access on the directory lockd
Product: Red Hat Enterprise Linux 8 Reporter: yafu <yafu>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.4CC: lvrabec, mmalik, nknazeko, plautrba, ssekidde, zpytela
Target Milestone: rcKeywords: AutoVerified, Triaged
Target Release: 8.5   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.14.3-68.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 1974875 (view as bug list) Environment:
Last Closed: 2021-11-09 19:42:58 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: 1974875    

Description yafu 2021-03-22 08:16:32 UTC
Description of problem:
SELinux is preventing /usr/sbin/virtlockd from create access on the directory lockd

Version-Release number of selected component (if applicable):
selinux-policy-3.14.3-67.el8.noarch
libvirt-daemon-7.0.0-10.module+el8.4.0+10417+37f6984d.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Set qemu.conf:
lock_manager = "lockd"

2.Set qemu-lockd.conf
file_lockspace_dir = "/var/lib/libvirt/lockd/files"

3.Restart libvirtd service
#systemctl restart libvirtd

4.Connect to libvirtd:
#virsh list
error: failed to connect to the hypervisor
error: Cannot recv data: Connection reset by peer

5.Check the audit log:
#ausearch -m avc
type=PROCTITLE msg=audit(1616400460.250:5235): proctitle="/usr/sbin/virtlockd"
type=SYSCALL msg=audit(1616400460.250:5235): arch=c000003e syscall=83 success=no exit=-13 a0=5596e327c930 a1=1c0 a2=7ffda5151600 a3=0 items=0 ppid=1 pid=123826 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="virtlockd" exe="/usr/sbin/virtlockd" subj=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1616400460.250:5235): avc:  denied  { create } for  pid=123826 comm="virtlockd" name="lockd" scontext=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:virt_var_lib_t:s0 tclass=dir permissive=0

Actual results:
SELinux is preventing /usr/sbin/virtlockd from create access on the directory lockd

Expected results:


Additional info:

Comment 1 Zdenek Pytela 2021-03-22 08:42:08 UTC
Nikola,

Can you assess if this permission request is expected, given the current state of the libvirt policy in RHEL 8?

Comment 2 Nikola Knazekova 2021-04-27 12:52:24 UTC
Hi Zdenko

the new libvirt policy for new virt drivers is not developed for RHEL8.

In the libvirt policy for RHEL8 and also in new libvirt policy, filecontext for /var/lib/libvirt/lockd should be virt_var_lockd_t, instead of virt_var_lib_t.

Comment 3 Zdenek Pytela 2021-04-27 19:58:29 UTC
Merged in rawhide:
commit f83261b20273c167520949c5a9e8b38ac9a18f93 (HEAD -> rawhide, upstream/rawhide)
Author: Nikola Knazekova <nknazeko>
Date:   Tue Apr 27 15:04:44 2021 +0200

    Allow virtlogd_t to create virt_var_lockd_t dir

    Allow virtlogd_t to create dir named "lockd"
    with label virt_var_lockd_t in parent directory
    labeled as virt_var_lib_t.

    Make the virt_var_lockd_t type usable for files
    in a filesystem.

    Fixed BZ1941464.

    Tested on RHEL8.4.

    Signed-off-by: Nikola Knazekova <nknazeko>

Comment 10 Milos Malik 2021-05-20 16:19:57 UTC
When old selinux-policy is installed, the following SELinux denial appears in enforcing mode:
----
type=PROCTITLE msg=audit(05/20/2021 12:15:04.945:439) : proctitle=/usr/sbin/virtlockd 
type=PATH msg=audit(05/20/2021 12:15:04.945:439) : item=1 name=/var/lib/libvirt/lockd nametype=CREATE cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=PATH msg=audit(05/20/2021 12:15:04.945:439) : item=0 name=/var/lib/libvirt/ inode=529464 dev=fd:01 mode=dir,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:virt_var_lib_t:s0 nametype=PARENT cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(05/20/2021 12:15:04.945:439) : cwd=/ 
type=SYSCALL msg=audit(05/20/2021 12:15:04.945:439) : arch=x86_64 syscall=mkdir success=no exit=EACCES(Permission denied) a0=0x56307fcdec00 a1=0700 a2=0x7ffed3f76950 a3=0x7f59ccce78ff items=2 ppid=1 pid=6654 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=virtlockd exe=/usr/sbin/virtlockd subj=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 key=(null) 
type=AVC msg=audit(05/20/2021 12:15:04.945:439) : avc:  denied  { create } for  pid=6654 comm=virtlockd name=lockd scontext=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:virt_var_lib_t:s0 tclass=dir permissive=0 
----

When old selinux-policy is installed, the following SELinux denial appears in permissive mode:
----
type=PROCTITLE msg=audit(05/20/2021 12:16:59.367:444) : proctitle=/usr/sbin/virtlockd 
type=PATH msg=audit(05/20/2021 12:16:59.367:444) : item=1 name=/var/lib/libvirt/lockd inode=18874568 dev=fd:01 mode=dir,700 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:virt_var_lib_t:s0 nametype=CREATE cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=PATH msg=audit(05/20/2021 12:16:59.367:444) : item=0 name=/var/lib/libvirt/ inode=529464 dev=fd:01 mode=dir,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:virt_var_lib_t:s0 nametype=PARENT cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(05/20/2021 12:16:59.367:444) : cwd=/ 
type=SYSCALL msg=audit(05/20/2021 12:16:59.367:444) : arch=x86_64 syscall=mkdir success=yes exit=0 a0=0x56307fce2590 a1=0700 a2=0x7ffed3f76950 a3=0x7f59ccce78ff items=2 ppid=1 pid=6654 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=virtlockd exe=/usr/sbin/virtlockd subj=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 key=(null) 
type=AVC msg=audit(05/20/2021 12:16:59.367:444) : avc:  denied  { create } for  pid=6654 comm=virtlockd name=lockd scontext=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:virt_var_lib_t:s0 tclass=dir permissive=1 
----

Comment 17 Zdenek Pytela 2021-06-11 10:06:30 UTC
Hi,

Can you please check if the scenario in #c0 is applicable to RHEL 9, too?

Comment 18 yafu 2021-06-16 00:34:20 UTC
(In reply to Zdenek Pytela from comment #17)
> Hi,
> 
> Can you please check if the scenario in #c0 is applicable to RHEL 9, too?

Hi Zdenek,

I tested comment #0 with selinux-policy-34.1.8-1.el9.noarch, the avc deny is different with comment #0:
# ausearch -m avc | grep -i virtlockd
type=AVC msg=audit(1623802355.506:1681): avc:  denied  { read append } for  pid=187608 comm="virtlockd" name="system.token" dev="tmpfs" ino=2505 scontext=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:virt_var_run_t:s0 tclass=file permissive=0

And it seems the same issue with https://bugzilla.redhat.com/show_bug.cgi?id=1966842.

Comment 19 Zdenek Pytela 2021-06-16 07:24:18 UTC
(In reply to yafu from comment #18)
> (In reply to Zdenek Pytela from comment #17)
> > Hi,
> > 
> > Can you please check if the scenario in #c0 is applicable to RHEL 9, too?
> 
> Hi Zdenek,
> 
> I tested comment #0 with selinux-policy-34.1.8-1.el9.noarch, the avc deny is
> different with comment #0:
> # ausearch -m avc | grep -i virtlockd
> type=AVC msg=audit(1623802355.506:1681): avc:  denied  { read append } for 
> pid=187608 comm="virtlockd" name="system.token" dev="tmpfs" ino=2505
> scontext=system_u:system_r:virtlogd_t:s0-s0:c0.c1023
> tcontext=system_u:object_r:virt_var_run_t:s0 tclass=file permissive=0
> 
> And it seems the same issue with
> https://bugzilla.redhat.com/show_bug.cgi?id=1966842.
Hi,

This issue will be addressed in the RHEL 9 clone bz#1969209, so we probably need to retest the #c0 scenario when the new build is available.

Comment 21 errata-xmlrpc 2021-11-09 19:42:58 UTC
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 (selinux-policy bug fix and enhancement update), and where to find the updated
files, follow the link below.

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

https://access.redhat.com/errata/RHBA-2021:4420