From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
kashyap.cv@gmail.com, "Benoît Canet" <benoit@irqsave.net>,
"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v2 2/3] qemu-img: Detect backing file chain infinite loops
Date: Mon, 15 Oct 2012 14:44:16 +0200 [thread overview]
Message-ID: <1350305057-6287-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1350305057-6287-1-git-send-email-stefanha@redhat.com>
A malicious or corruption image can contain an infinite loop of backing
files. The qemu-img info --backing-chain command must not hang when
such files are encountered.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
qemu-img.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/qemu-img.c b/qemu-img.c
index c717f3e..60a5cc8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1259,6 +1259,11 @@ typedef enum OutputFormat {
OFORMAT_HUMAN,
} OutputFormat;
+static gboolean str_equal_func(gconstpointer a, gconstpointer b)
+{
+ return strcmp(a, b) == 0;
+}
+
static int img_info(int argc, char **argv)
{
int c;
@@ -1268,6 +1273,7 @@ static int img_info(int argc, char **argv)
char *filename, *fmt;
BlockDriverState *bs;
ImageInfo *info;
+ GHashTable *filenames;
fmt = NULL;
output = NULL;
@@ -1306,6 +1312,9 @@ static int img_info(int argc, char **argv)
}
filename = g_strdup(argv[optind++]);
+ filenames = g_hash_table_new_full(g_str_hash, str_equal_func,
+ g_free, NULL);
+
if (output && !strcmp(output, "json")) {
output_format = OFORMAT_JSON;
} else if (output && !strcmp(output, "human")) {
@@ -1320,6 +1329,12 @@ static int img_info(int argc, char **argv)
}
do {
+ if (g_hash_table_lookup_extended(filenames, filename, NULL, NULL)) {
+ error_report("Aborting due to backing file chain infinite loop.");
+ goto err;
+ }
+ g_hash_table_insert(filenames, g_strdup(filename), NULL);
+
bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING,
false);
if (!bs) {
@@ -1376,11 +1391,13 @@ static int img_info(int argc, char **argv)
if (chain && output_format == OFORMAT_JSON) {
printf("]\n");
}
+ g_hash_table_destroy(filenames);
return 0;
err:
g_free(filename);
g_free(fmt);
+ g_hash_table_destroy(filenames);
return 1;
}
--
1.7.11.7
next prev parent reply other threads:[~2012-10-15 12:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-15 12:44 [Qemu-devel] [PATCH v2 0/3] qemu-img: Add --backing-chain option to info command Stefan Hajnoczi
2012-10-15 12:44 ` [Qemu-devel] [PATCH v2 1/3] " Stefan Hajnoczi
2012-10-16 10:04 ` Kevin Wolf
2012-10-16 14:51 ` Stefan Hajnoczi
2012-10-15 12:44 ` Stefan Hajnoczi [this message]
2012-10-16 10:11 ` [Qemu-devel] [PATCH v2 2/3] qemu-img: Detect backing file chain infinite loops Kevin Wolf
2012-10-16 14:42 ` Stefan Hajnoczi
2012-10-16 14:58 ` Kevin Wolf
2012-10-15 12:44 ` [Qemu-devel] [PATCH v2 3/3] qemu-iotests: Add 041 backing file chain infinite loop test Stefan Hajnoczi
2012-10-15 17:47 ` Eric Blake
2012-10-16 8:21 ` Stefan Hajnoczi
2012-10-16 10:22 ` Kevin Wolf
2012-10-16 14:53 ` Stefan Hajnoczi
2012-10-15 17:49 ` [Qemu-devel] [PATCH v2 0/3] qemu-img: Add --backing-chain option to info command Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1350305057-6287-3-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=benoit@irqsave.net \
--cc=kashyap.cv@gmail.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).