From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F6301B2188; Thu, 30 Jan 2025 08:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738226504; cv=none; b=IaipYjnDNyQxqAWDHJrV46kWk9qJZ0iVJ4DvMxRtC4lZ02AFxROXzvHnsTD7UvvPYfYEEUL4NXtU0qf0uST22IxS4phWFc4cJCInAvlkQ3Oog/glEe3+4g5VCQrDuba+2czkBOPl81LJH4//Hu4LqIWy8clT1s1IK3EzMJTAxw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738226504; c=relaxed/simple; bh=QdGmSS0fTuZy2qOjrWLniW1LVTA5Upsohdoh6z5yQV8=; h=Subject:To:Cc:From:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type; b=c4Jt9F2EDNLjEjwECd7MBI7OakYUQSeDrC4JJL6sL6Mytl3Zk0Y+ONOOlbM0VPK6A+KsElNgxGlYKsuj+6joRPhTx8OJJdLZq15IRCePRd+LZYFrHy/tnF+ryNkFMoJ+G9mnwqTaAmI4bnSbhsVk79+fQknzQj7NyF1KIqEk/Uo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=u5IXvFTL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="u5IXvFTL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27156C4CED2; Thu, 30 Jan 2025 08:41:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1738226503; bh=QdGmSS0fTuZy2qOjrWLniW1LVTA5Upsohdoh6z5yQV8=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=u5IXvFTLcjiiHOKNmDYbEWtt5L2ibOVlDBHQeGQ2bhvmCtBe09zwzvB5eRl5UO84/ YYjERtga3uLv3P5aGFTduNHtloXSD5h71JO7cjTCM/9tXl3pAS91etON85+y6ML+4C S1hDM0JiSaVGjBH3KmFeZs3+pVryI1yCzzzz26tE= Subject: Patch "xfs: make sure maxlen is still congruent with prod when rounding down" has been added to the 6.1-stable tree To: amir73il@gmail.com,catherine.hoang@oracle.com,chandan.babu@oracle.com,djwong@kernel.org,gregkh@linuxfoundation.org,hch@lst.de,leah.rumancik@gmail.com,xfs-stable@lists.linux.dev Cc: From: Date: Thu, 30 Jan 2025 09:41:00 +0100 In-Reply-To: <20250129184717.80816-7-leah.rumancik@gmail.com> Message-ID: <2025013000-portside-dragging-22ec@gregkh> Precedence: bulk X-Mailing-List: xfs-stable@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit X-stable: commit X-Patchwork-Hint: ignore This is a note to let you know that I've just added the patch titled xfs: make sure maxlen is still congruent with prod when rounding down to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: xfs-make-sure-maxlen-is-still-congruent-with-prod-when-rounding-down.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From stable+bounces-111217-greg=kroah.com@vger.kernel.org Wed Jan 29 19:47:46 2025 From: Leah Rumancik Date: Wed, 29 Jan 2025 10:47:04 -0800 Subject: xfs: make sure maxlen is still congruent with prod when rounding down To: stable@vger.kernel.org Cc: xfs-stable@lists.linux.dev, amir73il@gmail.com, chandan.babu@oracle.com, catherine.hoang@oracle.com, "Darrick J. Wong" , Christoph Hellwig , Leah Rumancik Message-ID: <20250129184717.80816-7-leah.rumancik@gmail.com> From: "Darrick J. Wong" [ Upstream commit f6a2dae2a1f52ea23f649c02615d073beba4cc35 ] In commit 2a6ca4baed62, we tried to fix an overflow problem in the realtime allocator that was caused by an overly large maxlen value causing xfs_rtcheck_range to run off the end of the realtime bitmap. Unfortunately, there is a subtle bug here -- maxlen (and minlen) both have to be aligned with @prod, but @prod can be larger than 1 if the user has set an extent size hint on the file, and that extent size hint is larger than the realtime extent size. If the rt free space extents are not aligned to this file's extszhint because other files without extent size hints allocated space (or the number of rt extents is similarly not aligned), then it's possible that maxlen after clamping to sb_rextents will no longer be aligned to prod. The allocation will succeed just fine, but we still trip the assertion. Fix the problem by reducing maxlen by any misalignment with prod. While we're at it, split the assertions into two so that we can tell which value had the bad alignment. Fixes: 2a6ca4baed62 ("xfs: make sure the rt allocator doesn't run off the end") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Leah Rumancik Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_rtalloc.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -212,6 +212,23 @@ xfs_rtallocate_range( } /* + * Make sure we don't run off the end of the rt volume. Be careful that + * adjusting maxlen downwards doesn't cause us to fail the alignment checks. + */ +static inline xfs_extlen_t +xfs_rtallocate_clamp_len( + struct xfs_mount *mp, + xfs_rtblock_t startrtx, + xfs_extlen_t rtxlen, + xfs_extlen_t prod) +{ + xfs_extlen_t ret; + + ret = min(mp->m_sb.sb_rextents, startrtx + rtxlen) - startrtx; + return rounddown(ret, prod); +} + +/* * Attempt to allocate an extent minlen<=len<=maxlen starting from * bitmap block bbno. If we don't get maxlen then use prod to trim * the length, if given. Returns error; returns starting block in *rtblock. @@ -248,7 +265,7 @@ xfs_rtallocate_extent_block( 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; + maxlen = xfs_rtallocate_clamp_len(mp, i, maxlen, prod); /* * See if there's a free extent of maxlen starting at i. @@ -355,7 +372,8 @@ xfs_rtallocate_extent_exact( int isfree; /* extent is free */ xfs_rtblock_t next; /* next block to try (dummy) */ - ASSERT(minlen % prod == 0 && maxlen % prod == 0); + ASSERT(minlen % prod == 0); + ASSERT(maxlen % prod == 0); /* * Check if the range in question (for maxlen) is free. */ @@ -438,7 +456,9 @@ xfs_rtallocate_extent_near( xfs_rtblock_t n; /* next block to try */ xfs_rtblock_t r; /* result block */ - ASSERT(minlen % prod == 0 && maxlen % prod == 0); + ASSERT(minlen % prod == 0); + ASSERT(maxlen % prod == 0); + /* * If the block number given is off the end, silently set it to * the last block. @@ -447,7 +467,7 @@ xfs_rtallocate_extent_near( 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; + maxlen = xfs_rtallocate_clamp_len(mp, bno, maxlen, prod); if (maxlen < minlen) { *rtblock = NULLRTBLOCK; return 0; @@ -638,7 +658,8 @@ xfs_rtallocate_extent_size( xfs_rtblock_t r; /* result block number */ xfs_suminfo_t sum; /* summary information for extents */ - ASSERT(minlen % prod == 0 && maxlen % prod == 0); + ASSERT(minlen % prod == 0); + ASSERT(maxlen % prod == 0); ASSERT(maxlen != 0); /* Patches currently in stable-queue which might be from leah.rumancik@gmail.com are queue-6.1/xfs-allow-read-io-and-ficlone-to-run-concurrently.patch queue-6.1/xfs-hoist-freeing-of-rt-data-fork-extent-mappings.patch queue-6.1/xfs-make-sure-maxlen-is-still-congruent-with-prod-when-rounding-down.patch queue-6.1/xfs-only-remap-the-written-blocks-in-xfs_reflink_end_cow_extent.patch queue-6.1/xfs-dquot-recovery-does-not-validate-the-recovered-dquot.patch queue-6.1/xfs-clean-up-dqblk-extraction.patch queue-6.1/xfs-abort-intent-items-when-recovery-intents-fail.patch queue-6.1/xfs-up-ic_sema-if-flushing-data-device-fails.patch queue-6.1/xfs-fix-internal-error-from-agfl-exhaustion.patch queue-6.1/xfs-factor-out-xfs_defer_pending_abort.patch queue-6.1/xfs-fix-units-conversion-error-in-xfs_bmap_del_extent_delay.patch queue-6.1/xfs-bump-max-fsgeom-struct-version.patch queue-6.1/xfs-handle-nimaps-0-from-xfs_bmapi_write-in-xfs_alloc_file_space.patch queue-6.1/xfs-rt-stubs-should-return-negative-errnos-when-rt-disabled.patch queue-6.1/xfs-clean-up-fs_xflag_realtime-handling-in-xfs_ioctl_setattr_xflags.patch queue-6.1/xfs-respect-the-stable-writes-flag-on-the-rt-device.patch queue-6.1/xfs-introduce-protection-for-drop-nlink.patch queue-6.1/xfs-prevent-rt-growfs-when-quota-is-enabled.patch queue-6.1/xfs-inode-recovery-does-not-validate-the-recovered-inode.patch