From nobody Sun Oct 5 19:23:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542229646120895.538203411544; Wed, 14 Nov 2018 13:07:26 -0800 (PST) Received: from localhost ([::1]:34243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN2NT-0003R3-1I for importer@patchew.org; Wed, 14 Nov 2018 16:07:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN2MU-00035i-E9 for qemu-devel@nongnu.org; Wed, 14 Nov 2018 16:06:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN2MS-0002ws-DH for qemu-devel@nongnu.org; Wed, 14 Nov 2018 16:06:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43478) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gN2MM-0002pM-MJ; Wed, 14 Nov 2018 16:06:02 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA50DC06A814; Wed, 14 Nov 2018 21:06:01 +0000 (UTC) Received: from red.redhat.com (ovpn-123-32.rdu2.redhat.com [10.10.123.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 589EB5D75C; Wed, 14 Nov 2018 21:05:57 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 15:05:48 -0600 Message-Id: <20181114210548.1098207-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 14 Nov 2018 21:06:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.1?] file-posix: Better checks of 64-bit copy_range 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, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" file-posix.c was taking a 64-bit bytes in raw_co_copy_range_to(), passing it through a 32-bit parameter of paio_submit_co_full(), then widening it back to size_t when assigning into acb->aio_nbytes. Looking at io.c, I can't quickly tell if bdrv_co_copy_range_internal() is fragmenting things to honor bs->bl.max_transfer, or if it can accidentally send requests larger than 2G down to the driver. If the former, then this is a no-op; if the latter, then someone needs to find a way to trigger this assertion and patch the block layer to properly fragment copy_range requests. Either way, we're better off with an assertion than the risk of silent data corruption. Signed-off-by: Eric Blake --- block/file-posix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 58c86a01eaa..48ad3bb372a 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1821,7 +1821,7 @@ static int aio_worker(void *arg) static int paio_submit_co_full(BlockDriverState *bs, int fd, int64_t offset, int fd2, int64_t offset2, QEMUIOVector *qiov, - int bytes, int type) + uint64_t bytes, int type) { RawPosixAIOData *acb =3D g_new(RawPosixAIOData, 1); ThreadPool *pool; @@ -1832,6 +1832,7 @@ static int paio_submit_co_full(BlockDriverState *bs, = int fd, acb->aio_fd2 =3D fd2; acb->aio_offset2 =3D offset2; + assert(bytes <=3D SIZE_MAX); acb->aio_nbytes =3D bytes; acb->aio_offset =3D offset; @@ -1848,7 +1849,7 @@ static int paio_submit_co_full(BlockDriverState *bs, = int fd, static inline int paio_submit_co(BlockDriverState *bs, int fd, int64_t offset, QEMUIOVector *qiov, - int bytes, int type) + uint64_t bytes, int type) { return paio_submit_co_full(bs, fd, offset, -1, 0, qiov, bytes, type); } --=20 2.17.2