Bug 1266078 - Audit log entries for hot(un)plugged memory devices are sometimes incorrect
Audit log entries for hot(un)plugged memory devices are sometimes incorrect
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.2
x86_64 Linux
low Severity low
: rc
: ---
Assigned To: Peter Krempa
Virtualization Bugs
:
Depends On: 1226234
Blocks:
  Show dependency treegraph
 
Reported: 2015-09-24 08:27 EDT by Peter Krempa
Modified: 2016-11-03 14:25 EDT (History)
6 users (show)

See Also:
Fixed In Version: libvirt-1.3.1-1.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1226234
Environment:
Last Closed: 2016-11-03 14:25:15 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Peter Krempa 2015-09-24 08:27:33 EDT
+++ This bug was initially created as a clone of Bug #1226234 +++

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:

--- Additional comment from Peter Krempa on 2015-07-01 10:25:42 CEST ---

Fixed upstream:

commit 91081979dd3e33f2e39e3de234e52d0e69ffcccb
Author: Peter Krempa <pkrempa@redhat.com>
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@redhat.com>
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

--- Additional comment from Luyao Huang on 2015-07-17 10:51:58 CEST ---

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.

--- Additional comment from Luyao Huang on 2015-09-08 11:48:40 CEST ---

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@redhat.com>
Date:   Thu Aug 13 22:15:28 2015 +0800

    qemu: Emit correct audit message for memory hot unplug

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

    qemu: Emit correct audit message for memory hot plug
Comment 1 Peter Krempa 2015-09-24 08:28:23 EDT
$ git desc 8f8031df1998725ac34a9a3138705c4f7cdf0488
v1.2.19-rc1
Comment 3 Luyao Huang 2016-06-01 05:05:03 EDT
Verify this bug with libvirt-1.3.4-1.el7.x86_64:

1. test hot-plug success:

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 57    rhel72-test                    running

# cat memdevice1G.xml
    <memory model='dimm'>
      <target>
        <size unit='G'>1</size>
        <node>0</node>
      </target>
    </memory>

# virsh dominfo rhel72-test
Id:             57
Name:           rhel72-test
UUID:           855670a9-34e6-4da2-a1ec-1993de100d79
OS Type:        hvm
State:          running
CPU(s):         10
CPU time:       61.0s
Max memory:     4194304 KiB
Used memory:    2145728 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c735,c1014 (permissive)


# virsh attach-device rhel72-test memdevice1G.xml 
Device attached successfully

# virsh dominfo rhel72-test
Id:             57
Name:           rhel72-test
UUID:           855670a9-34e6-4da2-a1ec-1993de100d79
OS Type:        hvm
State:          running
CPU(s):         10
CPU time:       73.3s
Max memory:     5242880 KiB
Used memory:    3194304 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c735,c1014 (permissive)


# ausearch -ts recent -m VIRT_RESOURCE | grep 'mem'
type=VIRT_RESOURCE msg=audit(1464770792.893:26047): pid=8698 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=kvm resrc=mem reason=start vm="rhel72-test" uuid=855670a9-34e6-4da2-a1ec-1993de100d79 old-mem=0 new-mem=4194304 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'
type=VIRT_RESOURCE msg=audit(1464770836.216:26050): pid=8698 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="rhel72-test" uuid=855670a9-34e6-4da2-a1ec-1993de100d79 old-mem=4194304 new-mem=5242880 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'

2. test hot-plug fail:

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 57    rhel72-test                    running

# cat memdevice0.xml
    <memory model='dimm'>
      <target>
        <size unit='G'>0</size>
        <node>0</node>
      </target>
    </memory>


# virsh attach-device rhel72-test memdevice0.xml
error: Failed to attach device from memdevice0.xml
error: internal error: unable to execute QEMU command 'object-add': Property 'memory-backend-ram.size' doesn't take value '0'

# ausearch -ts recent -m VIRT_RESOURCE | grep 'mem'
...
type=VIRT_RESOURCE msg=audit(1464771123.151:26051): pid=8698 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="rhel72-test" uuid=855670a9-34e6-4da2-a1ec-1993de100d79 old-mem=5242880 new-mem=5242880 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=failed'

3. test hot-unplug success:


# virsh list --all
 Id    Name                           State
----------------------------------------------------
 57    rhel72-test                    running

# cat memdevice3.xml
    <memory model='dimm'>
      <target>
        <size unit='KiB'>131072</size>
        <node>0</node>
      </target>
    </memory>

# virsh attach-device rhel72-test memdevice3.xml 
Device attached successfully

# virsh detach-device rhel72-test memdevice3.xml 
Device detached successfully

# ausearch -ts recent -m VIRT_RESOURCE | grep 'mem'
...
type=VIRT_RESOURCE msg=audit(1464771788.700:26089): pid=8698 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="rhel72-test" uuid=855670a9-34e6-4da2-a1ec-1993de100d79 old-mem=5242880 new-mem=5373952 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'
type=VIRT_RESOURCE msg=audit(1464771802.020:26090): pid=8698 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="rhel72-test" uuid=855670a9-34e6-4da2-a1ec-1993de100d79 old-mem=5373952 new-mem=5242880 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'
Comment 5 errata-xmlrpc 2016-11-03 14:25:15 EDT
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/RHSA-2016-2577.html

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