tools/xenstored: Harden corrupt()
authorJulien Grall <jgrall@amazon.com>
Tue, 12 Jul 2022 09:12:13 +0000 (11:12 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 12 Jul 2022 09:12:13 +0000 (11:12 +0200)
At the moment, corrupt() is neither checking for allocation failure
nor freeing the allocated memory.

Harden the code by printing ENOMEM if the allocation failed and
free 'str' after the last use.

This is not considered to be a security issue because corrupt() should
only be called when Xenstored thinks the database is corrupted. Note
that the trigger (i.e. a guest reliably provoking the call) would be
a security issue.

Fixes: 06d17943f0cd ("Added a basic integrity checker, and some basic ability to recover from store")
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
master commit: db3382dd4f468c763512d6bf91c96773395058fb
master date: 2022-06-23 13:44:10 +0100

tools/xenstore/xenstored_core.c

index 91d093a12ea6840684fa5b85fd9fb0a360480dc7..0c8ee276f8371785cb1e8afa961deb48d4831a41 100644 (file)
@@ -2087,7 +2087,10 @@ void corrupt(struct connection *conn, const char *fmt, ...)
        va_end(arglist);
 
        log("corruption detected by connection %i: err %s: %s",
-           conn ? (int)conn->id : -1, strerror(saved_errno), str);
+           conn ? (int)conn->id : -1, strerror(saved_errno),
+           str ?: "ENOMEM");
+
+       talloc_free(str);
 
        check_store();
 }