Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp387741pxx; Wed, 28 Oct 2020 07:15:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3pBL/4UR65EBOVkJ/JP4pEUnLMutjW7N7Ib4WmeAREngo1SX6HJ9ll1n9bi9OylxO4fsf X-Received: by 2002:a7b:c09a:: with SMTP id r26mr8819923wmh.45.1603894522730; Wed, 28 Oct 2020 07:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603894522; cv=none; d=google.com; s=arc-20160816; b=Y7imRR3hezjPgwqEpmWJCHz5Y6wvPf6iUQM9Q7oCyGyJuVbVQBgK+VMKPCYvBhOiGe OtLBjFvEUvTUR7Rbm3XHrR2qbS2mDl81xI5lD8Vs8I1MQI2miXpN5ewlndi54DyXzOv1 goq1qQgGl+e65/ma5KQ8qQP1/dhqtmNvrN65Aklr5dryjijjsP6eutAeBTdIvGPSqwLq W6yGEeAq71IKBCq/luBtDCP0AZCHPRCeghdc4RyDkhHYyBJJhkKlebh63VOQKt5DwJ7c bfy+X6NeP40A3t15kKwRmwg+BelGPByLFvQIYFBZVjFQZ+vLrSKHEoWcL9ZdQoKfkRoG yV6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1FiqqPcG2R5XBgQqKMRWlZMTa6+ZiFagvzfxHwKUino=; b=H9sqtLRQFzOxrVmP7C+bYQbxJfPAea50cSQtm+ukT93WGfR5HzDdh7sP2Rfg1iJSYi S/9EsQEiAacCyxyqpSuOyeUhMapsMqDBH30flpYORcyLAbOEUDEe5ubXn015K/3wH2qe IrpTN0ibG+5sSIgbZxknmC4/DLQkF5JB2E/dJgFSh/MXO6LhfcPd5gRmrE9euU1zMr7a s8ZE2a68+hSSMsfWMDDdN99V2wEF4aNXLXLTLL2v+Mit0jf3o92WQ95yRiYr8DUB9Zcm r5c9rdLWKZZ/6oGYVNv6lY6GscHQZ2A7hwNfQhjsc0Z++lziFzJgbsIpI1XuftB7ho2G 9uWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aCAjZna0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l12si2820211edk.163.2020.10.28.07.15.00; Wed, 28 Oct 2020 07:15:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aCAjZna0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1804966AbgJ0QAK (ORCPT + 99 others); Tue, 27 Oct 2020 12:00:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:53628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1793972AbgJ0PQh (ORCPT ); Tue, 27 Oct 2020 11:16:37 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 7559A20657; Tue, 27 Oct 2020 15:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811796; bh=DQjGKbpQTULMZhHuUu2Ys3nYEbPtZNpbo/JbdCotYps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCAjZna0E4lpoA67sEAAUZEF+k/HPz0y0a7ZclrE3qPc06btcEC5rPmGs0dPHySgq DwbCpsas++ky0w+FYdRK4X53KCxnDruA3sF8tqKgekKlto9eWA/98IVFjDgPgYG7le hfh+pxCbdjWbNioVsj3tzIB8RAVNggaYqJQYw2vs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.8 588/633] xfs: make sure the rt allocator doesnt run off the end Date: Tue, 27 Oct 2020 14:55:31 +0100 Message-Id: <20201027135550.395057285@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Darrick J. Wong [ Upstream commit 2a6ca4baed620303d414934aa1b7b0a8e7bab05f ] There's an overflow bug in the realtime allocator. If the rt volume is large enough to handle a single allocation request that is larger than the maximum bmap extent length and the rt bitmap ends exactly on a bitmap block boundary, it's possible that the near allocator will try to check the freeness of a range that extends past the end of the bitmap. This fails with a corruption error and shuts down the fs. Therefore, constrain maxlen so that the range scan cannot run off the end of the rt bitmap. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/xfs_rtalloc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 6209e7b6b895b..86994d7f7cba3 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -247,6 +247,9 @@ xfs_rtallocate_extent_block( end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1; i <= end; i++) { + /* Make sure we don't scan off the end of the rt volume. */ + maxlen = min(mp->m_sb.sb_rextents, i + maxlen) - i; + /* * See if there's a free extent of maxlen starting at i. * If it's not so then next will contain the first non-free. @@ -442,6 +445,14 @@ xfs_rtallocate_extent_near( */ if (bno >= mp->m_sb.sb_rextents) bno = mp->m_sb.sb_rextents - 1; + + /* Make sure we don't run off the end of the rt volume. */ + maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno; + if (maxlen < minlen) { + *rtblock = NULLRTBLOCK; + return 0; + } + /* * Try the exact allocation first. */ -- 2.25.1