Bug 1226234

Summary: No audit log when start a vm with memory device/hot-plug a memory device
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: dyuan, honzhang, mzhan, pkrempa, rbalakri, zhwang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.17-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1266078 (view as bug list) Environment:
Last Closed: 2015-11-19 06:39:24 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: 1266078    

Description Luyao Huang 2015-05-29 09:31:22 UTC
Description of problem:
No audit log when start a vm with memory device/hot-plug a memory device

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

libvirt-1.2.15-2.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Make sure auditing is enabled

2.hot-plug a memory device
# cat memdevice.xml 
    <memory model='dimm'>
      <source>
        <pagesize unit='KiB'>4</pagesize>
        <nodemask>0</nodemask>
      </source>
      <target>
        <size unit='m'>512</size>
        <node>0</node>
      </target>
    </memory>

# virsh attach-device rhel7.0 memdevice.xml 
Device attached successfully

3.check the audit log
# ausearch -ts today -m VIRT_RESOURCE | grep 'mem'
(no log for memory deivce)

Actual results:
No audit log when start a vm with memory device/hot-plug a memory device

Expected results:
As host memory is a part of source and i notice libvirt will log the memory change, so i think libvirt should provide auditing of memory device resources

Additional info:

Comment 1 Peter Krempa 2015-07-01 08:25:42 UTC
Fixed upstream:

commit 91081979dd3e33f2e39e3de234e52d0e69ffcccb
Author: Peter Krempa <pkrempa>
Date:   Fri Jun 26 17:14:33 2015 +0200

    qemu: Audit memory size with memory hotplug operations
    
    The memory device hot(un)plug was missing calls to the auditing code.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1226234

commit 1a1367746076f09d22cd1952673bcd4e0dbb6582
Author: Peter Krempa <pkrempa>
Date:   Fri Jun 26 17:12:39 2015 +0200

    conf: audit: Audit physical memory size rather than balloon request
    
    Since the balloon driver does not guarantee that it returns memory to
    the host, using the value in the audit message is not a good idea.
    
    This patch removes auditing from updating the balloon size and reports
    the total physical size at startup.

v1.2.17-rc2-7-g9108197

Comment 3 Luyao Huang 2015-07-17 08:51:58 UTC
Hi peter,

I found the result is not right in libvirt-1.2.17-2.el7.x86_64:


# virsh attach-device r7 memdevice.xml
Device attached successfully

# ausearch -ts today -m VIRT_RESOURCE | grep 'mem'
type=VIRT_RESOURCE msg=audit(1437119640.335:14164): pid=18439 uid=0 auid=0 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='virt=kvm resrc=mem reason=start vm="r7" uuid=9fedda95-4479-44c6-9feb-7ceee69e1669 old-mem=0 new-mem=1024000 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=pts/2 res=success'
type=VIRT_RESOURCE msg=audit(1437119753.401:14169): pid=18439 uid=0 auid=0 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='virt=kvm resrc=mem reason=update vm="r7" uuid=9fedda95-4479-44c6-9feb-7ceee69e1669 old-mem=1024000 new-mem=1548288 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=pts/2 res=failed'

Although hot-plug is success, audit log show it is failed, and if i test a failed case, i cannot get any log:

# virsh attach-device r7 memdevice.xml
error: Failed to attach device from memdevice.xml
error: internal error: unable to execute QEMU command 'device_add': backend memory size must be multiple of 0x200000

# ausearch -ts recent -m VIRT_RESOURCE | grep 'mem'
<no matches>

Would you please help to check out? Thanks a lot for your help.

Comment 4 Luyao Huang 2015-09-08 09:48:40 UTC
Hi peter,

I had sent mail to upstream to have a try to improve it:

https://www.redhat.com/archives/libvir-list/2015-August/msg00581.html

And Upstream commit:

commit 8f8031df1998725ac34a9a3138705c4f7cdf0488
Author: Luyao Huang <lhuang>
Date:   Thu Aug 13 22:15:28 2015 +0800

    qemu: Emit correct audit message for memory hot unplug

commit cb1fbda4a1b23581ed9e305a48b0376633d5ff4a
Author: Luyao Huang <lhuang>
Date:   Thu Aug 13 22:15:27 2015 +0800

    qemu: Emit correct audit message for memory hot plug

Comment 6 Luyao Huang 2015-10-08 09:49:20 UTC
Verify this bug with libvirt-1.2.17-12.el7.x86_64:

1. start a guest which have maxmemory:

# virsh start rhel7.0-rhel
Domain rhel7.0-rhel started

2. attach a memory device:

# virsh attach-device rhel7.0-rhel memdevice.xml
Device attached successfully

3. we can find a audit log:

# ausearch -ts today -m VIRT_RESOURCE | grep 'mem'
...
type=VIRT_RESOURCE msg=audit(1444297630.709:19955): pid=17359 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=kvm resrc=mem reason=update vm="rhel7.0-rhel" uuid=67c7a123-5415-4136-af62-a2ee098ba6cd old-mem=4048896 new-mem=4179968 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=failed'

4. hot-unplug a memdevice:

# virsh detach-device rhel7.0-rhel memdevice.xml
Device detached successfully

5. we can find a audit log:

type=VIRT_RESOURCE msg=audit(1444297632.731:19956): pid=17359 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=kvm resrc=mem reason=update vm="rhel7.0-rhel" uuid=67c7a123-5415-4136-af62-a2ee098ba6cd old-mem=4179968 new-mem=4048896 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'

Comment 8 errata-xmlrpc 2015-11-19 06:39:24 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, 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://rhn.redhat.com/errata/RHBA-2015-2202.html