Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp361984pxx; Wed, 28 Oct 2020 06:44:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzd6At/rNaF25yXUAIS0rVXvTCvxbQK+qr1iscltUsRgHwKzUe+uLMLghCqIO7Y5xSB55F X-Received: by 2002:a17:906:d1c3:: with SMTP id bs3mr7241415ejb.246.1603892660394; Wed, 28 Oct 2020 06:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603892660; cv=none; d=google.com; s=arc-20160816; b=HFc7ODMmpQyK5DWYftvlCiKUwHcjaoT77U67ozk//CmjE3u4WQ6OOePZ1uRC1ejDBn HQcBhpS6m8KMx5mrcG4LKGPRDbr6rIRa++T6/KIGFzBugrNI8DQ5s4XCXG3fVe55QS6n Ijw2pfM5EYw4a8iKvpgbCdcwjcnKDYKmok7JZFM+jIPhph9TKl5Z0bvektFBIgxBcE5L xfU65BVu8rjFhnRYnwGxGIh92dfFS0vXgPJwnY92oRP/j/nSNStX3ggmf87oCyQ2FFd8 wpy+lME7l5fDfOgoyKIySdfgSXGaVP6eoSoOo1NNTvfcQh0xdVO8Fm2q7HqPylbfHd7D JlyQ== 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=6O7BDE3kfVc5xMOVqWYese9CTb8mMbCJW4YY0cYNgfI=; b=DG3jU0nmT6mSqfPrmXvT4SjMITlttdCrBcK+w66H/JqOU2dgFOopNJmT4QINQ1kbTW jwWc1oCXIXdX6zQ+YJq+uXHBUAIsorB19x5YtLC//LZk/BQg7o7TgE5ZjBt9e4L4eFVu kn7pNNkTr0/7f+5Bzoz1UEZCjMYw/ly5srTIzEq//5urhiB87by3Ez/ClNoUgcy8Sel8 PQ/9AK3r8Ro5eAok2rOLMQ53LSvUSBp9stAr+smo3HBnbjnZd98k4Ix6xvqFcS0TsVKh AiLSVg+q6U4MWJdZzTCpkmlQPJAk2t3FsTqzZ7Pj1+QaTHd2o3EInzTdNXwIRmZb9fgK tQhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W43675HR; 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 t1si2868715ejb.712.2020.10.28.06.43.58; Wed, 28 Oct 2020 06:44:20 -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=W43675HR; 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 S1802905AbgJ0Pvz (ORCPT + 99 others); Tue, 27 Oct 2020 11:51:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:56944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1801050AbgJ0Phs (ORCPT ); Tue, 27 Oct 2020 11:37:48 -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 8DC4A204EF; Tue, 27 Oct 2020 15:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813067; bh=40/CG2GOzhuXH7Og2pJ+C8J6D3x9hkpd+2gdIvlcYuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W43675HRdGiaCWgMs0/ieL5tUb6ae3cAHtWuIZY8xFBIRUDC5LSaHeGPdBh7Z6eK/ 91xGM0lcjHkwqgk7M8fVBi2At2YWoyxDHN2GESuiiFB129MizDA85yNYLfOJwnuU/u xUcLUNYD5DEpxFiiM31PHaywxQiYj6Fxhf+s6qsc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Chandan Babu R , Sasha Levin Subject: [PATCH 5.9 426/757] xfs: fix high key handling in the rt allocators query_range function Date: Tue, 27 Oct 2020 14:51:16 +0100 Message-Id: <20201027135510.547743223@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@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 d88850bd5516a77c6f727e8b6cefb64e0cc929c7 ] Fix some off-by-one errors in xfs_rtalloc_query_range. The highest key in the realtime bitmap is always one less than the number of rt extents, which means that the key clamp at the start of the function is wrong. The 4th argument to xfs_rtfind_forw is the highest rt extent that we want to probe, which means that passing 1 less than the high key is wrong. Finally, drop the rem variable that controls the loop because we can compare the iteration point (rtstart) against the high key directly. The sordid history of this function is that the original commit (fb3c3) incorrectly passed (high_rec->ar_startblock - 1) as the 'limit' parameter to xfs_rtfind_forw. This was wrong because the "high key" is supposed to be the largest key for which the caller wants result rows, not the key for the first row that could possibly be outside the range that the caller wants to see. A subsequent attempt (8ad56) to strengthen the parameter checking added incorrect clamping of the parameters to the number of rt blocks in the system (despite the bitmap functions all taking units of rt extents) to avoid querying ranges past the end of rt bitmap file but failed to fix the incorrect _rtfind_forw parameter. The original _rtfind_forw parameter error then survived the conversion of the startblock and blockcount fields to rt extents (a0e5c), and the most recent off-by-one fix (a3a37) thought it was patching a problem when the end of the rt volume is not in use, but none of these fixes actually solved the original problem that the author was confused about the "limit" argument to xfs_rtfind_forw. Sadly, all four of these patches were written by this author and even his own usage of this function and rt testing were inadequate to get this fixed quickly. Original-problem: fb3c3de2f65c ("xfs: add a couple of queries to iterate free extents in the rtbitmap") Not-fixed-by: 8ad560d2565e ("xfs: strengthen rtalloc query range checks") Not-fixed-by: a0e5c435babd ("xfs: fix xfs_rtalloc_rec units") Fixes: a3a374bf1889 ("xfs: fix off-by-one error in xfs_rtalloc_query_range") Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_rtbitmap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 1d9fa8a300f15..6c1aba16113c5 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -1018,7 +1018,6 @@ xfs_rtalloc_query_range( struct xfs_mount *mp = tp->t_mountp; xfs_rtblock_t rtstart; xfs_rtblock_t rtend; - xfs_rtblock_t rem; int is_free; int error = 0; @@ -1027,13 +1026,12 @@ xfs_rtalloc_query_range( if (low_rec->ar_startext >= mp->m_sb.sb_rextents || low_rec->ar_startext == high_rec->ar_startext) return 0; - if (high_rec->ar_startext > mp->m_sb.sb_rextents) - high_rec->ar_startext = mp->m_sb.sb_rextents; + high_rec->ar_startext = min(high_rec->ar_startext, + mp->m_sb.sb_rextents - 1); /* Iterate the bitmap, looking for discrepancies. */ rtstart = low_rec->ar_startext; - rem = high_rec->ar_startext - rtstart; - while (rem) { + while (rtstart <= high_rec->ar_startext) { /* Is the first block free? */ error = xfs_rtcheck_range(mp, tp, rtstart, 1, 1, &rtend, &is_free); @@ -1042,7 +1040,7 @@ xfs_rtalloc_query_range( /* How long does the extent go for? */ error = xfs_rtfind_forw(mp, tp, rtstart, - high_rec->ar_startext - 1, &rtend); + high_rec->ar_startext, &rtend); if (error) break; @@ -1055,7 +1053,6 @@ xfs_rtalloc_query_range( break; } - rem -= rtend - rtstart + 1; rtstart = rtend + 1; } -- 2.25.1