From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42451C433DF for ; Sun, 18 Oct 2020 19:31:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CB3F207DE for ; Sun, 18 Oct 2020 19:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603049511; bh=33y6CAiMHrSEHGXU39bA0CzSEghh64lkJPtXonBCShA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jW9KuL091o1Oo923rVdRXT/3fmLRy4Scf0MUHZR6taXwtKAMzGSo9pUwWKivBM4Q6 5oaVitViJmY22wJYCh2pxpKvSVIFgF0I2VKK2c2vwEQN/7yWHAiKjOJ4Hw1jkS3zb+ GxOvmBIGYQX+/384j1Sqyi45gowiubx7XiMVMT4g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730153AbgJRTbu (ORCPT ); Sun, 18 Oct 2020 15:31:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:42840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731949AbgJRT1L (ORCPT ); Sun, 18 Oct 2020 15:27:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4C0CA2137B; Sun, 18 Oct 2020 19:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603049231; bh=33y6CAiMHrSEHGXU39bA0CzSEghh64lkJPtXonBCShA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xZGIXCHtDZFeLunM7R6FJfVTPMTYUmTD6I4aoCwMzwU8YpKErzXrsSEwhd9dJ56dG zaO+u0Gu3lKJKGJ3W+f5q6AzY8TfsoFDxDZDrC+m/QFK/xAz7Xuq1BD1ZiZvtAqIKs zpLe16jWvajkjNd6mq8K96MFm5UglH5ipwwbsS6M= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Darrick J. Wong" , Christoph Hellwig , Sasha Levin , linux-xfs@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 29/41] xfs: make sure the rt allocator doesn't run off the end Date: Sun, 18 Oct 2020 15:26:23 -0400 Message-Id: <20201018192635.4056198-29-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201018192635.4056198-1-sashal@kernel.org> References: <20201018192635.4056198-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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 0d93d3c10fcc4..d812f84252d5b 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -257,6 +257,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. @@ -448,6 +451,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