From patchwork Wed Apr 16 13:08:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 339579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 79BD9140081 for ; Wed, 16 Apr 2014 23:09:24 +1000 (EST) Received: from localhost ([::1]:54549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaPac-0005n1-BI for incoming@patchwork.ozlabs.org; Wed, 16 Apr 2014 09:09:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaPa2-0005BB-2u for qemu-devel@nongnu.org; Wed, 16 Apr 2014 09:08:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WaPZv-0006y5-Jr for qemu-devel@nongnu.org; Wed, 16 Apr 2014 09:08:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaPZv-0006y0-Bf for qemu-devel@nongnu.org; Wed, 16 Apr 2014 09:08:39 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3GD8cPo020137 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Apr 2014 09:08:38 -0400 Received: from noname.redhat.com (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s3GD8XOJ023879; Wed, 16 Apr 2014 09:08:37 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 16 Apr 2014 15:08:29 +0200 Message-Id: <1397653710-22971-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1397653710-22971-1-git-send-email-kwolf@redhat.com> References: <1397653710-22971-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 2/3] block: Limit size to INT_MAX in bdrv_check_byte_request() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Commit 8f4754ed intended to protect against integer overflow bugs in block drivers by making sure that a single request that is passed to drivers is no longer than INT_MAX bytes. However, meanwhile there are some callers that don't use that code path any more but call bdrv_check_byte_request() directy, so let's add a check there as well. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block.c b/block.c index 8be40bb..bcf9dc9 100644 --- a/block.c +++ b/block.c @@ -2589,6 +2589,10 @@ static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset, { int64_t len; + if (size > INT_MAX) { + return -EIO; + } + if (!bdrv_is_inserted(bs)) return -ENOMEDIUM;