[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 11/27] sheepdog: Defuse time bomb in sd_open() error
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 11/27] sheepdog: Defuse time bomb in sd_open() error handling |
Date: |
Tue, 7 Mar 2017 16:40:35 +0100 |
From: Markus Armbruster <address@hidden>
When qemu_opts_absorb_qdict() fails, sd_open() closes stdin, because
sd->fd is still zero. Fortunately, qemu_opts_absorb_qdict() can't
fail, because:
1. it only fails when qemu_opt_parse() fails, and
2. the only member of runtime_opts.desc[] is a QEMU_OPT_STRING, and
3. qemu_opt_parse() can't fail for QEMU_OPT_STRING.
Defuse this ticking time bomb by jumping behind the file descriptor
cleanup on error.
Also do that for the error paths where sd->fd is still -1. The file
descriptor cleanup happens to do nothing then, but let's not rely on
that here.
While there, rename label out to err, because it's on the error path,
not the normal path out of the function.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/sheepdog.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 7434710..c3ee4ce 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1392,7 +1392,7 @@ static int sd_open(BlockDriverState *bs, QDict *options,
int flags,
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
- goto out;
+ goto err_no_fd;
}
filename = qemu_opt_get(opts, "filename");
@@ -1412,17 +1412,17 @@ static int sd_open(BlockDriverState *bs, QDict
*options, int flags,
}
if (ret < 0) {
error_setg(errp, "Can't parse filename");
- goto out;
+ goto err_no_fd;
}
s->fd = get_sheep_fd(s, errp);
if (s->fd < 0) {
ret = s->fd;
- goto out;
+ goto err_no_fd;
}
ret = find_vdi_name(s, vdi, snapid, tag, &vid, true, errp);
if (ret) {
- goto out;
+ goto err;
}
/*
@@ -1443,7 +1443,7 @@ static int sd_open(BlockDriverState *bs, QDict *options,
int flags,
fd = connect_to_sdog(s, errp);
if (fd < 0) {
ret = fd;
- goto out;
+ goto err;
}
buf = g_malloc(SD_INODE_SIZE);
@@ -1454,7 +1454,7 @@ static int sd_open(BlockDriverState *bs, QDict *options,
int flags,
if (ret) {
error_setg(errp, "Can't read snapshot inode");
- goto out;
+ goto err;
}
memcpy(&s->inode, buf, sizeof(s->inode));
@@ -1466,12 +1466,12 @@ static int sd_open(BlockDriverState *bs, QDict
*options, int flags,
qemu_opts_del(opts);
g_free(buf);
return 0;
-out:
+
+err:
aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd,
false, NULL, NULL, NULL, NULL);
- if (s->fd >= 0) {
- closesocket(s->fd);
- }
+ closesocket(s->fd);
+err_no_fd:
qemu_opts_del(opts);
g_free(buf);
return ret;
--
1.8.3.1
- [Qemu-block] [PULL 00/27] Block layer fixes for 2.9.0-rc0, Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 03/27] mirror: Fix permissions for removing mirror_top_bs, Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 01/27] commit: Fix error handling, Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 02/27] mirror: Fix permission problem with 'replaces', Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 05/27] block: Fix blockdev-snapshot error handling, Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 04/27] mirror: Fix error path for dirty bitmap creation, Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 07/27] block: Factor out bdrv_replace_child_noperm(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 06/27] block: Factor out should_update_child(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 08/27] block: Ignore multiple children in bdrv_check_update_perm(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 11/27] sheepdog: Defuse time bomb in sd_open() error handling,
Kevin Wolf <=
- [Qemu-block] [PULL 09/27] block: Handle permission errors in change_parent_backing_link(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 10/27] block: Fix error handling in bdrv_replace_in_backing_chain(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 13/27] sheepdog: Fix error handling sd_create(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 14/27] sheepdog: Mark sd_snapshot_delete() lossage FIXME, Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 12/27] sheepdog: Fix error handling in sd_snapshot_delete(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 15/27] sheepdog: Fix snapshot ID parsing in _open(), _create, _goto(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 16/27] sheepdog: Don't truncate long VDI name in _open(), _create(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 19/27] sheepdog: Implement bdrv_parse_filename(), Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 17/27] sheepdog: Report errors in pseudo-filename more usefully, Kevin Wolf, 2017/03/07
- [Qemu-block] [PULL 18/27] sheepdog: Use SocketAddress and socket_connect(), Kevin Wolf, 2017/03/07