Currently, there's just one place where we care if hook script is
changing the domain XML: migration hook for incoming migration. In
all other places where a hook script is executed, we don't read the
XML back from the script.
Anyway, the hook script can alter domain XML and hence we should taint
it if the script did.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
Notes:
Do we want to mark all the cases where hook script was executed (but domain XML
hasn't changed)? For instance, at domain startup process, the hook script is
called and if it has exited with zero status, the startup process can continue,
otherwise it's aborted. I don't think that counts as taint reason, does it?
src/qemu/qemu_domain.c | 4 ++++
src/qemu/qemu_domain.h | 2 ++
src/qemu/qemu_migration.c | 10 ++++++++++
3 files changed, 16 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c947e2e..3069462 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1628,6 +1628,7 @@ void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
{
size_t i;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ qemuDomainObjPrivatePtr priv = obj->privateData;
if (cfg->privileged &&
(!cfg->clearEmulatorCapabilities ||
@@ -1635,6 +1636,9 @@ void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
cfg->group == 0))
qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES, logFD);
+ if (priv->hookRun)
+ qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HOOK, logFD);
+
if (obj->def->namespaceData) {
qemuDomainCmdlineDefPtr qemucmd = obj->def->namespaceData;
if (qemucmd->num_args || qemucmd->num_env)
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 6a92351..76a587f 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -173,6 +173,8 @@ struct _qemuDomainObjPrivate {
virCond unplugFinished; /* signals that unpluggingDevice was unplugged */
const char *unpluggingDevice; /* alias of the device that is being unplugged */
char **qemuDevices; /* NULL-terminated list of devices aliases known to QEMU */
+
+ bool hookRun; /* true if there was a hook run over this domain */
};
typedef enum {
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 407fb70..664602c 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2181,6 +2181,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
virCapsPtr caps = NULL;
char *migrateFrom = NULL;
bool abort_on_error = !!(flags & VIR_MIGRATE_ABORT_ON_ERROR);
+ bool taint_hook = false;
if (virTimeMillisNow(&now) < 0)
return -1;
@@ -2251,6 +2252,10 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
virDomainDefFree(*def);
*def = newdef;
+ /* We should taint the domain here. However, @vm and therefore
+ * privateData too are still NULL, so just notice the fact and
+ * taint it later. */
+ taint_hook = true;
}
}
}
@@ -2336,6 +2341,11 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
if (VIR_STRDUP(priv->origname, origname) < 0)
goto cleanup;
+ if (taint_hook) {
+ /* Domain XML has been altered by a hook script. */
+ priv->hookRun = true;
+ }
+
if (!(mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen,
QEMU_MIGRATION_COOKIE_LOCKSTATE |
QEMU_MIGRATION_COOKIE_NBD)))
--
1.8.5.2