Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2101073ybl; Thu, 30 Jan 2020 11:22:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyjFdZEuZKtbA9jEm2bkt6Vdnjixc1L6xZYJ+vmL4aLCuIh2bAxDeSYjAYRZTZHmAC1syVW X-Received: by 2002:a05:6808:a8e:: with SMTP id q14mr3806494oij.173.1580412141911; Thu, 30 Jan 2020 11:22:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580412141; cv=none; d=google.com; s=arc-20160816; b=BaO6+UnCr0ybxIJ/NGXa+mvTzC/35WqwTPp6738SOrEsnUvgG79gf/+MOC3H0pcKQ3 0IkPGyaWlPe4IBlSNQazY/SSFlK22FR5jwSCOoIZo2zVEtUci4pS6eGBtQFp3/Slvev3 D1iIXwcprD27yOfIOIBg8i3yps+vIaisreSYuJs577qnxA5gTBEoBfNlLC0+dHtJE76Y puhIUOKsjHVNjzF4LXFJyC14AhIVuUrNNi2UhqegDiSMvWHhzsbmJBYwEQWEjLbZBRAK l4+AJ6yQgKmvo8v327s/A6IIkYzuTDfvt6tqiZcGXHKIvvLByBeGvO+fv6/3VY595ghB mLpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JBK+pL0kMNg1j4hAyUgn6V5XozivRUJ4yW3dDkHx8f8=; b=rqvV5chXMo44kK6rn7pjuRA0D5WO5aU3tSQ54NZBeKCc9q/31xOC1si+zAqGlyETZQ 4xvKXxL8e6oDalHq2/YWmQpmjyXFRbWdhfH23V9nh6smi0wWHv7Hpyk9nQGDo0paLXjZ ginEXcz1CTSlEkiR4DlvobUjvDTsPM/fz4HrJdKyP4tbqch8jlatPpsdw13yQl/ENMB3 krs8Rht3F4w1MrzfOCMHjwoclZznAYiZ5uySAiVcwSpv6Xhrt5QmGCBAixGk4qAVA0gB n3lXcMNSxCxCqGWxjsd6xGXpX5tQmXZxOKuZZeRFm9xLAY3ggKHTsowj5M2fIXlMv2Zl hV7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JjbmkMJp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si1929460otk.80.2020.01.30.11.22.10; Thu, 30 Jan 2020 11:22:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JjbmkMJp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731668AbgA3StO (ORCPT + 99 others); Thu, 30 Jan 2020 13:49:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:60228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728018AbgA3Ss5 (ORCPT ); Thu, 30 Jan 2020 13:48:57 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 467A920CC7; Thu, 30 Jan 2020 18:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580410136; bh=wTJKfnahA9dRh4GuTokx+sUYQydd9BTA3cBAE6sWKVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JjbmkMJpWr9aEAc9dJslD4KjHQL3MtTT1SjMFLxn0QyNyIaFzjb85WbK7GBG3vGRd Z9Y4Qek0+1vw/8Xun2JOpvhXyRz2sR+VIhKrcpiqDazG6kyvgsiKfb9Tq0c3DwlGTp 2cIRCMqxp+LuYJS2tiK6mCrIpP72JhTBUEapSrcI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Dave Chinner , Jens Axboe , Konstantin Khlebnikov Subject: [PATCH 4.19 54/55] block: fix 32 bit overflow in __blkdev_issue_discard() Date: Thu, 30 Jan 2020 19:39:35 +0100 Message-Id: <20200130183618.177984182@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200130183608.563083888@linuxfoundation.org> References: <20200130183608.563083888@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Chinner commit 4800bf7bc8c725e955fcbc6191cc872f43f506d3 upstream. A discard cleanup merged into 4.20-rc2 causes fstests xfs/259 to fall into an endless loop in the discard code. The test is creating a device that is exactly 2^32 sectors in size to test mkfs boundary conditions around the 32 bit sector overflow region. mkfs issues a discard for the entire device size by default, and hence this throws a sector count of 2^32 into blkdev_issue_discard(). It takes the number of sectors to discard as a sector_t - a 64 bit value. The commit ba5d73851e71 ("block: cleanup __blkdev_issue_discard") takes this sector count and casts it to a 32 bit value before comapring it against the maximum allowed discard size the device has. This truncates away the upper 32 bits, and so if the lower 32 bits of the sector count is zero, it starts issuing discards of length 0. This causes the code to fall into an endless loop, issuing a zero length discards over and over again on the same sector. Fixes: ba5d73851e71 ("block: cleanup __blkdev_issue_discard") Tested-by: Darrick J. Wong Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner Killed pointless WARN_ON(). Signed-off-by: Jens Axboe Signed-off-by: Konstantin Khlebnikov Signed-off-by: Greg Kroah-Hartman --- block/blk-lib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -56,9 +56,11 @@ int __blkdev_issue_discard(struct block_ return -EINVAL; while (nr_sects) { - unsigned int req_sects = min_t(unsigned int, nr_sects, + sector_t req_sects = min_t(sector_t, nr_sects, bio_allowed_max_sectors(q)); + WARN_ON_ONCE((req_sects << 9) > UINT_MAX); + bio = next_bio(bio, 0, gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev);