From patchwork Fri Jan 22 13:26:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 43482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 74315B7CD7 for ; Sat, 23 Jan 2010 00:28:25 +1100 (EST) Received: from localhost ([127.0.0.1]:46919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NYJYk-0003zn-5g for incoming@patchwork.ozlabs.org; Fri, 22 Jan 2010 08:28:22 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NYJY5-0003zE-Ls for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NYJY0-0003vz-Vy for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:41 -0500 Received: from [199.232.76.173] (port=44143 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NYJY0-0003vp-MP for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64614) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NYJY0-0007yD-8b for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:36 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0MDRX2D012500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 22 Jan 2010 08:27:34 -0500 Received: from localhost.localdomain (vpn1-4-189.ams2.redhat.com [10.36.4.189]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0MDRVI7030247; Fri, 22 Jan 2010 08:27:32 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 22 Jan 2010 14:26:38 +0100 Message-Id: <1264166798-27422-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] block/raw-posix: Abort on pread beyond end of non-growable file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This shouldn't happen under any normal circumstances. However, it looks like it's possible to achieve this with corrupted images. Without this patch raw_pread is hanging in an endless loop in such cases. The patch is not affecting growable files, for which such reads happen in normal use cases. raw_pread_aligned already handles these cases and won't return zero in the first place. Signed-off-by: Kevin Wolf --- block/raw-posix.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 4d79881..6ef1cff 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -403,8 +403,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, size = ALIGNED_BUFFER_SIZE; ret = raw_pread_aligned(bs, offset, s->aligned_buf, size); - if (ret < 0) + if (ret < 0) { return ret; + } else if (ret == 0) { + fprintf(stderr, "raw_pread: read beyond end of file\n"); + abort(); + } size = ret; if (size > count)