From patchwork Mon Jul 23 20:16:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10540963 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3250391E for ; Mon, 23 Jul 2018 20:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2218327FA1 for ; Mon, 23 Jul 2018 20:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16C41284EE; Mon, 23 Jul 2018 20:56:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AAD5327FA1 for ; Mon, 23 Jul 2018 20:56:33 +0000 (UTC) Received: from localhost ([::1]:36562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhse-0000O3-Rq for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 Jul 2018 16:56:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhJU-0002g6-8V for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:20:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhhJT-0004SH-8i for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:20:12 -0400 Received: from mail-oi0-x243.google.com ([2607:f8b0:4003:c06::243]:46631) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhhJT-0004S3-2t; Mon, 23 Jul 2018 16:20:11 -0400 Received: by mail-oi0-x243.google.com with SMTP id y207-v6so3457122oie.13; Mon, 23 Jul 2018 13:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Tu8r4wisGpHHAloiCJc+Q0opauUgffx/w08W9MSO9Qw=; b=WAljWmdDK8hvGLARJHffllJXoZp+4SbHveon9IRuMJEIieWmbE/v+mPmgzaFtBVtoX PdTBzo1kq17OQcY2vxoVkRnmpUEcuALj1Bgacp2gBJFE8oH8ORCW7jj6eZI39Uy1jD4o RGrbJYI3ROPzC1IwpupR++rntB56uBzxMpVoB7mSHCRi7NswORdTrziYVpEVEP9SOb+T Cru0zFbQxWmEi6K3H1Uzc/n+1D5quacgw4uK/6ocbkZkFL/lxlUsE8mBTqRN5dkMPu4p wIJbEeYbZ5XjsHWd/UnZDzSefuNZHygfDR/o00QSbRB+SGwqUlOaEgdBWx6eJ6qRWHbj Bc9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Tu8r4wisGpHHAloiCJc+Q0opauUgffx/w08W9MSO9Qw=; b=k0CEQSI5NhpU8UPSTW0DY+bTiOhgJ4xHkN5nO7FYkFh/rWFZNEDznLzsq/Yrsjdpn1 JVaCZtmqeRUoK1wEuOE4sqKmikAD2TU6DjOCGiGB5HlmSJGUATADuG9s3jHiDpO9/L2I oSQWYlSg0gCsnvjmIbLabSX43WOdVIsmKO8IcmRrCrdJRlIcYjQGLqUJYxmgsum1M6oI RpbA0Le34lTbfAhSFURjzATKRznp2rkf7EtBn6zZfY8JHiAaSjN0N+cGdHIUPBFgTYVn LXLlxXsCVR2iAGgtfLtp64JZpC4xkcVl/nyx6Jx455OnQeyMi+Fbu374XkhE0kBQRbSY EkOg== X-Gm-Message-State: AOUpUlFrsAWQ7qDVYWe4mWHibGw+NLkysrw1zdRfZ6OfD2gM+oIGlqI5 jZeISz91oJOp1Z3v4+wIjQ1RDng9mJg= X-Google-Smtp-Source: AAOMgpf9SLaM/BM+yFCFgIpPUCs/Sdf8XLPlR0uNtfDMPRxdrVwth2cX8BGKQTVmljhxsJJtfCBFsA== X-Received: by 2002:aca:400b:: with SMTP id n11-v6mr306331oia.150.1532377209867; Mon, 23 Jul 2018 13:20:09 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id m62-v6sm26385502oik.30.2018.07.23.13.20.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 13:20:08 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 15:16:56 -0500 Message-Id: <20180723201748.25573-48-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> References: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::243 Subject: [Qemu-devel] [PATCH 47/99] qemu-img: Fix assert when mapping unaligned raw file 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: Kevin Wolf , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake Commit a290f085 exposed a latent bug in qemu-img map introduced during the conversion of block status to be byte-based. Earlier in commit 5e344dd8, the internal interface get_block_status() switched to take byte-based parameters, but still called a sector-based block layer function; as such, rounding was added in the lone caller to obey the contract. However, commit 237d78f8 changed get_block_status() to truly be byte-based, at which point rounding to sector boundaries can result in calling bdrv_block_status() with 'bytes == 0' (a coding error) when the boundary between data and a hole falls mid-sector (true for the past-EOF implicit hole present in POSIX files). Fix things by removing the rounding that is now no longer necessary. See also https://bugzilla.redhat.com/1589738 Fixes: 237d78f8 Reported-by: Dan Kenigsberg Reported-by: Nir Soffer Reported-by: Maor Lipchuk CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Signed-off-by: Kevin Wolf (cherry picked from commit e0b371ed5e2db079051139136fd0478728b6a58f) Signed-off-by: Michael Roth --- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index b422fda6f3..a8e2b53dc6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2827,7 +2827,7 @@ static int img_map(int argc, char **argv) int64_t n; /* Probe up to 1 GiB at a time. */ - n = QEMU_ALIGN_DOWN(MIN(1 << 30, length - offset), BDRV_SECTOR_SIZE); + n = MIN(1 << 30, length - offset); ret = get_block_status(bs, offset, n, &next); if (ret < 0) {