2010-12-16 16:10:54 +00:00
|
|
|
/*
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* domain_audit.c: Domain audit management
|
2010-12-16 16:10:54 +00:00
|
|
|
*
|
2014-02-10 10:18:16 +00:00
|
|
|
* Copyright (C) 2006-2014 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-16 16:10:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2011-03-07 23:17:26 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2020-01-24 17:32:48 +00:00
|
|
|
#ifdef __linux__
|
2016-04-14 13:11:45 +00:00
|
|
|
# include <sys/sysmacros.h>
|
|
|
|
#endif
|
|
|
|
|
Make sure sys/types.h is included after sys/sysmacros.h
In the latest glibc, major() and minor() functions are marked as
deprecated (glibc commit dbab6577):
CC util/libvirt_util_la-vircgroup.lo
util/vircgroup.c: In function 'virCgroupGetBlockDevString':
util/vircgroup.c:768:5: error: '__major_from_sys_types' is deprecated:
In the GNU C Library, `major' is defined by <sys/sysmacros.h>.
For historical compatibility, it is currently defined by
<sys/types.h> as well, but we plan to remove this soon.
To use `major', include <sys/sysmacros.h> directly.
If you did not intend to use a system-defined macro `major',
you should #undef it after including <sys/types.h>.
[-Werror=deprecated-declarations]
if (virAsprintf(&ret, "%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)) < 0)
^~
In file included from /usr/include/features.h:397:0,
from /usr/include/bits/libc-header-start.h:33,
from /usr/include/stdio.h:28,
from ../gnulib/lib/stdio.h:43,
from util/vircgroup.c:26:
/usr/include/sys/sysmacros.h:87:1: note: declared here
__SYSMACROS_DEFINE_MAJOR (__SYSMACROS_FST_IMPL_TEMPL)
^
Moreover, in the glibc commit, there's suggestion to keep
ordering of including of header files as implemented here.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-06 12:20:04 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
#include "domain_audit.h"
|
2011-07-11 19:42:15 +00:00
|
|
|
#include "viraudit.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("conf.domain_audit");
|
|
|
|
|
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 *
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
virDomainAuditGetRdev(const char *path)
|
2011-03-07 23:17:26 +00:00
|
|
|
{
|
|
|
|
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);
|
2019-10-22 13:26:14 +00:00
|
|
|
ret = g_strdup_printf("%02X:%02X", maj, min);
|
2011-03-07 23:17:26 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static char *
|
2019-10-14 12:45:33 +00:00
|
|
|
virDomainAuditGetRdev(const char *path G_GNUC_UNUSED)
|
2011-03-07 23:17:26 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-11 16:09:19 +00:00
|
|
|
|
2018-07-26 17:57:31 +00:00
|
|
|
static const char *
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditGetVirtType(virDomainDef *def)
|
2018-07-26 17:57:31 +00:00
|
|
|
{
|
|
|
|
const char *virt;
|
|
|
|
|
|
|
|
if (!(virt = virDomainVirtTypeToString(def->virtType))) {
|
|
|
|
VIR_WARN("Unexpected virt type %d while encoding audit message",
|
|
|
|
def->virtType);
|
|
|
|
virt = "?";
|
|
|
|
}
|
|
|
|
|
|
|
|
return virt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-02 09:24:24 +00:00
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditGenericDev(virDomainObj *vm,
|
2014-07-02 09:24:24 +00:00
|
|
|
const char *type,
|
|
|
|
const char *oldsrcpath,
|
|
|
|
const char *newsrcpath,
|
|
|
|
const char *reason,
|
|
|
|
bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
2019-12-20 12:43:11 +00:00
|
|
|
g_autofree char *newdev = NULL;
|
|
|
|
g_autofree char *olddev = NULL;
|
|
|
|
g_autofree char *vmname = NULL;
|
|
|
|
g_autofree char *oldsrc = NULL;
|
|
|
|
g_autofree char *newsrc = NULL;
|
2010-12-16 16:10:54 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2014-07-02 09:24:24 +00:00
|
|
|
/* if both new and old source aren't provided don't log anything */
|
|
|
|
if (!newsrcpath && !oldsrcpath)
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
2014-07-02 09:24:24 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
newdev = g_strdup_printf("new-%s", type);
|
|
|
|
olddev = g_strdup_printf("old-%s", type);
|
2014-07-02 09:24:24 +00:00
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name)))
|
2019-12-20 12:43:11 +00:00
|
|
|
return;
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2014-07-02 09:24:24 +00:00
|
|
|
if (!(newsrc = virAuditEncode(newdev, VIR_AUDIT_STR(newsrcpath))))
|
2019-12-20 12:43:11 +00:00
|
|
|
return;
|
2014-07-02 09:24:24 +00:00
|
|
|
|
|
|
|
if (!(oldsrc = virAuditEncode(olddev, VIR_AUDIT_STR(oldsrcpath))))
|
2019-12-20 12:43:11 +00:00
|
|
|
return;
|
2010-12-16 16:10:54 +00:00
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
2014-07-02 09:24:24 +00:00
|
|
|
"virt=%s resrc=%s reason=%s %s uuid=%s %s %s",
|
|
|
|
virt, type, reason, vmname, uuidstr, oldsrc, newsrc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-03 08:59:58 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditChardev(virDomainObj *vm,
|
|
|
|
virDomainChrDef *oldDef,
|
|
|
|
virDomainChrDef *newDef,
|
2014-07-03 08:59:58 +00:00
|
|
|
const char *reason,
|
|
|
|
bool success)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainChrSourceDef *oldsrc = NULL;
|
|
|
|
virDomainChrSourceDef *newsrc = NULL;
|
2014-07-03 08:59:58 +00:00
|
|
|
|
|
|
|
if (oldDef)
|
2016-10-21 11:45:54 +00:00
|
|
|
oldsrc = oldDef->source;
|
2014-07-03 08:59:58 +00:00
|
|
|
|
|
|
|
if (newDef)
|
2016-10-21 11:45:54 +00:00
|
|
|
newsrc = newDef->source;
|
2014-07-03 08:59:58 +00:00
|
|
|
|
|
|
|
virDomainAuditGenericDev(vm, "chardev",
|
2017-06-19 14:43:25 +00:00
|
|
|
virDomainChrSourceDefGetPath(oldsrc),
|
|
|
|
virDomainChrSourceDefGetPath(newsrc),
|
2014-07-03 08:59:58 +00:00
|
|
|
reason, success);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-03 10:03:41 +00:00
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditSmartcard(virDomainObj *vm,
|
|
|
|
virDomainSmartcardDef *def,
|
2014-07-03 10:03:41 +00:00
|
|
|
const char *reason,
|
|
|
|
bool success)
|
|
|
|
{
|
|
|
|
const char *database = VIR_DOMAIN_SMARTCARD_DEFAULT_DATABASE;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (def) {
|
|
|
|
switch ((virDomainSmartcardType) def->type) {
|
|
|
|
case VIR_DOMAIN_SMARTCARD_TYPE_HOST:
|
|
|
|
virDomainAuditGenericDev(vm, "smartcard",
|
|
|
|
NULL, "nss-smartcard-device",
|
|
|
|
reason, success);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES:
|
|
|
|
for (i = 0; i < VIR_DOMAIN_SMARTCARD_NUM_CERTIFICATES; i++) {
|
|
|
|
virDomainAuditGenericDev(vm, "smartcard", NULL,
|
|
|
|
def->data.cert.file[i],
|
|
|
|
reason, success);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (def->data.cert.database)
|
|
|
|
database = def->data.cert.database;
|
|
|
|
|
|
|
|
virDomainAuditGenericDev(vm, "smartcard",
|
|
|
|
NULL, database,
|
|
|
|
reason, success);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
|
|
|
|
virDomainAuditGenericDev(vm, "smartcard", NULL,
|
2017-06-19 14:43:25 +00:00
|
|
|
virDomainChrSourceDefGetPath(def->data.passthru),
|
2014-07-03 10:03:41 +00:00
|
|
|
reason, success);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-02 09:24:24 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditDisk(virDomainObj *vm,
|
|
|
|
virStorageSource *oldDef,
|
|
|
|
virStorageSource *newDef,
|
2014-07-03 08:28:12 +00:00
|
|
|
const char *reason,
|
|
|
|
bool success)
|
2014-07-02 09:24:24 +00:00
|
|
|
{
|
2014-07-03 08:28:12 +00:00
|
|
|
const char *oldsrc = NULL;
|
|
|
|
const char *newsrc = NULL;
|
|
|
|
|
|
|
|
if (oldDef && virStorageSourceIsLocalStorage(oldDef))
|
|
|
|
oldsrc = oldDef->path;
|
|
|
|
|
|
|
|
if (newDef && virStorageSourceIsLocalStorage(newDef))
|
|
|
|
newsrc = newDef->path;
|
|
|
|
|
|
|
|
virDomainAuditGenericDev(vm, "disk", oldsrc, newsrc, reason, success);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-17 05:09:36 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditRNG(virDomainObj *vm,
|
|
|
|
virDomainRNGDef *oldDef, virDomainRNGDef *newDef,
|
2013-03-11 16:09:19 +00:00
|
|
|
const char *reason, bool success)
|
|
|
|
{
|
|
|
|
const char *newsrcpath = NULL;
|
|
|
|
const char *oldsrcpath = NULL;
|
|
|
|
|
|
|
|
if (newDef) {
|
2014-06-01 00:22:30 +00:00
|
|
|
switch ((virDomainRNGBackend) newDef->backend) {
|
2013-03-11 16:09:19 +00:00
|
|
|
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
|
2014-07-25 08:00:49 +00:00
|
|
|
newsrcpath = newDef->source.file;
|
2013-03-11 16:09:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_RNG_BACKEND_EGD:
|
2017-06-19 14:43:25 +00:00
|
|
|
newsrcpath = virDomainChrSourceDefGetPath(newDef->source.chardev);
|
2013-03-11 16:09:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-09 08:00:07 +00:00
|
|
|
case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
|
2013-03-11 16:09:19 +00:00
|
|
|
case VIR_DOMAIN_RNG_BACKEND_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldDef) {
|
2014-06-01 00:22:30 +00:00
|
|
|
switch ((virDomainRNGBackend) oldDef->backend) {
|
2013-03-11 16:09:19 +00:00
|
|
|
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
|
2014-07-25 08:00:49 +00:00
|
|
|
oldsrcpath = oldDef->source.file;
|
2013-03-11 16:09:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_RNG_BACKEND_EGD:
|
2017-06-19 14:43:25 +00:00
|
|
|
oldsrcpath = virDomainChrSourceDefGetPath(oldDef->source.chardev);
|
2013-03-11 16:09:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-09 08:00:07 +00:00
|
|
|
case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
|
2013-03-11 16:09:19 +00:00
|
|
|
case VIR_DOMAIN_RNG_BACKEND_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-02 09:24:24 +00:00
|
|
|
virDomainAuditGenericDev(vm, "rng", oldsrcpath, newsrcpath, reason, success);
|
2013-03-11 16:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-04 11:00:33 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditFS(virDomainObj *vm,
|
|
|
|
virDomainFSDef *oldDef, virDomainFSDef *newDef,
|
2011-07-04 11:00:33 +00:00
|
|
|
const char *reason, bool success)
|
|
|
|
{
|
2014-07-02 09:24:24 +00:00
|
|
|
virDomainAuditGenericDev(vm, "fs",
|
2016-07-14 13:52:38 +00:00
|
|
|
oldDef ? oldDef->src->path : NULL,
|
|
|
|
newDef ? newDef->src->path : NULL,
|
2014-07-02 09:24:24 +00:00
|
|
|
reason, success);
|
2011-07-04 11:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditNet(virDomainObj *vm,
|
|
|
|
virDomainNetDef *oldDef, virDomainNetDef *newDef,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
const char *reason, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
char newMacstr[VIR_MAC_STRING_BUFLEN];
|
|
|
|
char oldMacstr[VIR_MAC_STRING_BUFLEN];
|
|
|
|
|
|
|
|
if (oldDef)
|
2012-07-17 12:07:59 +00:00
|
|
|
virMacAddrFormat(&oldDef->mac, oldMacstr);
|
2014-07-02 09:24:24 +00:00
|
|
|
|
2010-12-16 16:10:54 +00:00
|
|
|
if (newDef)
|
2012-07-17 12:07:59 +00:00
|
|
|
virMacAddrFormat(&newDef->mac, newMacstr);
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2014-07-02 09:24:24 +00:00
|
|
|
virDomainAuditGenericDev(vm, "net",
|
|
|
|
oldDef ? oldMacstr : NULL,
|
|
|
|
newDef ? newMacstr : NULL,
|
|
|
|
reason, success);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* virDomainAuditNetDevice:
|
2014-08-07 08:12:58 +00:00
|
|
|
* @vmDef: the definition of the VM
|
|
|
|
* @netDef: details of network device that fd will be tied to
|
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
|
|
|
* @device: device being opened (such as /dev/vhost-net,
|
|
|
|
* /dev/net/tun, /dev/tanN). Note that merely opening a device
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* does not mean that virDomain owns it; a followup virDomainAuditNet
|
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
|
|
|
* 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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditNetDevice(virDomainDef *vmDef, virDomainNetDef *netDef,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
const char *device, bool success)
|
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
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char macstr[VIR_MAC_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
2013-01-22 14:15:38 +00:00
|
|
|
char *dev_name = NULL;
|
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
|
|
|
char *rdev;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vmDef);
|
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
|
|
|
|
|
|
|
virUUIDFormat(vmDef->uuid, uuidstr);
|
2012-07-17 12:07:59 +00:00
|
|
|
virMacAddrFormat(&netDef->mac, macstr);
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
rdev = virDomainAuditGetRdev(device);
|
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
|
|
|
|
|
|
|
if (!(vmname = virAuditEncode("vm", vmDef->name)) ||
|
2011-09-16 12:05:58 +00:00
|
|
|
!(dev_name = 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,
|
2012-02-09 19:06:00 +00:00
|
|
|
"virt=%s resrc=net reason=open %s uuid=%s net=%s %s rdev=%s",
|
2011-09-16 12:05:58 +00:00
|
|
|
virt, vmname, uuidstr, macstr, dev_name, VIR_AUDIT_STR(rdev));
|
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
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
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
|
|
|
VIR_FREE(vmname);
|
2011-09-16 12:05:58 +00:00
|
|
|
VIR_FREE(dev_name);
|
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
|
|
|
VIR_FREE(rdev);
|
|
|
|
}
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2011-02-23 23:15:23 +00:00
|
|
|
/**
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* virDomainAuditHostdev:
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
const char *reason, bool success)
|
2011-02-23 23:15:23 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
2011-09-14 20:02:30 +00:00
|
|
|
char *address = NULL;
|
|
|
|
char *device = NULL;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainHostdevSubsysUSB *usbsrc = &hostdev->source.subsys.u.usb;
|
|
|
|
virDomainHostdevSubsysPCI *pcisrc = &hostdev->source.subsys.u.pci;
|
|
|
|
virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi;
|
|
|
|
virDomainHostdevSubsysSCSIVHost *hostsrc = &hostdev->source.subsys.u.scsi_host;
|
|
|
|
virDomainHostdevSubsysMediatedDev *mdevsrc = &hostdev->source.subsys.u.mdev;
|
2011-02-23 23:15:23 +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-23 23:15:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:42:58 +00:00
|
|
|
switch ((virDomainHostdevMode) hostdev->mode) {
|
2012-11-23 13:50:29 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
|
2018-05-31 07:42:58 +00:00
|
|
|
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
|
2012-11-23 13:50:29 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
2021-01-04 12:54:25 +00:00
|
|
|
address = virPCIDeviceAddressAsString(&pcisrc->addr);
|
2012-11-23 13:50:29 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
|
2019-10-22 13:26:14 +00:00
|
|
|
address = g_strdup_printf("%.3d.%.3d", usbsrc->bus, usbsrc->device);
|
2013-05-03 18:07:20 +00:00
|
|
|
break;
|
2014-06-20 15:35:46 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
2014-07-09 13:31:38 +00:00
|
|
|
if (scsisrc->protocol ==
|
|
|
|
VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
|
|
|
|
/* Follow virDomainAuditDisk && virDomainAuditGenericDev
|
|
|
|
* and don't audit the networked device.
|
|
|
|
*/
|
2013-05-03 18:07:20 +00:00
|
|
|
goto cleanup;
|
2014-07-09 13:31:38 +00:00
|
|
|
} else {
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host;
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
address = g_strdup_printf("%s:%u:%u:%llu",
|
|
|
|
scsihostsrc->adapter, scsihostsrc->bus,
|
|
|
|
scsihostsrc->target,
|
|
|
|
scsihostsrc->unit);
|
2012-11-23 13:50:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-06-20 15:35:46 +00:00
|
|
|
}
|
2016-11-22 03:58:20 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
|
2019-10-20 11:49:46 +00:00
|
|
|
address = g_strdup(hostsrc->wwpn);
|
2016-11-22 03:58:20 +00:00
|
|
|
break;
|
2018-05-31 07:42:58 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
|
2019-10-20 11:49:46 +00:00
|
|
|
address = g_strdup(mdevsrc->uuidstr);
|
2018-05-31 07:42:58 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
|
2012-11-23 13:50:29 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-11-23 13:50:29 +00:00
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=dev reason=%s %s uuid=%s bus=%s %s",
|
|
|
|
virt, reason, vmname, uuidstr,
|
|
|
|
virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type),
|
|
|
|
device);
|
2011-02-23 23:15:23 +00:00
|
|
|
break;
|
2012-11-23 13:50:29 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
|
|
|
|
switch (hostdev->source.caps.type) {
|
|
|
|
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
|
|
|
|
if (!(device = virAuditEncode("disk",
|
|
|
|
VIR_AUDIT_STR(hostdev->source.caps.u.storage.block)))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=hostdev reason=%s %s uuid=%s %s",
|
|
|
|
virt, reason, vmname, uuidstr, device);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
|
|
|
|
if (!(device = virAuditEncode("chardev",
|
|
|
|
VIR_AUDIT_STR(hostdev->source.caps.u.misc.chardev)))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=hostdev reason=%s %s uuid=%s %s",
|
|
|
|
virt, reason, vmname, uuidstr, device);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
VIR_WARN("Unexpected hostdev type while encoding audit message: %d",
|
|
|
|
hostdev->source.caps.type);
|
2011-02-23 23:15:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-31 07:42:58 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_MODE_LAST:
|
2012-11-23 13:50:29 +00:00
|
|
|
default:
|
|
|
|
VIR_WARN("Unexpected hostdev mode while encoding audit message: %d",
|
|
|
|
hostdev->mode);
|
2011-02-23 23:15:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2011-02-23 23:15:23 +00:00
|
|
|
VIR_FREE(vmname);
|
|
|
|
VIR_FREE(device);
|
|
|
|
VIR_FREE(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-02 15:09:14 +00:00
|
|
|
/**
|
|
|
|
* virDomainAuditRedirdev:
|
|
|
|
* @vm: domain making a change in pass-through host device
|
|
|
|
* @redirdev: device being attached or removed
|
|
|
|
* @reason: one of "start", "attach", or "detach"
|
|
|
|
* @success: true if the device passthrough operation succeeded
|
|
|
|
*
|
|
|
|
* Log an audit message about an attempted device passthrough change.
|
|
|
|
*/
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditRedirdev(virDomainObj *vm, virDomainRedirdevDef *redirdev,
|
2011-09-02 15:09:14 +00:00
|
|
|
const char *reason, bool success)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
2011-09-14 20:02:30 +00:00
|
|
|
char *address = NULL;
|
|
|
|
char *device = NULL;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2011-09-02 15:09:14 +00:00
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (redirdev->bus) {
|
|
|
|
case VIR_DOMAIN_REDIRDEV_BUS_USB:
|
2019-10-20 11:49:46 +00:00
|
|
|
address = g_strdup("USB redirdev");
|
2011-09-14 20:02:30 +00:00
|
|
|
break;
|
2011-09-02 15:09:14 +00:00
|
|
|
default:
|
|
|
|
VIR_WARN("Unexpected redirdev bus while encoding audit message: %d",
|
|
|
|
redirdev->bus);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(address)))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=dev reason=%s %s uuid=%s bus=%s %s",
|
|
|
|
virt, reason, vmname, uuidstr,
|
|
|
|
virDomainRedirdevBusTypeToString(redirdev->bus),
|
|
|
|
device);
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2011-09-02 15:09:14 +00:00
|
|
|
VIR_FREE(vmname);
|
|
|
|
VIR_FREE(device);
|
|
|
|
VIR_FREE(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-12 20:55:46 +00:00
|
|
|
/**
|
|
|
|
* virDomainAuditTPM:
|
2018-05-24 14:51:26 +00:00
|
|
|
* @vm: domain making a change in pass-through host device or emulator
|
2013-04-12 20:55:46 +00:00
|
|
|
* @tpm: TPM device being attached or removed
|
|
|
|
* @reason: one of "start", "attach", or "detach"
|
2018-05-24 14:51:26 +00:00
|
|
|
* @success: true if the device operation succeeded
|
2013-04-12 20:55:46 +00:00
|
|
|
*
|
2018-05-24 14:51:26 +00:00
|
|
|
* Log an audit message about an attempted device passthrough or emulator
|
|
|
|
* change.
|
2013-04-12 20:55:46 +00:00
|
|
|
*/
|
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
|
2013-04-12 20:55:46 +00:00
|
|
|
const char *reason, bool success)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
|
|
|
char *path = NULL;
|
|
|
|
char *device = NULL;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2013-04-12 20:55:46 +00:00
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (tpm->type) {
|
|
|
|
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
|
|
|
path = tpm->data.passthrough.source.data.file.path;
|
|
|
|
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(path)))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
2018-05-24 14:53:05 +00:00
|
|
|
"virt=%s resrc=tpm reason=%s %s uuid=%s %s",
|
2013-04-12 20:55:46 +00:00
|
|
|
virt, reason, vmname, uuidstr, device);
|
|
|
|
break;
|
2017-04-04 16:22:31 +00:00
|
|
|
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
2018-05-24 14:51:26 +00:00
|
|
|
path = tpm->data.emulator.source.data.nix.path;
|
|
|
|
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(path)))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=tpm-emulator reason=%s %s uuid=%s %s",
|
|
|
|
virt, reason, vmname, uuidstr, device);
|
2017-04-04 16:22:31 +00:00
|
|
|
break;
|
2018-02-14 09:43:59 +00:00
|
|
|
case VIR_DOMAIN_TPM_TYPE_LAST:
|
2013-04-12 20:55:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2013-04-12 20:55:46 +00:00
|
|
|
VIR_FREE(vmname);
|
|
|
|
VIR_FREE(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-16 02:35:43 +00:00
|
|
|
/**
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* virDomainAuditCgroup:
|
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
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* latter two are generated by virDomainAuditCgroupMajor and
|
|
|
|
* virDomainAuditCgroupPath).
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditCgroup(virDomainObj *vm, virCgroup *cgroup,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +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;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
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-07-04 11:21:21 +00:00
|
|
|
"virt=%s resrc=cgroup reason=%s %s uuid=%s %s class=%s",
|
|
|
|
virt, reason, vmname, uuidstr,
|
2011-03-07 23:41:40 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* virDomainAuditCgroupMajor:
|
2011-03-07 23:17:26 +00:00
|
|
|
* @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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditCgroupMajor(virDomainObj *vm, virCgroup *cgroup,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
const char *reason, int maj, const char *name,
|
|
|
|
const char *perms, bool success)
|
2011-03-07 23:17:26 +00:00
|
|
|
{
|
|
|
|
char *extra;
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
extra = g_strdup_printf("major category=%s maj=%02X acl=%s",
|
|
|
|
name, maj, perms);
|
2011-03-07 23:17:26 +00:00
|
|
|
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
virDomainAuditCgroup(vm, cgroup, reason, extra, success);
|
2011-03-07 23:17:26 +00:00
|
|
|
|
|
|
|
VIR_FREE(extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* virDomainAuditCgroupPath:
|
2011-03-07 23:17:26 +00:00
|
|
|
* @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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditCgroupPath(virDomainObj *vm, virCgroup *cgroup,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +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;
|
2013-01-22 14:15:38 +00:00
|
|
|
char *extra = NULL;
|
2011-03-07 23:17:26 +00:00
|
|
|
|
|
|
|
/* Nothing to audit for regular files. */
|
|
|
|
if (rc > 0)
|
|
|
|
return;
|
|
|
|
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
rdev = virDomainAuditGetRdev(path);
|
2011-03-07 23:17:26 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
if (!(detail = virAuditEncode("path", path))) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
extra = g_strdup_printf("path %s rdev=%s acl=%s",
|
|
|
|
detail, VIR_AUDIT_STR(rdev), perms);
|
|
|
|
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
virDomainAuditCgroup(vm, cgroup, reason, extra, rc == 0);
|
2011-02-16 02:35:43 +00:00
|
|
|
|
2014-03-25 06:48:31 +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
|
|
|
/**
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
* virDomainAuditResource:
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditResource(virDomainObj *vm, const char *resource,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
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;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2011-02-22 00:02:17 +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-22 00:02:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
2011-07-04 11:21:21 +00:00
|
|
|
"virt=%s resrc=%s reason=%s %s uuid=%s old-%s=%lld new-%s=%lld",
|
|
|
|
virt, resource, reason, vmname, uuidstr,
|
2011-02-22 00:02:17 +00:00
|
|
|
resource, oldval, resource, newval);
|
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditMemory(virDomainObj *vm,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
unsigned long long oldmem, unsigned long long newmem,
|
|
|
|
const char *reason, bool success)
|
2011-02-22 00:02:17 +00:00
|
|
|
{
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
return virDomainAuditResource(vm, "mem", oldmem, newmem, reason, success);
|
2011-02-22 00:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditVcpu(virDomainObj *vm,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
unsigned int oldvcpu, unsigned int newvcpu,
|
|
|
|
const char *reason, bool success)
|
2011-02-22 00:02:17 +00:00
|
|
|
{
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
return virDomainAuditResource(vm, "vcpu", oldvcpu, newvcpu, reason, success);
|
2011-02-22 00:02:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 10:51:12 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditIOThread(virDomainObj *vm,
|
2015-03-18 10:51:12 +00:00
|
|
|
unsigned int oldiothread, unsigned int newiothread,
|
|
|
|
const char *reason, bool success)
|
|
|
|
{
|
|
|
|
return virDomainAuditResource(vm, "iothread", oldiothread, newiothread,
|
|
|
|
reason, success);
|
|
|
|
}
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditLifecycle(virDomainObj *vm, const char *op,
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
const char *reason, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2010-12-16 16:10:54 +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");
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_CONTROL, success,
|
2012-04-20 13:13:51 +00:00
|
|
|
"virt=%s op=%s reason=%s %s uuid=%s vm-pid=%lld",
|
|
|
|
virt, op, reason, vmname, uuidstr, (long long)vm->pid);
|
2010-12-16 16:10:54 +00:00
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditStart(virDomainObj *vm, const char *reason, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2014-07-03 08:28:12 +00:00
|
|
|
for (i = 0; i < vm->def->ndisks; i++)
|
|
|
|
virDomainAuditDisk(vm, NULL, vm->def->disks[i]->src, "start", true);
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < vm->def->nfss; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainFSDef *fs = vm->def->fss[i];
|
2011-07-04 11:00:33 +00:00
|
|
|
virDomainAuditFS(vm, NULL, fs, "start", true);
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < vm->def->nnets; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNetDef *net = vm->def->nets[i];
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
virDomainAuditNet(vm, NULL, net, "start", true);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < vm->def->nhostdevs; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainHostdevDef *hostdev = vm->def->hostdevs[i];
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
virDomainAuditHostdev(vm, hostdev, "start", true);
|
2011-02-23 23:15:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < vm->def->nredirdevs; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainRedirdevDef *redirdev = vm->def->redirdevs[i];
|
2011-09-02 15:09:14 +00:00
|
|
|
virDomainAuditRedirdev(vm, redirdev, "start", true);
|
|
|
|
}
|
|
|
|
|
2014-07-03 08:59:58 +00:00
|
|
|
for (i = 0; i < vm->def->nserials; i++)
|
|
|
|
virDomainAuditChardev(vm, NULL, vm->def->serials[i], "start", true);
|
|
|
|
|
|
|
|
for (i = 0; i < vm->def->nparallels; i++)
|
|
|
|
virDomainAuditChardev(vm, NULL, vm->def->parallels[i], "start", true);
|
|
|
|
|
|
|
|
for (i = 0; i < vm->def->nchannels; i++)
|
|
|
|
virDomainAuditChardev(vm, NULL, vm->def->channels[i], "start", true);
|
|
|
|
|
|
|
|
for (i = 0; i < vm->def->nconsoles; i++) {
|
|
|
|
if (i == 0 &&
|
|
|
|
(vm->def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ||
|
|
|
|
vm->def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) &&
|
2015-04-17 00:11:06 +00:00
|
|
|
vm->def->os.type == VIR_DOMAIN_OSTYPE_HVM)
|
2014-07-03 08:59:58 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
virDomainAuditChardev(vm, NULL, vm->def->consoles[i], "start", true);
|
|
|
|
}
|
|
|
|
|
2014-07-03 10:03:41 +00:00
|
|
|
for (i = 0; i < vm->def->nsmartcards; i++)
|
|
|
|
virDomainAuditSmartcard(vm, vm->def->smartcards[i], "start", true);
|
|
|
|
|
2013-02-25 22:31:11 +00:00
|
|
|
for (i = 0; i < vm->def->nrngs; i++)
|
|
|
|
virDomainAuditRNG(vm, NULL, vm->def->rngs[i], "start", true);
|
2013-03-11 16:09:19 +00:00
|
|
|
|
2020-06-10 18:11:47 +00:00
|
|
|
for (i = 0; i < vm->def->ntpms; i++)
|
|
|
|
virDomainAuditTPM(vm, vm->def->tpms[i], "start", true);
|
2013-04-12 20:55:46 +00:00
|
|
|
|
2016-08-11 09:40:18 +00:00
|
|
|
for (i = 0; i < vm->def->nshmems; i++)
|
|
|
|
virDomainAuditShmem(vm, vm->def->shmems[i], "start", true);
|
|
|
|
|
2017-10-16 12:58:51 +00:00
|
|
|
for (i = 0; i < vm->def->ninputs; i++)
|
|
|
|
virDomainAuditInput(vm, vm->def->inputs[i], "start", true);
|
|
|
|
|
2016-06-15 13:34:04 +00:00
|
|
|
virDomainAuditMemory(vm, 0, virDomainDefGetMemoryTotal(vm->def),
|
2015-06-26 15:12:39 +00:00
|
|
|
"start", true);
|
2015-10-22 12:59:03 +00:00
|
|
|
virDomainAuditVcpu(vm, 0, virDomainDefGetVcpus(vm->def), "start", true);
|
2015-10-15 14:26:26 +00:00
|
|
|
if (vm->def->niothreadids)
|
|
|
|
virDomainAuditIOThread(vm, 0, vm->def->niothreadids, "start", true);
|
2011-02-22 00:02:17 +00:00
|
|
|
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
virDomainAuditLifecycle(vm, "start", reason, success);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2012-11-20 17:49:25 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditInit(virDomainObj *vm,
|
2013-03-06 14:56:49 +00:00
|
|
|
pid_t initpid,
|
|
|
|
ino_t pidns)
|
2012-11-20 17:49:25 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2012-11-20 17:49:25 +00:00
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name))) {
|
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_CONTROL, true,
|
2013-03-06 14:56:49 +00:00
|
|
|
"virt=%s op=init %s uuid=%s vm-pid=%lld init-pid=%lld pid-ns=%lld",
|
|
|
|
virt, vmname, uuidstr, (long long)vm->pid, (long long)initpid,
|
|
|
|
(long long)pidns);
|
2012-11-20 17:49:25 +00:00
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditStop(virDomainObj *vm, const char *reason)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
Move qemu_audit.h helpers into shared code
The LXC and UML drivers can both make use of auditing. Move
the qemu_audit.{c,h} files to src/conf/domain_audit.{c,h}
* src/conf/domain_audit.c: Rename from src/qemu/qemu_audit.c
* src/conf/domain_audit.h: Rename from src/qemu/qemu_audit.h
* src/Makefile.am: Remove qemu_audit.{c,h}, add domain_audit.{c,h}
* src/qemu/qemu_audit.h, src/qemu/qemu_cgroup.c,
src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
src/qemu/qemu_hotplug.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c: Update for changed audit API names
2011-07-04 10:56:13 +00:00
|
|
|
virDomainAuditLifecycle(vm, "stop", reason, true);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 21:28:51 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditSecurityLabel(virDomainObj *vm, bool success)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2010-12-16 16:10:54 +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");
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-15 22:10:35 +00:00
|
|
|
for (i = 0; i < vm->def->nseclabels; i++) {
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_ID, success,
|
|
|
|
"virt=%s %s uuid=%s vm-ctx=%s img-ctx=%s model=%s",
|
|
|
|
virt, vmname, uuidstr,
|
|
|
|
VIR_AUDIT_STR(vm->def->seclabels[i]->label),
|
|
|
|
VIR_AUDIT_STR(vm->def->seclabels[i]->imagelabel),
|
|
|
|
VIR_AUDIT_STR(vm->def->seclabels[i]->model));
|
|
|
|
}
|
2010-12-16 16:10:54 +00:00
|
|
|
|
|
|
|
VIR_FREE(vmname);
|
|
|
|
}
|
2016-08-11 09:40:18 +00:00
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditShmem(virDomainObj *vm,
|
|
|
|
virDomainShmemDef *def,
|
2016-08-11 09:40:18 +00:00
|
|
|
const char *reason, bool success)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
char *vmname = virAuditEncode("vm", vm->def->name);
|
2017-06-19 14:43:25 +00:00
|
|
|
const char *srcpath = virDomainChrSourceDefGetPath(&def->server.chr);
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2017-05-11 08:10:54 +00:00
|
|
|
char *shmpath = NULL;
|
2016-08-11 09:40:18 +00:00
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
if (!vmname) {
|
2016-08-11 09:40:18 +00:00
|
|
|
VIR_WARN("OOM while encoding audit message");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
shmpath = g_strdup_printf("/dev/shm/%s", def->name);
|
|
|
|
|
2016-08-11 09:40:18 +00:00
|
|
|
if (!virt) {
|
|
|
|
VIR_WARN("Unexpected virt type %d while encoding audit message",
|
|
|
|
vm->def->virtType);
|
|
|
|
virt = "?";
|
|
|
|
}
|
|
|
|
|
2017-05-11 08:10:54 +00:00
|
|
|
if (def->server.enabled) {
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=ivshmem-socket reason=%s %s uuid=%s path=%s",
|
|
|
|
virt, reason, vmname, uuidstr, VIR_AUDIT_STR(srcpath));
|
|
|
|
} else {
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=shmem reason=%s %s uuid=%s size=%llu path=%s",
|
|
|
|
virt, reason, vmname, uuidstr, def->size, VIR_AUDIT_STR(shmpath));
|
|
|
|
}
|
2016-08-11 09:40:18 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(vmname);
|
2017-05-11 08:10:54 +00:00
|
|
|
VIR_FREE(shmpath);
|
2016-08-11 09:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-16 12:58:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainAuditInput(virDomainObj *vm,
|
|
|
|
virDomainInputDef *input,
|
2017-10-16 12:58:51 +00:00
|
|
|
const char *reason,
|
|
|
|
bool success)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2019-12-20 12:43:11 +00:00
|
|
|
g_autofree char *vmname = NULL;
|
2018-07-26 17:57:31 +00:00
|
|
|
const char *virt = virDomainAuditGetVirtType(vm->def);
|
2017-10-16 12:58:51 +00:00
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
|
|
|
|
if (!(vmname = virAuditEncode("vm", vm->def->name)))
|
2019-12-20 12:43:11 +00:00
|
|
|
return;
|
2017-10-16 12:58:51 +00:00
|
|
|
|
|
|
|
switch ((virDomainInputType) input->type) {
|
|
|
|
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
|
|
|
|
case VIR_DOMAIN_INPUT_TYPE_TABLET:
|
|
|
|
case VIR_DOMAIN_INPUT_TYPE_KBD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
|
|
|
|
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
|
|
|
|
"virt=%s resrc=evdev reason=%s %s uuid=%s path=%s",
|
|
|
|
virt, reason, vmname, uuidstr, VIR_AUDIT_STR(input->source.evdev));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_INPUT_TYPE_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|