2010-12-16 16:10:54 +00:00
|
|
|
/*
|
|
|
|
* qemu_audit.c: QEMU audit management
|
|
|
|
*
|
2011-02-16 02:35:43 +00:00
|
|
|
* Copyright (C) 2006-2011 Red Hat, Inc.
|
2010-12-16 16:10:54 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2011-03-07 23:17:26 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2010-12-16 16:10:54 +00:00
|
|
|
#include "qemu_audit.h"
|
|
|
|
#include "virtaudit.h"
|
|
|
|
#include "uuid.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "memory.h"
|
2011-07-04 02:23:46 +00:00
|
|
|
#include "ignore-value.h"
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2011-03-07 23:17:26 +00:00
|
|
|
/* Return nn:mm in hex for block and character devices, and NULL
|
|
|
|
* for other file types, stat failure, or allocation failure. */
|
|
|
|
#if defined major && defined minor
|
|
|
|
static char *
|
|
|
|
qemuAuditGetRdev(const char *path)
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
if (stat(path, &sb) == 0 &&
|
|
|
|
(S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode))) {
|
|
|
|
int maj = major(sb.st_rdev);
|
|
|
|
int min = minor(sb.st_rdev);
|
|
|
|
virAsprintf(&ret, "%02X:%02X", maj, min);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static char *
|
|
|
|
qemuAuditGetRdev(const char *path ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
|
|
|
qemuAuditDisk(virDomainObjPtr vm,
|
|
|
|
virDomainDiskDefPtr oldDef, virDomainDiskDefPtr newDef,
|
|
|
|
const char *reason, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
char *oldsrc = NULL;
|
|
|
|
char *newsrc = NULL;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(oldsrc = virAuditEncode("old-disk",
|
|
|
|
oldDef && oldDef->src ?
|
|
|
|
oldDef->src : "?"))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2010-12-16 16:10:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (!(newsrc = virAuditEncode("new-disk",
|
|
|
|
newDef && newDef->src ?
|
|
|
|
newDef->src : "?"))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2010-12-16 16:10:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"resrc=disk reason=%s %s uuid=%s %s %s",
|
|
|
|
reason, vmname, uuidstr,
|
|
|
|
oldsrc, newsrc);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
VIR_FREE(oldsrc);
|
|
|
|
VIR_FREE(newsrc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
|
|
|
qemuAuditNet(virDomainObjPtr vm,
|
|
|
|
virDomainNetDefPtr oldDef, virDomainNetDefPtr newDef,
|
|
|
|
const char *reason, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char newMacstr[VIR_MAC_STRING_BUFLEN];
|
|
|
|
char oldMacstr[VIR_MAC_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (oldDef)
|
|
|
|
virFormatMacAddr(oldDef->mac, oldMacstr);
|
|
|
|
if (newDef)
|
|
|
|
virFormatMacAddr(newDef->mac, newMacstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"resrc=net reason=%s %s uuid=%s old-net='%s' new-net='%s'",
|
|
|
|
reason, vmname, uuidstr,
|
|
|
|
oldDef ? oldMacstr : "?",
|
|
|
|
newDef ? newMacstr : "?");
|
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|
|
|
|
|
audit: audit use of /dev/net/tun, /dev/tapN, /dev/vhost-net
Opening raw network devices with the intent of passing those fds to
qemu is worth an audit point. This makes a multi-part audit: first,
we audit the device(s) that libvirt opens on behalf of the MAC address
of a to-be-created interface (which can independently succeed or
fail), then we audit whether qemu actually started the network device
with the same MAC (so searching backwards for successful audits with
the same MAC will show which fd(s) qemu is actually using). Note that
it is possible for the fd to be successfully opened but no attempt
made to pass the fd to qemu (for example, because intermediate
nwfilter operations failed) - no interface start audit will occur in
that case; so the audit for a successful opened fd does not imply
rights given to qemu unless there is a followup audit about the
attempt to start a new interface.
Likewise, when a network device is hot-unplugged, there is only one
audit message about the MAC being discontinued; again, searching back
to the earlier device open audits will show which fds that qemu quits
using (and yes, I checked via /proc/<qemu-pid>/fd that qemu _does_
close out the fds associated with an interface on hot-unplug). The
code would require much more refactoring to be able to definitively
state which device(s) were discontinued at that point, since we
currently don't record anywhere in the XML whether /dev/vhost-net was
opened for a given interface.
* src/qemu/qemu_audit.h (qemuAuditNetDevice): New prototype.
* src/qemu/qemu_audit.c (qemuAuditNetDevice): New function.
* src/qemu/qemu_command.h (qemuNetworkIfaceConnect)
(qemuPhysIfaceConnect, qemuOpenVhostNet): Adjust prototype.
* src/qemu/qemu_command.c (qemuNetworkIfaceConnect)
(qemuPhysIfaceConnect, qemuOpenVhostNet): Add audit points and
adjust parameters.
(qemuBuildCommandLine): Adjust caller.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
2011-03-08 18:00:59 +00:00
|
|
|
/**
|
|
|
|
* qemuAuditNetDevice:
|
|
|
|
* @vm: domain opening a network-related device
|
|
|
|
* @def: details of network device that fd will be tied to
|
|
|
|
* @device: device being opened (such as /dev/vhost-net,
|
|
|
|
* /dev/net/tun, /dev/tanN). Note that merely opening a device
|
|
|
|
* does not mean that qemu owns it; a followup qemuAuditNet
|
|
|
|
* shows whether the fd was passed on.
|
|
|
|
* @success: true if the device was opened
|
|
|
|
*
|
|
|
|
* Log an audit message about an attempted network device open.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
qemuAuditNetDevice(virDomainDefPtr vmDef, virDomainNetDefPtr netDef,
|
|
|
|
const char *device, bool success)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char macstr[VIR_MAC_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
char *devname;
|
|
|
|
char *rdev;
|
|
|
|
|
|
|
|
virUUIDFormat(vmDef->uuid, uuidstr);
|
|
|
|
virFormatMacAddr(netDef->mac, macstr);
|
|
|
|
rdev = qemuAuditGetRdev(device);
|
|
|
|
|
|
|
|
if (!(vmname = virAuditEncode("vm", vmDef->name)) ||
|
|
|
|
!(devname = virAuditEncode("path", device))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
audit: audit use of /dev/net/tun, /dev/tapN, /dev/vhost-net
Opening raw network devices with the intent of passing those fds to
qemu is worth an audit point. This makes a multi-part audit: first,
we audit the device(s) that libvirt opens on behalf of the MAC address
of a to-be-created interface (which can independently succeed or
fail), then we audit whether qemu actually started the network device
with the same MAC (so searching backwards for successful audits with
the same MAC will show which fd(s) qemu is actually using). Note that
it is possible for the fd to be successfully opened but no attempt
made to pass the fd to qemu (for example, because intermediate
nwfilter operations failed) - no interface start audit will occur in
that case; so the audit for a successful opened fd does not imply
rights given to qemu unless there is a followup audit about the
attempt to start a new interface.
Likewise, when a network device is hot-unplugged, there is only one
audit message about the MAC being discontinued; again, searching back
to the earlier device open audits will show which fds that qemu quits
using (and yes, I checked via /proc/<qemu-pid>/fd that qemu _does_
close out the fds associated with an interface on hot-unplug). The
code would require much more refactoring to be able to definitively
state which device(s) were discontinued at that point, since we
currently don't record anywhere in the XML whether /dev/vhost-net was
opened for a given interface.
* src/qemu/qemu_audit.h (qemuAuditNetDevice): New prototype.
* src/qemu/qemu_audit.c (qemuAuditNetDevice): New function.
* src/qemu/qemu_command.h (qemuNetworkIfaceConnect)
(qemuPhysIfaceConnect, qemuOpenVhostNet): Adjust prototype.
* src/qemu/qemu_command.c (qemuNetworkIfaceConnect)
(qemuPhysIfaceConnect, qemuOpenVhostNet): Add audit points and
adjust parameters.
(qemuBuildCommandLine): Adjust caller.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
2011-03-08 18:00:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"resrc=net reason=open %s uuid=%s net='%s' %s rdev=%s",
|
|
|
|
vmname, uuidstr, macstr, devname, VIR_AUDIT_STR(rdev));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
VIR_FREE(devname);
|
|
|
|
VIR_FREE(rdev);
|
|
|
|
}
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2011-02-23 23:15:23 +00:00
|
|
|
/**
|
2011-03-08 21:28:51 +00:00
|
|
|
* qemuAuditHostdev:
|
2011-02-23 23:15:23 +00:00
|
|
|
* @vm: domain making a change in pass-through host device
|
|
|
|
* @hostdev: device being attached or removed
|
2011-03-07 23:17:26 +00:00
|
|
|
* @reason: one of "start", "attach", or "detach"
|
2011-02-23 23:15:23 +00:00
|
|
|
* @success: true if the device passthrough operation succeeded
|
|
|
|
*
|
|
|
|
* Log an audit message about an attempted device passthrough change.
|
|
|
|
*/
|
|
|
|
void
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
|
|
|
|
const char *reason, bool success)
|
2011-02-23 23:15:23 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
char *address;
|
|
|
|
char *device;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-02-23 23:15:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (hostdev->source.subsys.type) {
|
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
|
|
|
if (virAsprintf(&address, "%.4x:%.2x:%.2x.%.1x",
|
|
|
|
hostdev->source.subsys.u.pci.domain,
|
|
|
|
hostdev->source.subsys.u.pci.bus,
|
|
|
|
hostdev->source.subsys.u.pci.slot,
|
|
|
|
hostdev->source.subsys.u.pci.function) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-02-23 23:15:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
|
|
|
|
if (virAsprintf(&address, "%.3d.%.3d",
|
|
|
|
hostdev->source.subsys.u.usb.bus,
|
|
|
|
hostdev->source.subsys.u.usb.device) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-02-23 23:15:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
VIR_WARN("Unexpected hostdev type while encoding audit message: %d",
|
|
|
|
hostdev->source.subsys.type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(address)))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-02-23 23:15:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
2011-02-26 00:28:21 +00:00
|
|
|
"resrc=dev reason=%s %s uuid=%s bus=%s %s",
|
2011-02-23 23:15:23 +00:00
|
|
|
reason, vmname, uuidstr,
|
|
|
|
virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type),
|
|
|
|
device);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
VIR_FREE(device);
|
|
|
|
VIR_FREE(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-16 02:35:43 +00:00
|
|
|
/**
|
2011-03-07 23:17:26 +00:00
|
|
|
* qemuAuditCgroup:
|
2011-02-16 02:35:43 +00:00
|
|
|
* @vm: domain making the cgroups ACL change
|
|
|
|
* @cgroup: cgroup that manages the devices
|
|
|
|
* @reason: either "allow" or "deny"
|
2011-03-07 23:17:26 +00:00
|
|
|
* @extra: additional details, in the form "all",
|
|
|
|
* "major category=xyz maj=nn", or "path path=xyz dev=nn:mm" (the
|
|
|
|
* latter two are generated by qemuAuditCgroupMajor and
|
|
|
|
* qemuAuditCgroupPath).
|
2011-02-16 02:35:43 +00:00
|
|
|
* @success: true if the cgroup operation succeeded
|
|
|
|
*
|
|
|
|
* Log an audit message about an attempted cgroup device ACL change.
|
|
|
|
*/
|
2011-03-07 23:17:26 +00:00
|
|
|
void
|
2011-03-07 23:41:40 +00:00
|
|
|
qemuAuditCgroup(virDomainObjPtr vm, virCgroupPtr cgroup,
|
2011-03-07 23:17:26 +00:00
|
|
|
const char *reason, const char *extra, bool success)
|
2011-02-16 02:35:43 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
2011-03-07 23:41:40 +00:00
|
|
|
char *controller = NULL;
|
|
|
|
char *detail;
|
2011-02-16 02:35:43 +00:00
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-02-16 02:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-03-07 23:17:26 +00:00
|
|
|
|
2011-07-04 02:23:46 +00:00
|
|
|
ignore_value(virCgroupPathOfController(cgroup,
|
|
|
|
VIR_CGROUP_CONTROLLER_DEVICES,
|
|
|
|
NULL, &controller));
|
2011-03-07 23:41:40 +00:00
|
|
|
detail = virAuditEncode("cgroup", VIR_AUDIT_STR(controller));
|
|
|
|
|
2011-03-07 23:17:26 +00:00
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
2011-03-07 23:41:40 +00:00
|
|
|
"resrc=cgroup reason=%s %s uuid=%s %s class=%s",
|
|
|
|
reason, vmname, uuidstr,
|
|
|
|
detail ? detail : "cgroup=?", extra);
|
2011-03-07 23:17:26 +00:00
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
2011-03-07 23:41:40 +00:00
|
|
|
VIR_FREE(controller);
|
|
|
|
VIR_FREE(detail);
|
2011-03-07 23:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuAuditCgroupMajor:
|
|
|
|
* @vm: domain making the cgroups ACL change
|
|
|
|
* @cgroup: cgroup that manages the devices
|
|
|
|
* @reason: either "allow" or "deny"
|
|
|
|
* @maj: the major number of the device category
|
|
|
|
* @name: a textual name for that device category, alphabetic only
|
2011-03-09 03:06:26 +00:00
|
|
|
* @perms: string containing "r", "w", and/or "m" as appropriate
|
2011-03-07 23:17:26 +00:00
|
|
|
* @success: true if the cgroup operation succeeded
|
|
|
|
*
|
|
|
|
* Log an audit message about an attempted cgroup device ACL change.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
qemuAuditCgroupMajor(virDomainObjPtr vm, virCgroupPtr cgroup,
|
|
|
|
const char *reason, int maj, const char *name,
|
2011-03-09 03:06:26 +00:00
|
|
|
const char *perms, bool success)
|
2011-03-07 23:17:26 +00:00
|
|
|
{
|
|
|
|
char *extra;
|
|
|
|
|
2011-03-09 03:06:26 +00:00
|
|
|
if (virAsprintf(&extra, "major category=%s maj=%02X acl=%s",
|
|
|
|
name, maj, perms) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-03-07 23:17:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuAuditCgroup(vm, cgroup, reason, extra, success);
|
|
|
|
|
|
|
|
VIR_FREE(extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuAuditCgroupPath:
|
|
|
|
* @vm: domain making the cgroups ACL change
|
|
|
|
* @cgroup: cgroup that manages the devices
|
|
|
|
* @reason: either "allow" or "deny"
|
|
|
|
* @path: the device being adjusted
|
2011-03-09 03:06:26 +00:00
|
|
|
* @perms: string containing "r", "w", and/or "m" as appropriate
|
2011-03-07 23:17:26 +00:00
|
|
|
* @rc: > 0 if not a device, 0 if success, < 0 if failure
|
|
|
|
*
|
|
|
|
* Log an audit message about an attempted cgroup device ACL change to
|
|
|
|
* a specific device.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
qemuAuditCgroupPath(virDomainObjPtr vm, virCgroupPtr cgroup,
|
2011-03-09 03:06:26 +00:00
|
|
|
const char *reason, const char *path, const char *perms,
|
|
|
|
int rc)
|
2011-03-07 23:17:26 +00:00
|
|
|
{
|
|
|
|
char *detail;
|
|
|
|
char *rdev;
|
|
|
|
char *extra;
|
|
|
|
|
|
|
|
/* Nothing to audit for regular files. */
|
|
|
|
if (rc > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rdev = qemuAuditGetRdev(path);
|
|
|
|
|
|
|
|
if (!(detail = virAuditEncode("path", path)) ||
|
2011-03-09 03:06:26 +00:00
|
|
|
virAsprintf(&extra, "path path=%s rdev=%s acl=%s",
|
|
|
|
path, VIR_AUDIT_STR(rdev), perms) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-02-16 02:35:43 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-03-07 23:17:26 +00:00
|
|
|
qemuAuditCgroup(vm, cgroup, reason, extra, rc == 0);
|
2011-02-16 02:35:43 +00:00
|
|
|
|
|
|
|
cleanup:
|
2011-03-07 23:17:26 +00:00
|
|
|
VIR_FREE(extra);
|
2011-02-16 02:35:43 +00:00
|
|
|
VIR_FREE(detail);
|
2011-03-07 23:17:26 +00:00
|
|
|
VIR_FREE(rdev);
|
2011-02-16 02:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 00:02:17 +00:00
|
|
|
/**
|
2011-03-08 21:28:51 +00:00
|
|
|
* qemuAuditResource:
|
2011-02-22 00:02:17 +00:00
|
|
|
* @vm: domain making an integer resource change
|
|
|
|
* @resource: name of the resource: "mem" or "vcpu"
|
|
|
|
* @oldval: the old value of the resource
|
|
|
|
* @newval: the new value of the resource
|
|
|
|
* @reason: either "start" or "update"
|
|
|
|
* @success: true if the resource change succeeded
|
|
|
|
*
|
|
|
|
* Log an audit message about an attempted resource change.
|
|
|
|
*/
|
|
|
|
static void
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditResource(virDomainObjPtr vm, const char *resource,
|
|
|
|
unsigned long long oldval, unsigned long long newval,
|
|
|
|
const char *reason, bool success)
|
2011-02-22 00:02:17 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2011-02-22 00:02:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"resrc=%s reason=%s %s uuid=%s old-%s=%lld new-%s=%lld",
|
|
|
|
resource, reason, vmname, uuidstr,
|
|
|
|
resource, oldval, resource, newval);
|
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditMemory(virDomainObjPtr vm,
|
|
|
|
unsigned long long oldmem, unsigned long long newmem,
|
|
|
|
const char *reason, bool success)
|
2011-02-22 00:02:17 +00:00
|
|
|
{
|
2011-03-08 21:28:51 +00:00
|
|
|
return qemuAuditResource(vm, "mem", oldmem, newmem, reason, success);
|
2011-02-22 00:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditVcpu(virDomainObjPtr vm,
|
|
|
|
unsigned int oldvcpu, unsigned int newvcpu,
|
|
|
|
const char *reason, bool success)
|
2011-02-22 00:02:17 +00:00
|
|
|
{
|
2011-03-08 21:28:51 +00:00
|
|
|
return qemuAuditResource(vm, "vcpu", oldvcpu, newvcpu, reason, success);
|
2011-02-22 00:02:17 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
static void
|
|
|
|
qemuAuditLifecycle(virDomainObjPtr vm, const char *op,
|
|
|
|
const char *reason, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_CONTROL, success,
|
|
|
|
"op=%s reason=%s %s uuid=%s", op, reason, vmname, uuidstr);
|
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
|
|
|
qemuAuditDomainStart(virDomainObjPtr vm, const char *reason, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < vm->def->ndisks ; i++) {
|
|
|
|
virDomainDiskDefPtr disk = vm->def->disks[i];
|
|
|
|
if (disk->src) /* Skips CDROM without media initially inserted */
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditDisk(vm, NULL, disk, "start", true);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < vm->def->nnets ; i++) {
|
|
|
|
virDomainNetDefPtr net = vm->def->nets[i];
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditNet(vm, NULL, net, "start", true);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2011-02-23 23:15:23 +00:00
|
|
|
for (i = 0 ; i < vm->def->nhostdevs ; i++) {
|
|
|
|
virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditHostdev(vm, hostdev, "start", true);
|
2011-02-23 23:15:23 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditMemory(vm, 0, vm->def->mem.cur_balloon, "start", true);
|
|
|
|
qemuAuditVcpu(vm, 0, vm->def->vcpus, "start", true);
|
2011-02-22 00:02:17 +00:00
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditLifecycle(vm, "start", reason, success);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
|
|
|
qemuAuditDomainStop(virDomainObjPtr vm, const char *reason)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
2011-03-08 21:28:51 +00:00
|
|
|
qemuAuditLifecycle(vm, "stop", reason, true);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
|
|
|
qemuAuditSecurityLabel(virDomainObjPtr vm, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_ID, success,
|
|
|
|
"%s uuid=%s vm-ctx=%s img-ctx=%s",
|
|
|
|
vmname, uuidstr,
|
|
|
|
VIR_AUDIT_STR(vm->def->seclabel.label),
|
|
|
|
VIR_AUDIT_STR(vm->def->seclabel.imagelabel));
|
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|