From nobody Mon Feb 9 19:53:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1555683193; cv=none; d=zoho.com; s=zohoarc; b=eUDcTgDCzNRHhIW2tS2yfjDfqR4p3prpAKAogkFfyNL1y27tsH+XkpW0OwUs0n+L5A40qrSNjaS/RQOHJhJhEY5BNERtJXFMhZ+w8Crv7KJ0lMo1/9v+WksS4OgCfDC+qSHbSJyRw+OHkSqGRe8QIPWTF2G1+KNQ0zmklKOyNB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555683193; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WiQDXhjJ/mx/Vhg2Ounns73g4O6iE4j0Kepggrr0BP8=; b=Jrg/RVpapOsvIAh0pPUixC7+GKTMsDsd6R243GwolRJrEsGut0qUQBvNeeHoBe0pQYd/yepR83Z7UzdvNglxJumO8PYJteGpDVxY6vHanrujguWC5z6nwlBt1zGyiw1/tRarIhOYwluSA40I/9jYNdHk9UNX/GyslQvKK89hiYM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555683193498827.1843528580548; Fri, 19 Apr 2019 07:13:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:57119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHUGM-0002Vq-78 for importer@patchew.org; Fri, 19 Apr 2019 10:13:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHU9i-0005hy-ID for qemu-devel@nongnu.org; Fri, 19 Apr 2019 10:06:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hHU9h-00089w-Eh for qemu-devel@nongnu.org; Fri, 19 Apr 2019 10:06:18 -0400 Received: from relay.sw.ru ([185.231.240.75]:34400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hHU9h-0007ct-65; Fri, 19 Apr 2019 10:06:17 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hHU9O-0000CE-3u; Fri, 19 Apr 2019 17:05:58 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 19 Apr 2019 17:05:56 +0300 Message-Id: <20190419140557.102725-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190419140557.102725-1-vsementsov@virtuozzo.com> References: <20190419140557.102725-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v3 2/3] block/io: bdrv_pdiscard: support int64_t bytes parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes at least one overflow in qcow2_process_discards, which passes 64bit region length to bdrv_pdiscard which bytes (or sectors in the past) parameter is int since it's introduction in 0b919fae. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- include/block/block.h | 4 ++-- block/io.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index c7a26199aa..69fa18867e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -432,8 +432,8 @@ void bdrv_drain_all(void); AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \ cond); }) =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes); -int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int bytes); +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); +int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); diff --git a/block/io.c b/block/io.c index dfc153b8d8..35c4157669 100644 --- a/block/io.c +++ b/block/io.c @@ -2653,7 +2653,7 @@ int bdrv_flush(BlockDriverState *bs) typedef struct DiscardCo { BdrvChild *child; int64_t offset; - int bytes; + int64_t bytes; int ret; } DiscardCo; static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) @@ -2664,14 +2664,15 @@ static void coroutine_fn bdrv_pdiscard_co_entry(voi= d *opaque) aio_wait_kick(); } =20 -int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int by= tes) +int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes) { BdrvTrackedRequest req; int max_pdiscard, ret; int head, tail, align; BlockDriverState *bs =3D child->bs; =20 - if (!bs || !bs->drv) { + if (!bs || !bs->drv || !bdrv_is_inserted(bs)) { return -ENOMEDIUM; } =20 @@ -2679,9 +2680,8 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int bytes) return -EPERM; } =20 - ret =3D bdrv_check_byte_request(bs, offset, bytes); - if (ret < 0) { - return ret; + if (offset < 0) { + return -EIO; } =20 /* Do nothing if disabled. */ @@ -2716,7 +2716,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int bytes) assert(max_pdiscard >=3D bs->bl.request_alignment); =20 while (bytes > 0) { - int num =3D bytes; + int64_t num =3D bytes; =20 if (head) { /* Make small requests to get to alignment boundaries. */ @@ -2778,7 +2778,7 @@ out: return ret; } =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes) +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { Coroutine *co; DiscardCo rwco =3D { --=20 2.18.0