From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSRsX-00018B-Cx for qemu-devel@nongnu.org; Thu, 10 May 2012 07:49:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSRsP-0006CB-S4 for qemu-devel@nongnu.org; Thu, 10 May 2012 07:49:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSRsP-0006Bg-Hi for qemu-devel@nongnu.org; Thu, 10 May 2012 07:49:45 -0400 From: Kevin Wolf Date: Thu, 10 May 2012 13:49:10 +0200 Message-Id: <1336650574-12835-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1336650574-12835-1-git-send-email-kwolf@redhat.com> References: <1336650574-12835-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 06/30] block: open backing file as read-only when probing for size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Paolo Bonzini bdrv_img_create will temporarily open the backing file to probe its size. However, this could be done with a read-write open if the wrong flags are passed to bdrv_img_create. Since there is really no documentation on what flags can be passed, assume that bdrv_img_create receives the flags with which the new image will be opened; sanitize them when opening the backing file. Reported-by: Eric Blake Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- block.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/block.c b/block.c index dbd60e3..754a422 100644 --- a/block.c +++ b/block.c @@ -4103,10 +4103,15 @@ int bdrv_img_create(const char *filename, const char *fmt, if (backing_file && backing_file->value.s) { uint64_t size; char buf[32]; + int back_flags; + + /* backing files always opened read-only */ + back_flags = + flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); bs = bdrv_new(""); - ret = bdrv_open(bs, backing_file->value.s, flags, backing_drv); + ret = bdrv_open(bs, backing_file->value.s, back_flags, backing_drv); if (ret < 0) { error_report("Could not open '%s'", backing_file->value.s); goto out; -- 1.7.6.5